-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathproon
More file actions
executable file
·45 lines (42 loc) · 1.11 KB
/
proon
File metadata and controls
executable file
·45 lines (42 loc) · 1.11 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
#!/bin/bash
# Delete all branches that have been merged to master or specified merge branch && push deletes to remote origin
CHECK_ORIGIN=$(git remote -v | grep '^origin.\+(push)$')
if [ -z "$CHECK_ORIGIN" ]; then
echo "You need to be in a git repo with a pushable \"origin\" remote!"
exit 1
fi
INTERACTIVE=''
MERGE_BRANCH='master'
while getopts "ib:" OPTION
do
case "$OPTION" in
i)
INTERACTIVE='yes'
;;
b)
MERGE_BRANCH="$OPTARG"
;;
esac
done
for BRANCH in $(git branch --merged "$MERGE_BRANCH" | grep -v "\<master\>\|^\*\|\<$MERGE_BRANCH\>"); do
if [ -n "$INTERACTIVE" ]; then
read -p "$(basename $0): remove branch '$BRANCH'? (y)" RESPONSE
if [ "$RESPONSE" != 'y' ] && [ "$RESPONSE" != '' ]; then
continue
fi
fi
ST=$(git branch -d "$BRANCH" 2>&1)
if [ $? -eq 0 ]; then
echo -n "Pruned \"$BRANCH\"; removing from origin..."
RST=$(git push origin ":$BRANCH" 2>&1)
if [ $? -eq 0 ]; then
echo " Removed."
else
echo
echo "Branch \"$BRANCH\" not removed from origin: $RST"
fi
else
ST=$(echo "$ST" | head -n 1 | sed 's/error: //')
echo "Branch \"$BRANCH\" not removed: $ST"
fi
done