-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-rb
executable file
·87 lines (70 loc) · 1.63 KB
/
git-rb
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
#!/bin/bash
HELP_TEXT=$(cat <<'EOF'
Usage: git rb <branches> [-p | --push] [-o | --onto <base>]
Rebase a list of branches onto a given branch.
Positional arguments:
branches
optional arguments:
-h, --help Show this help message and exit
-p, --push Push the branches after successful rebase upstream
-o, --onto Specify onto which branch should the rebase happen
Default: master
EOF
)
PARAMS=""
while (( "$#" )); do
case "$1" in
-p|--push)
SHOULD_PUSH="1"
shift 1
;;
-o|--onto)
REBASE_ONTO="$2"
if [ "$REBASE_ONTO" = "" ]; then
echo "Please specify which branch you want to rebase onto."
exit 1
fi
shift 2
;;
-h)
echo "$HELP_TEXT"
exit 0
;;
--) # End argument parsing
shift
break
;;
-*|--*=) # Unsupported flags
echo "Error: Unsupported flag $1" >&2
exit 1
;;
*) # Preserve positional arguments
PARAMS="$PARAMS $1"
shift
;;
esac
done
# Set positional arguments in their proper place
eval set -- "$PARAMS"
BRANCHES=($@)
REBASE_ONTO="${REBASE_ONTO:-master}"
if [ "$(git status --untracked-file=no)" != "" ]; then
echo "The working tree is not clean."
exit 1
fi
function refresh_master () {
echo "Refreshing \"$REBASE_ONTO\" before rebase."
git checkout "$REBASE_ONTO" || exit 1
git pull || exit 1
}
function rebase_branches () {
for branch in "${BRANCHES[@]}"; do
git checkout "$branch" || exit 1
git rebase "$REBASE_ONTO" || exit 1
if [ "$SHOULD_PUSH" != "" ]; then
git push -f || exit 1
fi
done
}
refresh_master
rebase_branches