-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathggrbm
More file actions
executable file
·182 lines (151 loc) · 3.62 KB
/
ggrbm
File metadata and controls
executable file
·182 lines (151 loc) · 3.62 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/bash
me=`basename $0`
usage () {
# Call as: usage [EXITCODE] [USAGE MESSAGE]
exit_code=1
if [[ "$1" == [0-9] ]]; then
exit_code="$1"
shift
fi
cat <<EOF >&2
Usage: $me [options] [BRANCH-CONFIG]
BRANCH-CONFIG defaults to $wd/.git/topic-branches and takes the
format:
# Comments are allowed
# Each line contains a set of arguments to pass to git rebase
# e.g.
trunk myroot
myroot mytopic1
myroot mytopic2
# You can use arbitrary git commands by prefixing with '!':
!branch -f working mytopic1
!merge --no-edit mytopic2
Options:
-i Do interactive rebase
EOF
if [ -n "$1" ]; then
echo "$*" >&2
echo
fi
exit $exit_code
}
parse_opts () {
while [ $# != 0 ]; do
case "$1" in
-h|--help)
usage 0
;;
-i)
interactive=-i
shift
;;
-*)
usage "Unrecognised option: $1"
;;
*)
break
;;
esac
done
if [ "$#" -gt 1 ]; then
usage
elif [ "$#" -eq 1 ]; then
conf="$1"
shift
elif [ "$#" -eq 0 ]; then
conf="$root/.git/topic-branches"
fi
if ! [ -e "$conf" ]; then
die "$conf not found; aborting."
fi
ARGV=( "$@" )
}
die () {
echo >&2 "$*"
exit 1
}
process_line () {
case "${args[0]}" in
!*)
args[0]="${args[0]#!}"
process_arbitrary_git_command
;;
*)
process_rebase_command
;;
esac
}
process_arbitrary_git_command () {
echo "git ${args[*]}"
if ! git "${args[@]}"; then
had_issues=y
echo "git ${args[*]} failed"
echo "Please fix and then exit shell."
bash <&3
fi
}
process_rebase_command () {
range="${args[0]}..${args[1]}"
check_whitespace
echo
rebase_until_success
echo
if [ -z "$had_issues" ]; then
echo -n "git rebase ${args[*]} done"
else
echo -n "git rebase ${args[*]} done; hit enter to continue ... "
read <&3
fi
echo
div
}
check_whitespace () {
echo "Checking for whitespace errors in $range"
if ! ggdcm "$range"; then
echo -n "Hit enter to continue regardless ... "
read <&3
echo
fi
}
rebase_until_success () {
echo "git rebase $interactive ${args[*]}"
had_issues=
if ! git rebase $interactive "${args[@]}"; then
had_issues=y
while [ -e "$root/.git/rebase-apply" ] || [ -d "$root/.git/rebase-merge" ]; do
echo
echo "git rebase ${args[@]} not completed."
echo "Please fix via git rebase --continue / --abort then exit shell."
bash <&3
done
fi
}
restore_head () {
if [ -n "$orig_head" ]; then
echo "Checking out original HEAD ($orig_head) ... "
git checkout "$orig_head"
else
echo "WARNING: Couldn't determine original HEAD; current HEAD is probably different".
fi
}
main () {
root="`git root`"
if [ -z "$root" ]; then
die "git root failed; aborting."
fi
if ! which div >&/dev/null; then
die "div not found on \$PATH; please get from: https://github.com/aspiers/shell-env/blob/master/bin/div"
fi
parse_opts "$@"
if [ -e "$root/.git/rebase-apply" ]; then
die "$me: rebase already in progress! aborting."
fi
orig_head=`git head`
exec 3>&0 # save STDIN tty
grep -Ev '^ *(#|$)' "$conf" | while read -a args; do
process_line
done
echo
restore_head
}
main "$@"