-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_integrated_topic_branches
More file actions
executable file
·97 lines (82 loc) · 3.07 KB
/
Copy pathremove_integrated_topic_branches
File metadata and controls
executable file
·97 lines (82 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh
set -e
PR_BRANCH_PREFIX=pr_
UPSTREAM=$(git config sync.upstreamRepo || true)
TOPIC_BRANCH_PREFIX=$(git config sync.topicBranchPrefix || true)
#TOPIC_BRANCH_PREFIX=t_
RELEASE_BRANCHES=$(git config sync.releaseBranches || true)
function git_ls_branches() {
git for-each-ref --format='%(refname:short)' "refs/heads/$1*" "refs/heads/$1*/*" "refs/heads/$1*/*/*" "refs/heads/$1*/*/*/*" "refs/heads/$1*/*/*/*/*" "refs/heads/$1*/*/*/*/*/*"
}
if [ -z "$TOPIC_BRANCH_PREFIX" ]; then
echo "$0: config sync.topicBranchPrefix not set"
exit 1
fi
if [ -z "$RELEASE_BRANCHES" ]; then
echo "$0: config sync.releaseBranches not set"
exit 1
fi
SAVED_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ -n"$(git status --porcelain --untracked-files=no)" ]]; then
git stash save "remove_integrated_topic_branches backup"
fi
TOPIC_BRANCH_PREFIXES=($TOPIC_BRANCH_PREFIX)
for prefix in "${TOPIC_BRANCH_PREFIXES[@]}"; do
for tb in $(git_ls_branches $prefix) ; do
rb=$(find_upstream_branch $tb)
# Checkout could fail because the branch is checked out in another worktree
if git switch -q $tb ; then
# The rebase could fail because it has conflicts
git rebase $rb $tb &>/dev/null || git rebase --abort
tb_head=$(git rev-parse "$tb")
rb_head=$(git rev-parse "$rb")
if [[ "$tb_head" == "$rb_head" ]] || git merge-base --is-ancestor $tb $rb ; then
echo Removing topic branch $tb merged in $rb
git checkout -q $rb
git branch --set-upstream-to=$rb $tb
git branch -d $tb
git push origin :$tb || true
if [[ "$SAVED_BRANCH" == "$tb" ]]; then
SAVED_BRANCH=$rb
fi
fi
fi
done
done
for tb in $(git_ls_branches $PR_BRANCH_PREFIX) ; do
rb=$(find_upstream_branch $tb)
# Checkout could fail because the branch is checked out in another worktree
if git switch -q $tb ; then
# The rebase could fail because it has conflicts
git rebase $rb $tb &>/dev/null || git rebase --abort
tb_head=$(git rev-parse "$tb")
rb_head=$(git rev-parse "$rb")
if [[ "$tb_head" == "$rb_head" ]] || git merge-base --is-ancestor $tb $rb ; then
echo Removing PR review branch $tb merged in $rb
git checkout -q $rb
git branch --set-upstream-to=$UPSTREAM/$rb $tb
git branch -d $tb
if [[ "$SAVED_BRANCH" == "$tb" ]]; then
SAVED_BRANCH=$rb
fi
fi
fi
done
# for prb in $(git_ls_branches $PR_BRANCH_PREFIX) ; do git checkout -q $prb ; git rebase -q $(find_upstream_branch) &>/dev/null || git rebase --abort ; done
#git checkout -q master
git reset
git checkout -q $SAVED_BRANCH
if git stash list --format="%s" | grep -q "remove_integrated_topic_branches backup"; then
git stash pop
fi
echo Topic branches not integrated yet:
for prefix in "${TOPIC_BRANCH_PREFIXES[@]}"; do
git_ls_branches $prefix | tr -d '*'
done
echo
echo PR branches not integrated yet:
echo $(git_ls_branches $PR_BRANCH_PREFIX | tr -d '*')
echo
echo Other branches:
TOPIC_PREFIX_PATTERN=$(IFS='|'; echo "${TOPIC_BRANCH_PREFIXES[*]}")
echo $(git_ls_branches | grep -Ev "^($TOPIC_PREFIX_PATTERN|$PR_BRANCH_PREFIX)")