]>
Commit | Line | Data |
---|---|---|
8cc6a083 | 1 | #!/bin/sh |
d025524d | 2 | |
dbc349bb | 3 | USAGE='[help|start|bad|good|new|old|terms|skip|next|reset|visualize|view|replay|log|run]' |
243a60fb | 4 | LONG_USAGE='git bisect help |
6021be86 | 5 | print this long help message. |
06e6a745 MM |
6 | git bisect start [--term-{old,good}=<term> --term-{new,bad}=<term>] |
7 | [--no-checkout] [<bad> [<good>...]] [--] [<pathspec>...] | |
6021be86 | 8 | reset bisect state and start bisection. |
21e5cfd8 AD |
9 | git bisect (bad|new) [<rev>] |
10 | mark <rev> a known-bad revision/ | |
11 | a revision after change in a given property. | |
12 | git bisect (good|old) [<rev>...] | |
13 | mark <rev>... known-good revisions/ | |
14 | revisions before change in a given property. | |
21b55e33 MM |
15 | git bisect terms [--term-good | --term-bad] |
16 | show the terms used for old and new commits (default: bad, good) | |
5413812f | 17 | git bisect skip [(<rev>|<range>)...] |
6021be86 | 18 | mark <rev>... untestable revisions. |
38a47fd6 | 19 | git bisect next |
6021be86 | 20 | find next bisection to test and check it out. |
6b87ce23 | 21 | git bisect reset [<commit>] |
6021be86 | 22 | finish bisection search and go back to commit. |
dbc349bb | 23 | git bisect (visualize|view) |
6021be86 | 24 | show bisect status in gitk. |
38a47fd6 | 25 | git bisect replay <logfile> |
6021be86 | 26 | replay bisection log. |
38a47fd6 | 27 | git bisect log |
6021be86 | 28 | show bisect log. |
38a47fd6 | 29 | git bisect run <cmd>... |
6021be86 | 30 | use <cmd>... to automatically bisect. |
243a60fb CC |
31 | |
32 | Please use "git help bisect" to get the full man page.' | |
d025524d | 33 | |
8f321a39 | 34 | OPTIONS_SPEC= |
ae2b0f15 | 35 | . git-sh-setup |
8cc6a083 | 36 | |
ce32660e JS |
37 | _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' |
38 | _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40" | |
43f9d9f3 AD |
39 | TERM_BAD=bad |
40 | TERM_GOOD=good | |
ce32660e | 41 | |
4796e823 JS |
42 | bisect_head() |
43 | { | |
de966e39 | 44 | if git rev-parse --verify -q BISECT_HEAD > /dev/null |
4796e823 JS |
45 | then |
46 | echo BISECT_HEAD | |
47 | else | |
48 | echo HEAD | |
49 | fi | |
50 | } | |
51 | ||
8cc6a083 | 52 | bisect_autostart() { |
823ea121 | 53 | test -s "$GIT_DIR/BISECT_START" || { |
3145b1a2 | 54 | gettextln "You need to start by \"git bisect start\"" >&2 |
8cc6a083 LT |
55 | if test -t 0 |
56 | then | |
04de0996 ÆAB |
57 | # TRANSLATORS: Make sure to include [Y] and [n] in your |
58 | # translation. The program will only accept English input | |
59 | # at this point. | |
6021be86 | 60 | gettext "Do you want me to do it for you [Y/n]? " >&2 |
8cc6a083 LT |
61 | read yesno |
62 | case "$yesno" in | |
63 | [Nn]*) | |
64 | exit ;; | |
65 | esac | |
66 | bisect_start | |
67 | else | |
68 | exit 1 | |
69 | fi | |
70 | } | |
71 | } | |
72 | ||
73 | bisect_start() { | |
06f5608c | 74 | git bisect--helper --bisect-start $@ || exit |
38a47fd6 | 75 | |
ba963de8 CC |
76 | # |
77 | # Change state. | |
78 | # In case of mistaken revs or checkout error, or signals received, | |
79 | # "bisect_auto_next" below may exit or misbehave. | |
80 | # We have to trap this to be able to clean up using | |
81 | # "bisect_clean_state". | |
82 | # | |
fb71a329 | 83 | trap 'git bisect--helper --bisect-clean-state' 0 |
ba963de8 CC |
84 | trap 'exit 255' 1 2 3 15 |
85 | ||
ba963de8 CC |
86 | # |
87 | # Check if we can proceed to the next bisect state. | |
88 | # | |
06f5608c | 89 | get_terms |
38a47fd6 | 90 | bisect_auto_next |
ba963de8 CC |
91 | |
92 | trap '-' 0 | |
8cc6a083 LT |
93 | } |
94 | ||
ee2314f5 | 95 | bisect_skip() { |
6021be86 | 96 | all='' |
ee2314f5 CC |
97 | for arg in "$@" |
98 | do | |
6021be86 JS |
99 | case "$arg" in |
100 | *..*) | |
101 | revs=$(git rev-list "$arg") || die "$(eval_gettext "Bad rev input: \$arg")" ;; | |
102 | *) | |
103 | revs=$(git rev-parse --sq-quote "$arg") ;; | |
104 | esac | |
105 | all="$all $revs" | |
106 | done | |
107 | eval bisect_state 'skip' $all | |
ee2314f5 CC |
108 | } |
109 | ||
155fc795 | 110 | bisect_state() { |
8cc6a083 | 111 | bisect_autostart |
155fc795 | 112 | state=$1 |
4fbdbd5b PB |
113 | git bisect--helper --check-and-set-terms $state $TERM_GOOD $TERM_BAD || exit |
114 | get_terms | |
155fc795 CC |
115 | case "$#,$state" in |
116 | 0,*) | |
f813fb41 | 117 | die "Please call 'bisect_state' with at least one argument." ;; |
43f9d9f3 | 118 | 1,"$TERM_BAD"|1,"$TERM_GOOD"|1,skip) |
57984dd9 VA |
119 | bisected_head=$(bisect_head) |
120 | rev=$(git rev-parse --verify "$bisected_head") || | |
121 | die "$(eval_gettext "Bad rev input: \$bisected_head")" | |
0f30233a | 122 | git bisect--helper --bisect-write "$state" "$rev" "$TERM_GOOD" "$TERM_BAD" || exit |
b903674b | 123 | git bisect--helper --check-expected-revs "$rev" ;; |
43f9d9f3 | 124 | 2,"$TERM_BAD"|*,"$TERM_GOOD"|*,skip) |
155fc795 | 125 | shift |
6bc02d56 | 126 | hash_list='' |
e3389075 | 127 | for rev in "$@" |
155fc795 | 128 | do |
a179a303 | 129 | sha=$(git rev-parse --verify "$rev^{commit}") || |
15eaa049 | 130 | die "$(eval_gettext "Bad rev input: \$rev")" |
6bc02d56 | 131 | hash_list="$hash_list $sha" |
d3e54c88 | 132 | done |
6bc02d56 CC |
133 | for rev in $hash_list |
134 | do | |
0f30233a | 135 | git bisect--helper --bisect-write "$state" "$rev" "$TERM_GOOD" "$TERM_BAD" || exit |
6bc02d56 | 136 | done |
b903674b | 137 | git bisect--helper --check-expected-revs $hash_list ;; |
43f9d9f3 AD |
138 | *,"$TERM_BAD") |
139 | die "$(eval_gettext "'git bisect \$TERM_BAD' can take only one argument.")" ;; | |
cc9f24d0 JH |
140 | *) |
141 | usage ;; | |
8cc6a083 | 142 | esac |
97e1c51e CC |
143 | bisect_auto_next |
144 | } | |
145 | ||
8cc6a083 | 146 | bisect_auto_next() { |
129a6cf3 | 147 | git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD && bisect_next || : |
8cc6a083 LT |
148 | } |
149 | ||
150 | bisect_next() { | |
8fe26f44 | 151 | case "$#" in 0) ;; *) usage ;; esac |
8cc6a083 | 152 | bisect_autostart |
129a6cf3 | 153 | git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD $TERM_GOOD|| exit |
0a5280a9 | 154 | |
0871984d | 155 | # Perform all bisection computation, display and checkout |
be5fe200 | 156 | git bisect--helper --next-all |
5a1d31c7 | 157 | res=$? |
0a5280a9 | 158 | |
6021be86 | 159 | # Check if we should exit because bisection is finished |
a7f8b8ac TH |
160 | if test $res -eq 10 |
161 | then | |
43f9d9f3 | 162 | bad_rev=$(git show-ref --hash --verify refs/bisect/$TERM_BAD) |
a7f8b8ac | 163 | bad_commit=$(git show-branch $bad_rev) |
43f9d9f3 | 164 | echo "# first $TERM_BAD commit: $bad_commit" >>"$GIT_DIR/BISECT_LOG" |
a7f8b8ac | 165 | exit 0 |
f989cac9 TH |
166 | elif test $res -eq 2 |
167 | then | |
168 | echo "# only skipped commits left to test" >>"$GIT_DIR/BISECT_LOG" | |
43f9d9f3 AD |
169 | good_revs=$(git for-each-ref --format="%(objectname)" "refs/bisect/$TERM_GOOD-*") |
170 | for skipped in $(git rev-list refs/bisect/$TERM_BAD --not $good_revs) | |
f989cac9 TH |
171 | do |
172 | skipped_commit=$(git show-branch $skipped) | |
43f9d9f3 | 173 | echo "# possible first $TERM_BAD commit: $skipped_commit" >>"$GIT_DIR/BISECT_LOG" |
f989cac9 TH |
174 | done |
175 | exit $res | |
a7f8b8ac | 176 | fi |
0a5280a9 | 177 | |
5a1d31c7 CC |
178 | # Check for an error in the bisection process |
179 | test $res -ne 0 && exit $res | |
180 | ||
181 | return 0 | |
8cc6a083 LT |
182 | } |
183 | ||
cc9f24d0 | 184 | bisect_visualize() { |
129a6cf3 | 185 | git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit |
235997c9 JH |
186 | |
187 | if test $# = 0 | |
188 | then | |
c4e4644e | 189 | if test -n "${DISPLAY+set}${SESSIONNAME+set}${MSYSTEM+set}${SECURITYSESSIONID+set}" && |
43b8ff4b | 190 | type gitk >/dev/null 2>&1 |
eef12a9a | 191 | then |
c4e4644e JK |
192 | set gitk |
193 | else | |
194 | set git log | |
195 | fi | |
235997c9 JH |
196 | else |
197 | case "$1" in | |
198 | git*|tig) ;; | |
199 | -*) set git log "$@" ;; | |
200 | *) set git "$@" ;; | |
201 | esac | |
202 | fi | |
203 | ||
fc13aa3d | 204 | eval '"$@"' --bisect -- $(cat "$GIT_DIR/BISECT_NAMES") |
cc9f24d0 JH |
205 | } |
206 | ||
e204de28 | 207 | bisect_replay () { |
55a9fc80 ÆAB |
208 | file="$1" |
209 | test "$#" -eq 1 || die "$(gettext "No logfile given")" | |
210 | test -r "$file" || die "$(eval_gettext "cannot read \$file for replaying")" | |
5e82c3dd | 211 | git bisect--helper --bisect-reset || exit |
6c722cbe | 212 | oIFS="$IFS" IFS="$IFS$(printf '\015')" |
173cb08d | 213 | while read git bisect command rev tail |
e204de28 | 214 | do |
c82af12a | 215 | test "$git $bisect" = "git bisect" || test "$git" = "git-bisect" || continue |
eef12a9a JS |
216 | if test "$git" = "git-bisect" |
217 | then | |
6c98c054 MV |
218 | rev="$command" |
219 | command="$bisect" | |
220 | fi | |
cb46d630 | 221 | get_terms |
4fbdbd5b PB |
222 | git bisect--helper --check-and-set-terms "$command" "$TERM_GOOD" "$TERM_BAD" || exit |
223 | get_terms | |
e204de28 JH |
224 | case "$command" in |
225 | start) | |
173cb08d | 226 | cmd="bisect_start $rev $tail" |
737c74ee | 227 | eval "$cmd" ;; |
cb46d630 | 228 | "$TERM_GOOD"|"$TERM_BAD"|skip) |
0f30233a | 229 | git bisect--helper --bisect-write "$command" "$rev" "$TERM_GOOD" "$TERM_BAD" || exit;; |
21b55e33 | 230 | terms) |
450ebb73 | 231 | git bisect--helper --bisect-terms $rev || exit;; |
e204de28 | 232 | *) |
9570fc1e | 233 | die "$(gettext "?? what are you talking about?")" ;; |
e204de28 | 234 | esac |
55a9fc80 | 235 | done <"$file" |
6c722cbe | 236 | IFS="$oIFS" |
e204de28 | 237 | bisect_auto_next |
8cc6a083 LT |
238 | } |
239 | ||
a17c4101 | 240 | bisect_run () { |
129a6cf3 | 241 | git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD fail || exit |
6021be86 | 242 | |
fecd2dd3 SB |
243 | test -n "$*" || die "$(gettext "bisect run failed: no command provided.")" |
244 | ||
6021be86 JS |
245 | while true |
246 | do | |
247 | command="$@" | |
3145b1a2 | 248 | eval_gettextln "running \$command" |
6021be86 JS |
249 | "$@" |
250 | res=$? | |
251 | ||
252 | # Check for really bad run error. | |
eef12a9a JS |
253 | if [ $res -lt 0 -o $res -ge 128 ] |
254 | then | |
3145b1a2 JS |
255 | eval_gettextln "bisect run failed: |
256 | exit code \$res from '\$command' is < 0 or >= 128" >&2 | |
6021be86 JS |
257 | exit $res |
258 | fi | |
259 | ||
260 | # Find current state depending on run success or failure. | |
261 | # A special exit code of 125 means cannot test. | |
eef12a9a JS |
262 | if [ $res -eq 125 ] |
263 | then | |
6021be86 | 264 | state='skip' |
eef12a9a JS |
265 | elif [ $res -gt 0 ] |
266 | then | |
43f9d9f3 | 267 | state="$TERM_BAD" |
6021be86 | 268 | else |
43f9d9f3 | 269 | state="$TERM_GOOD" |
6021be86 JS |
270 | fi |
271 | ||
272 | # We have to use a subshell because "bisect_state" can exit. | |
305a233c | 273 | ( bisect_state $state >"$GIT_DIR/BISECT_RUN" ) |
6021be86 JS |
274 | res=$? |
275 | ||
276 | cat "$GIT_DIR/BISECT_RUN" | |
277 | ||
43f9d9f3 | 278 | if sane_grep "first $TERM_BAD commit could be any of" "$GIT_DIR/BISECT_RUN" \ |
305a233c | 279 | >/dev/null |
eef12a9a | 280 | then |
3145b1a2 | 281 | gettextln "bisect run cannot continue any more" >&2 |
6021be86 JS |
282 | exit $res |
283 | fi | |
284 | ||
eef12a9a JS |
285 | if [ $res -ne 0 ] |
286 | then | |
3145b1a2 JS |
287 | eval_gettextln "bisect run failed: |
288 | 'bisect_state \$state' exited with error code \$res" >&2 | |
6021be86 JS |
289 | exit $res |
290 | fi | |
a17c4101 | 291 | |
43f9d9f3 | 292 | if sane_grep "is the first $TERM_BAD commit" "$GIT_DIR/BISECT_RUN" >/dev/null |
eef12a9a | 293 | then |
3145b1a2 | 294 | gettextln "bisect run success" |
6021be86 JS |
295 | exit 0; |
296 | fi | |
a17c4101 | 297 | |
6021be86 | 298 | done |
a17c4101 CC |
299 | } |
300 | ||
412ff738 | 301 | bisect_log () { |
9570fc1e | 302 | test -s "$GIT_DIR/BISECT_LOG" || die "$(gettext "We are not bisecting.")" |
412ff738 SG |
303 | cat "$GIT_DIR/BISECT_LOG" |
304 | } | |
a17c4101 | 305 | |
cb46d630 AD |
306 | get_terms () { |
307 | if test -s "$GIT_DIR/BISECT_TERMS" | |
308 | then | |
309 | { | |
310 | read TERM_BAD | |
311 | read TERM_GOOD | |
312 | } <"$GIT_DIR/BISECT_TERMS" | |
313 | fi | |
314 | } | |
315 | ||
8cc6a083 LT |
316 | case "$#" in |
317 | 0) | |
6021be86 | 318 | usage ;; |
8cc6a083 | 319 | *) |
6021be86 | 320 | cmd="$1" |
cb46d630 | 321 | get_terms |
6021be86 JS |
322 | shift |
323 | case "$cmd" in | |
324 | help) | |
325 | git bisect -h ;; | |
326 | start) | |
327 | bisect_start "$@" ;; | |
21e5cfd8 | 328 | bad|good|new|old|"$TERM_BAD"|"$TERM_GOOD") |
6021be86 JS |
329 | bisect_state "$cmd" "$@" ;; |
330 | skip) | |
331 | bisect_skip "$@" ;; | |
332 | next) | |
333 | # Not sure we want "next" at the UI level anymore. | |
334 | bisect_next "$@" ;; | |
335 | visualize|view) | |
336 | bisect_visualize "$@" ;; | |
337 | reset) | |
5e82c3dd | 338 | git bisect--helper --bisect-reset "$@" ;; |
6021be86 JS |
339 | replay) |
340 | bisect_replay "$@" ;; | |
341 | log) | |
342 | bisect_log ;; | |
343 | run) | |
344 | bisect_run "$@" ;; | |
21b55e33 | 345 | terms) |
450ebb73 | 346 | git bisect--helper --bisect-terms "$@" || exit;; |
6021be86 JS |
347 | *) |
348 | usage ;; | |
349 | esac | |
8cc6a083 | 350 | esac |