-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathold-branches.sh
executable file
·43 lines (34 loc) · 1.13 KB
/
old-branches.sh
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
#!/bin/sh
BASE_BRANCH="origin/master"
REMOTE_NAME=gh-robux4
#git remote prune $REMOTE_NAME
echo "" > to_remove.txt
echo "#!/bin/sh" > del_remote.sh
echo "for branch in \\" >> del_remote.sh
# delete branches that have been fully merged upstream
for branch in $(git branch -r --list --sort=-committerdate --format="%(refname:lstrip=3)" "$REMOTE_NAME/*"); do
# for branch in ci-llvm11; do
if [ "$branch" = "master" ] || [ "$branch" = "HEAD" ]; then
continue
fi
echo ""
echo "* Branch $REMOTE_NAME/$branch"
# remove remote first (verify it merges cleanly first)
ALL_MERGED=$(git cherry $BASE_BRANCH $REMOTE_NAME/$branch | sed '/^- /d' | wc -l)
if test 0 -eq "$ALL_MERGED"; then
echo "Branch $branch can be removed"
echo "Branch $REMOTE_NAME/$branch can be removed" >> to_remove.txt
echo " $branch \\" >> del_remote.sh
else
echo "Branch $branch has not been merged ($ALL_MERGED commits differ)"
fi
done
echo " none_
do
if [ \"\$branch\" = \"none_\" ]; then
continue
fi
echo \$branch
git push $REMOTE_NAME --delete \$branch
done
" >> del_remote.sh