blob: d7518e9c3b2cdf16da10b791a0591dc2347fd168 [file] [log] [blame]
Linus Torvalds8cc6a082005-07-30 10:08:20 -07001#!/bin/sh
Fredrik Kuivinend0255242005-12-11 10:55:49 +01002
Christian Couder243a60f2008-04-11 05:55:21 +02003USAGE='[help|start|bad|good|skip|next|reset|visualize|replay|log|run]'
4LONG_USAGE='git bisect help
Jon Seymour6021be82011-08-05 21:31:30 +10005 print this long help message.
Jon Seymour4796e822011-08-04 22:01:01 +10006git bisect start [--no-checkout] [<bad> [<good>...]] [--] [<pathspec>...]
Jon Seymour6021be82011-08-05 21:31:30 +10007 reset bisect state and start bisection.
Christian Couder38a47fd2007-04-04 07:12:02 +02008git bisect bad [<rev>]
Jon Seymour6021be82011-08-05 21:31:30 +10009 mark <rev> a known-bad revision.
Christian Couder38a47fd2007-04-04 07:12:02 +020010git bisect good [<rev>...]
Jon Seymour6021be82011-08-05 21:31:30 +100011 mark <rev>... known-good revisions.
Christian Couder54138122008-12-02 14:53:51 +010012git bisect skip [(<rev>|<range>)...]
Jon Seymour6021be82011-08-05 21:31:30 +100013 mark <rev>... untestable revisions.
Christian Couder38a47fd2007-04-04 07:12:02 +020014git bisect next
Jon Seymour6021be82011-08-05 21:31:30 +100015 find next bisection to test and check it out.
Anders Kaseorg6b87ce22009-10-13 17:02:24 -040016git bisect reset [<commit>]
Jon Seymour6021be82011-08-05 21:31:30 +100017 finish bisection search and go back to commit.
Christian Couder38a47fd2007-04-04 07:12:02 +020018git bisect visualize
Jon Seymour6021be82011-08-05 21:31:30 +100019 show bisect status in gitk.
Christian Couder38a47fd2007-04-04 07:12:02 +020020git bisect replay <logfile>
Jon Seymour6021be82011-08-05 21:31:30 +100021 replay bisection log.
Christian Couder38a47fd2007-04-04 07:12:02 +020022git bisect log
Jon Seymour6021be82011-08-05 21:31:30 +100023 show bisect log.
Christian Couder38a47fd2007-04-04 07:12:02 +020024git bisect run <cmd>...
Jon Seymour6021be82011-08-05 21:31:30 +100025 use <cmd>... to automatically bisect.
Christian Couder243a60f2008-04-11 05:55:21 +020026
27Please use "git help bisect" to get the full man page.'
Fredrik Kuivinend0255242005-12-11 10:55:49 +010028
Junio C Hamano8f321a32007-11-06 01:50:02 -080029OPTIONS_SPEC=
Junio C Hamanoae2b0f12005-11-24 00:12:11 -080030. git-sh-setup
Ævar Arnfjörð Bjarmasondcf9c2e2011-05-21 18:44:19 +000031. git-sh-i18n
Linus Torvalds8cc6a082005-07-30 10:08:20 -070032
Johannes Schindelince326602008-02-10 13:59:50 +000033_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
34_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
35
Jon Seymour4796e822011-08-04 22:01:01 +100036bisect_head()
37{
38 if test -f "$GIT_DIR/BISECT_HEAD"
39 then
40 echo BISECT_HEAD
41 else
42 echo HEAD
43 fi
44}
45
Linus Torvalds8cc6a082005-07-30 10:08:20 -070046bisect_autostart() {
Christian Couder823ea122008-05-28 18:57:02 +020047 test -s "$GIT_DIR/BISECT_START" || {
Jon Seymour3145b1a2011-08-31 09:09:47 +100048 gettextln "You need to start by \"git bisect start\"" >&2
Linus Torvalds8cc6a082005-07-30 10:08:20 -070049 if test -t 0
50 then
Ævar Arnfjörð Bjarmason04de0992011-05-21 18:44:28 +000051 # TRANSLATORS: Make sure to include [Y] and [n] in your
52 # translation. The program will only accept English input
53 # at this point.
Jon Seymour6021be82011-08-05 21:31:30 +100054 gettext "Do you want me to do it for you [Y/n]? " >&2
Linus Torvalds8cc6a082005-07-30 10:08:20 -070055 read yesno
56 case "$yesno" in
57 [Nn]*)
58 exit ;;
59 esac
60 bisect_start
61 else
62 exit 1
63 fi
64 }
65}
66
67bisect_start() {
Linus Torvalds8cc6a082005-07-30 10:08:20 -070068 #
Jon Seymour4764f462011-08-04 22:00:57 +100069 # Check for one bad and then some good revisions.
70 #
71 has_double_dash=0
72 for arg; do
Jon Seymour6021be82011-08-05 21:31:30 +100073 case "$arg" in --) has_double_dash=1; break ;; esac
Jon Seymour4764f462011-08-04 22:00:57 +100074 done
75 orig_args=$(git rev-parse --sq-quote "$@")
76 bad_seen=0
77 eval=''
Jon Seymour24c51282011-08-09 12:11:54 +100078 if test "z$(git rev-parse --is-bare-repository)" != zfalse
79 then
80 mode=--no-checkout
81 else
82 mode=''
83 fi
Jon Seymour4764f462011-08-04 22:00:57 +100084 while [ $# -gt 0 ]; do
Jon Seymour6021be82011-08-05 21:31:30 +100085 arg="$1"
86 case "$arg" in
87 --)
88 shift
89 break
Jon Seymour4764f462011-08-04 22:00:57 +100090 ;;
Jon Seymour6021be82011-08-05 21:31:30 +100091 --no-checkout)
92 mode=--no-checkout
93 shift ;;
94 --*)
95 die "$(eval_gettext "unrecognised option: '\$arg'")" ;;
96 *)
97 rev=$(git rev-parse -q --verify "$arg^{commit}") || {
Junio C Hamano43b8ff42011-08-05 10:09:23 -070098 test $has_double_dash -eq 1 &&
99 die "$(eval_gettext "'\$arg' does not appear to be a valid revision")"
100 break
Jon Seymour6021be82011-08-05 21:31:30 +1000101 }
102 case $bad_seen in
103 0) state='bad' ; bad_seen=1 ;;
104 *) state='good' ;;
105 esac
106 eval="$eval bisect_write '$state' '$rev' 'nolog' &&"
107 shift
108 ;;
Jon Seymour4764f462011-08-04 22:00:57 +1000109 esac
Jon Seymour4764f462011-08-04 22:00:57 +1000110 done
111
112 #
Christian Couder634f2462008-05-23 01:28:57 +0200113 # Verify HEAD.
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700114 #
Christian Couder48949a12008-04-16 04:09:49 +0200115 head=$(GIT_DIR="$GIT_DIR" git symbolic-ref -q HEAD) ||
Johannes Schindelince326602008-02-10 13:59:50 +0000116 head=$(GIT_DIR="$GIT_DIR" git rev-parse --verify HEAD) ||
Ævar Arnfjörð Bjarmason9570fc12011-05-21 18:44:23 +0000117 die "$(gettext "Bad HEAD - I need a HEAD")"
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700118
119 #
Christian Couder634f2462008-05-23 01:28:57 +0200120 # Check if we are bisecting.
121 #
122 start_head=''
123 if test -s "$GIT_DIR/BISECT_START"
124 then
125 # Reset to the rev from where we started.
126 start_head=$(cat "$GIT_DIR/BISECT_START")
Jon Seymour4796e822011-08-04 22:01:01 +1000127 if test "z$mode" != "z--no-checkout"
128 then
Christian Couder1acf1172011-09-21 07:17:24 +0200129 git checkout "$start_head" -- ||
130 die "$(eval_gettext "Checking out '\$start_head' failed. Try 'git bisect reset <validbranch>'.")"
Jon Seymour4796e822011-08-04 22:01:01 +1000131 fi
Christian Couder634f2462008-05-23 01:28:57 +0200132 else
133 # Get rev from where we start.
134 case "$head" in
135 refs/heads/*|$_x40)
136 # This error message should only be triggered by
137 # cogito usage, and cogito users should understand
138 # it relates to cg-seek.
139 [ -s "$GIT_DIR/head-name" ] &&
Ævar Arnfjörð Bjarmason9570fc12011-05-21 18:44:23 +0000140 die "$(gettext "won't bisect on seeked tree")"
Christian Couder634f2462008-05-23 01:28:57 +0200141 start_head="${head#refs/heads/}"
142 ;;
143 *)
Ævar Arnfjörð Bjarmason9570fc12011-05-21 18:44:23 +0000144 die "$(gettext "Bad HEAD - strange symbolic ref")"
Christian Couder634f2462008-05-23 01:28:57 +0200145 ;;
146 esac
147 fi
148
149 #
150 # Get rid of any old bisect state.
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700151 #
Christian Couder823ea122008-05-28 18:57:02 +0200152 bisect_clean_state || exit
Christian Couder38a47fd2007-04-04 07:12:02 +0200153
154 #
Christian Couderba963de2008-05-23 00:39:22 +0200155 # Change state.
156 # In case of mistaken revs or checkout error, or signals received,
157 # "bisect_auto_next" below may exit or misbehave.
158 # We have to trap this to be able to clean up using
159 # "bisect_clean_state".
160 #
161 trap 'bisect_clean_state' 0
162 trap 'exit 255' 1 2 3 15
163
164 #
165 # Write new start state.
166 #
Jon Seymour4796e822011-08-04 22:01:01 +1000167 echo "$start_head" >"$GIT_DIR/BISECT_START" && {
168 test "z$mode" != "z--no-checkout" ||
169 git update-ref --no-deref BISECT_HEAD "$start_head"
170 } &&
Christian Couderde52f5a2009-04-24 08:29:00 +0200171 git rev-parse --sq-quote "$@" >"$GIT_DIR/BISECT_NAMES" &&
Jon Seymour6ba7acf2011-08-04 22:00:58 +1000172 eval "$eval true" &&
Miklos Vajna6c98c052008-07-11 18:01:29 +0200173 echo "git bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG" || exit
Christian Couderba963de2008-05-23 00:39:22 +0200174 #
175 # Check if we can proceed to the next bisect state.
176 #
Christian Couder38a47fd2007-04-04 07:12:02 +0200177 bisect_auto_next
Christian Couderba963de2008-05-23 00:39:22 +0200178
179 trap '-' 0
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700180}
181
Christian Couder55624f92007-10-24 07:01:05 +0200182bisect_write() {
183 state="$1"
184 rev="$2"
Christian Couder737c74e2007-10-24 07:01:13 +0200185 nolog="$3"
Christian Couder55624f92007-10-24 07:01:05 +0200186 case "$state" in
187 bad) tag="$state" ;;
188 good|skip) tag="$state"-"$rev" ;;
Ævar Arnfjörð Bjarmason15eaa042011-05-21 18:44:24 +0000189 *) die "$(eval_gettext "Bad bisect_write argument: \$state")" ;;
Christian Couder55624f92007-10-24 07:01:05 +0200190 esac
Christian Couderba963de2008-05-23 00:39:22 +0200191 git update-ref "refs/bisect/$tag" "$rev" || exit
Johannes Schindelinf454cdc2008-02-12 19:50:57 +0000192 echo "# $state: $(git show-branch $rev)" >>"$GIT_DIR/BISECT_LOG"
Miklos Vajna6c98c052008-07-11 18:01:29 +0200193 test -n "$nolog" || echo "git bisect $state $rev" >>"$GIT_DIR/BISECT_LOG"
Christian Couder55624f92007-10-24 07:01:05 +0200194}
195
Christian Couderc9c4e2d2008-08-22 05:52:29 +0200196is_expected_rev() {
197 test -f "$GIT_DIR/BISECT_EXPECTED_REV" &&
198 test "$1" = $(cat "$GIT_DIR/BISECT_EXPECTED_REV")
199}
200
Christian Couderc9c4e2d2008-08-22 05:52:29 +0200201check_expected_revs() {
202 for _rev in "$@"; do
Jon Seymoureef12a92011-08-05 21:31:31 +1000203 if ! is_expected_rev "$_rev"
204 then
Christian Couderc9c4e2d2008-08-22 05:52:29 +0200205 rm -f "$GIT_DIR/BISECT_ANCESTORS_OK"
206 rm -f "$GIT_DIR/BISECT_EXPECTED_REV"
207 return
208 fi
209 done
210}
211
Christian Couderee2314f2008-11-23 22:02:49 +0100212bisect_skip() {
Jon Seymour6021be82011-08-05 21:31:30 +1000213 all=''
Christian Couderee2314f2008-11-23 22:02:49 +0100214 for arg in "$@"
215 do
Jon Seymour6021be82011-08-05 21:31:30 +1000216 case "$arg" in
217 *..*)
218 revs=$(git rev-list "$arg") || die "$(eval_gettext "Bad rev input: \$arg")" ;;
219 *)
220 revs=$(git rev-parse --sq-quote "$arg") ;;
221 esac
222 all="$all $revs"
223 done
224 eval bisect_state 'skip' $all
Christian Couderee2314f2008-11-23 22:02:49 +0100225}
226
Christian Couder155fc792007-10-24 07:01:21 +0200227bisect_state() {
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700228 bisect_autostart
Christian Couder155fc792007-10-24 07:01:21 +0200229 state=$1
230 case "$#,$state" in
231 0,*)
Ævar Arnfjörð Bjarmason9570fc12011-05-21 18:44:23 +0000232 die "$(gettext "Please call 'bisect_state' with at least one argument.")" ;;
Christian Couder155fc792007-10-24 07:01:21 +0200233 1,bad|1,good|1,skip)
Jon Seymour4796e822011-08-04 22:01:01 +1000234 rev=$(git rev-parse --verify $(bisect_head)) ||
235 die "$(gettext "Bad rev input: $(bisect_head)")"
Christian Couderc9c4e2d2008-08-22 05:52:29 +0200236 bisect_write "$state" "$rev"
237 check_expected_revs "$rev" ;;
Christian Coudere3389072008-04-12 07:53:59 +0200238 2,bad|*,good|*,skip)
Christian Couder155fc792007-10-24 07:01:21 +0200239 shift
Christian Couderd3e54c82008-04-14 05:41:45 +0200240 eval=''
Christian Coudere3389072008-04-12 07:53:59 +0200241 for rev in "$@"
Christian Couder155fc792007-10-24 07:01:21 +0200242 do
Christian Coudera179a302008-04-12 02:17:36 -0700243 sha=$(git rev-parse --verify "$rev^{commit}") ||
Ævar Arnfjörð Bjarmason15eaa042011-05-21 18:44:24 +0000244 die "$(eval_gettext "Bad rev input: \$rev")"
Christian Couderd3e54c82008-04-14 05:41:45 +0200245 eval="$eval bisect_write '$state' '$sha'; "
246 done
Christian Couderc9c4e2d2008-08-22 05:52:29 +0200247 eval "$eval"
248 check_expected_revs "$@" ;;
Christian Coudere3389072008-04-12 07:53:59 +0200249 *,bad)
Ævar Arnfjörð Bjarmason9570fc12011-05-21 18:44:23 +0000250 die "$(gettext "'git bisect bad' can take only one argument.")" ;;
Junio C Hamanocc9f24d2005-08-30 12:45:41 -0700251 *)
252 usage ;;
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700253 esac
Christian Couder97e1c512007-10-22 07:48:36 +0200254 bisect_auto_next
255}
256
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700257bisect_next_check() {
Junio C Hamano0a5280a2007-04-05 23:27:44 -0700258 missing_good= missing_bad=
259 git show-ref -q --verify refs/bisect/bad || missing_bad=t
260 test -n "$(git for-each-ref "refs/bisect/good-*")" || missing_good=t
Junio C Hamano6fecf192007-04-05 22:51:14 -0700261
Junio C Hamano0a5280a2007-04-05 23:27:44 -0700262 case "$missing_good,$missing_bad,$1" in
263 ,,*)
264 : have both good and bad - ok
265 ;;
266 *,)
267 # do not have both but not asked to fail - just report.
268 false
269 ;;
270 t,,good)
271 # have bad but not good. we could bisect although
272 # this is less optimum.
Jon Seymour3145b1a2011-08-31 09:09:47 +1000273 gettextln "Warning: bisecting only with a bad commit." >&2
Junio C Hamano0a5280a2007-04-05 23:27:44 -0700274 if test -t 0
275 then
Ævar Arnfjörð Bjarmason04de0992011-05-21 18:44:28 +0000276 # TRANSLATORS: Make sure to include [Y] and [n] in your
277 # translation. The program will only accept English input
278 # at this point.
279 gettext "Are you sure [Y/n]? " >&2
Francis Moreaue5d3afd2008-08-11 19:37:46 +0200280 read yesno
281 case "$yesno" in [Nn]*) exit 1 ;; esac
Junio C Hamano0a5280a2007-04-05 23:27:44 -0700282 fi
283 : bisect without good...
284 ;;
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700285 *)
Ævar Arnfjörð Bjarmasonbe508d32011-05-21 18:44:29 +0000286
287 if test -s "$GIT_DIR/BISECT_START"
288 then
Jon Seymour3145b1a2011-08-31 09:09:47 +1000289 gettextln "You need to give me at least one good and one bad revisions.
290(You can use \"git bisect bad\" and \"git bisect good\" for that.)" >&2
Ævar Arnfjörð Bjarmasonbe508d32011-05-21 18:44:29 +0000291 else
Jon Seymour3145b1a2011-08-31 09:09:47 +1000292 gettextln "You need to start by \"git bisect start\".
Ævar Arnfjörð Bjarmasonbe508d32011-05-21 18:44:29 +0000293You then need to give me at least one good and one bad revisions.
Jon Seymour3145b1a2011-08-31 09:09:47 +1000294(You can use \"git bisect bad\" and \"git bisect good\" for that.)" >&2
Ævar Arnfjörð Bjarmasonbe508d32011-05-21 18:44:29 +0000295 fi
Junio C Hamano0a5280a2007-04-05 23:27:44 -0700296 exit 1 ;;
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700297 esac
298}
299
300bisect_auto_next() {
Junio C Hamano434d0362005-09-17 13:51:03 -0700301 bisect_next_check && bisect_next || :
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700302}
303
304bisect_next() {
Christian Couder8fe26f42007-10-22 07:48:23 +0200305 case "$#" in 0) ;; *) usage ;; esac
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700306 bisect_autostart
Junio C Hamano0a5280a2007-04-05 23:27:44 -0700307 bisect_next_check good
308
Christian Couder08719842009-05-09 17:55:47 +0200309 # Perform all bisection computation, display and checkout
Jon Seymour4796e822011-08-04 22:01:01 +1000310 git bisect--helper --next-all $(test -f "$GIT_DIR/BISECT_HEAD" && echo --no-checkout)
Christian Couder5a1d31c2009-04-19 11:56:16 +0200311 res=$?
Junio C Hamano0a5280a2007-04-05 23:27:44 -0700312
Jon Seymour6021be82011-08-05 21:31:30 +1000313 # Check if we should exit because bisection is finished
Torstein Heggea7f8b8a2013-04-13 17:22:57 +0200314 if test $res -eq 10
315 then
316 bad_rev=$(git show-ref --hash --verify refs/bisect/bad)
317 bad_commit=$(git show-branch $bad_rev)
318 echo "# first bad commit: $bad_commit" >>"$GIT_DIR/BISECT_LOG"
319 exit 0
Torstein Heggef989cac2013-04-22 23:02:29 +0200320 elif test $res -eq 2
321 then
322 echo "# only skipped commits left to test" >>"$GIT_DIR/BISECT_LOG"
323 good_revs=$(git for-each-ref --format="--not %(objectname)" "refs/bisect/good-*")
324 for skipped in $(git rev-list refs/bisect/bad $good_revs)
325 do
326 skipped_commit=$(git show-branch $skipped)
327 echo "# possible first bad commit: $skipped_commit" >>"$GIT_DIR/BISECT_LOG"
328 done
329 exit $res
Torstein Heggea7f8b8a2013-04-13 17:22:57 +0200330 fi
Junio C Hamano0a5280a2007-04-05 23:27:44 -0700331
Christian Couder5a1d31c2009-04-19 11:56:16 +0200332 # Check for an error in the bisection process
333 test $res -ne 0 && exit $res
334
335 return 0
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700336}
337
Junio C Hamanocc9f24d2005-08-30 12:45:41 -0700338bisect_visualize() {
339 bisect_next_check fail
Junio C Hamano235997c2007-12-07 02:25:34 -0800340
341 if test $# = 0
342 then
Jeff Kingc4e4644e2011-03-21 09:14:22 -0400343 if test -n "${DISPLAY+set}${SESSIONNAME+set}${MSYSTEM+set}${SECURITYSESSIONID+set}" &&
Junio C Hamano43b8ff42011-08-05 10:09:23 -0700344 type gitk >/dev/null 2>&1
Jon Seymoureef12a92011-08-05 21:31:31 +1000345 then
Jeff Kingc4e4644e2011-03-21 09:14:22 -0400346 set gitk
347 else
348 set git log
349 fi
Junio C Hamano235997c2007-12-07 02:25:34 -0800350 else
351 case "$1" in
352 git*|tig) ;;
353 -*) set git log "$@" ;;
354 *) set git "$@" ;;
355 esac
356 fi
357
Christian Couderfc13aa32009-11-23 05:16:14 +0100358 eval '"$@"' --bisect -- $(cat "$GIT_DIR/BISECT_NAMES")
Junio C Hamanocc9f24d2005-08-30 12:45:41 -0700359}
360
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700361bisect_reset() {
Christian Couder823ea122008-05-28 18:57:02 +0200362 test -s "$GIT_DIR/BISECT_START" || {
Jon Seymour3145b1a2011-08-31 09:09:47 +1000363 gettextln "We are not bisecting."
Christian Couderfce04992007-11-20 06:39:53 +0100364 return
365 }
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700366 case "$#" in
Christian Couder823ea122008-05-28 18:57:02 +0200367 0) branch=$(cat "$GIT_DIR/BISECT_START") ;;
Ævar Arnfjörð Bjarmason7d0c2d62011-05-21 18:44:26 +0000368 1) git rev-parse --quiet --verify "$1^{commit}" > /dev/null || {
Jon Seymour6021be82011-08-05 21:31:30 +1000369 invalid="$1"
370 die "$(eval_gettext "'\$invalid' is not a valid commit")"
371 }
372 branch="$1" ;;
Christian Couder8fe26f42007-10-22 07:48:23 +0200373 *)
Jon Seymour6021be82011-08-05 21:31:30 +1000374 usage ;;
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700375 esac
Junio C Hamano43b8ff42011-08-05 10:09:23 -0700376
377 if ! test -f "$GIT_DIR/BISECT_HEAD" && ! git checkout "$branch" --
Jon Seymour4796e822011-08-04 22:01:01 +1000378 then
Junio C Hamano43b8ff42011-08-05 10:09:23 -0700379 die "$(eval_gettext "Could not check out original HEAD '\$branch'.
Ævar Arnfjörð Bjarmason15eaa042011-05-21 18:44:24 +0000380Try 'git bisect reset <commit>'.")"
SZEDER Gábor3bb8cf82010-10-10 23:48:57 +0200381 fi
Jon Seymour4796e822011-08-04 22:01:01 +1000382 bisect_clean_state
Junio C Hamanoe204de22005-09-10 15:18:31 -0700383}
384
Christian Couder38a47fd2007-04-04 07:12:02 +0200385bisect_clean_state() {
Christian Couder947a6042007-11-15 08:18:07 +0100386 # There may be some refs packed during bisection.
Christian Couder634f2462008-05-23 01:28:57 +0200387 git for-each-ref --format='%(refname) %(objectname)' refs/bisect/\* |
Christian Couder947a6042007-11-15 08:18:07 +0100388 while read ref hash
389 do
Christian Couder823ea122008-05-28 18:57:02 +0200390 git update-ref -d $ref $hash || exit
Christian Couder947a6042007-11-15 08:18:07 +0100391 done
Christian Couderc9c4e2d2008-08-22 05:52:29 +0200392 rm -f "$GIT_DIR/BISECT_EXPECTED_REV" &&
393 rm -f "$GIT_DIR/BISECT_ANCESTORS_OK" &&
Christian Couder823ea122008-05-28 18:57:02 +0200394 rm -f "$GIT_DIR/BISECT_LOG" &&
395 rm -f "$GIT_DIR/BISECT_NAMES" &&
396 rm -f "$GIT_DIR/BISECT_RUN" &&
Christian Couder9d0cd912008-05-23 00:38:59 +0200397 # Cleanup head-name if it got left by an old version of git-bisect
Christian Couder823ea122008-05-28 18:57:02 +0200398 rm -f "$GIT_DIR/head-name" &&
Jon Seymour4796e822011-08-04 22:01:01 +1000399 git update-ref -d --no-deref BISECT_HEAD &&
400 # clean up BISECT_START last
Christian Couder823ea122008-05-28 18:57:02 +0200401 rm -f "$GIT_DIR/BISECT_START"
Christian Couder38a47fd2007-04-04 07:12:02 +0200402}
403
Junio C Hamanoe204de22005-09-10 15:18:31 -0700404bisect_replay () {
Ævar Arnfjörð Bjarmason55a9fc82011-05-21 18:44:27 +0000405 file="$1"
406 test "$#" -eq 1 || die "$(gettext "No logfile given")"
407 test -r "$file" || die "$(eval_gettext "cannot read \$file for replaying")"
Junio C Hamanoe204de22005-09-10 15:18:31 -0700408 bisect_reset
Miklos Vajna6c98c052008-07-11 18:01:29 +0200409 while read git bisect command rev
Junio C Hamanoe204de22005-09-10 15:18:31 -0700410 do
Miklos Vajna6c98c052008-07-11 18:01:29 +0200411 test "$git $bisect" = "git bisect" -o "$git" = "git-bisect" || continue
Jon Seymoureef12a92011-08-05 21:31:31 +1000412 if test "$git" = "git-bisect"
413 then
Miklos Vajna6c98c052008-07-11 18:01:29 +0200414 rev="$command"
415 command="$bisect"
416 fi
Junio C Hamanoe204de22005-09-10 15:18:31 -0700417 case "$command" in
418 start)
Junio C Hamanoe9a45d72005-11-27 17:42:05 -0800419 cmd="bisect_start $rev"
Christian Couder737c74e2007-10-24 07:01:13 +0200420 eval "$cmd" ;;
421 good|bad|skip)
422 bisect_write "$command" "$rev" ;;
Junio C Hamanoe204de22005-09-10 15:18:31 -0700423 *)
Ævar Arnfjörð Bjarmason9570fc12011-05-21 18:44:23 +0000424 die "$(gettext "?? what are you talking about?")" ;;
Junio C Hamanoe204de22005-09-10 15:18:31 -0700425 esac
Ævar Arnfjörð Bjarmason55a9fc82011-05-21 18:44:27 +0000426 done <"$file"
Junio C Hamanoe204de22005-09-10 15:18:31 -0700427 bisect_auto_next
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700428}
429
Christian Coudera17c4102007-03-23 08:49:59 +0100430bisect_run () {
Jon Seymour6021be82011-08-05 21:31:30 +1000431 bisect_next_check fail
Christian Couder83020122007-03-27 06:49:57 +0200432
Jon Seymour6021be82011-08-05 21:31:30 +1000433 while true
434 do
435 command="$@"
Jon Seymour3145b1a2011-08-31 09:09:47 +1000436 eval_gettextln "running \$command"
Jon Seymour6021be82011-08-05 21:31:30 +1000437 "$@"
438 res=$?
Christian Coudera17c4102007-03-23 08:49:59 +0100439
Jon Seymour6021be82011-08-05 21:31:30 +1000440 # Check for really bad run error.
Jon Seymoureef12a92011-08-05 21:31:31 +1000441 if [ $res -lt 0 -o $res -ge 128 ]
442 then
Jon Seymour3145b1a2011-08-31 09:09:47 +1000443 eval_gettextln "bisect run failed:
444exit code \$res from '\$command' is < 0 or >= 128" >&2
Jon Seymour6021be82011-08-05 21:31:30 +1000445 exit $res
446 fi
Christian Coudera17c4102007-03-23 08:49:59 +0100447
Jon Seymour6021be82011-08-05 21:31:30 +1000448 # Find current state depending on run success or failure.
449 # A special exit code of 125 means cannot test.
Jon Seymoureef12a92011-08-05 21:31:31 +1000450 if [ $res -eq 125 ]
451 then
Jon Seymour6021be82011-08-05 21:31:30 +1000452 state='skip'
Jon Seymoureef12a92011-08-05 21:31:31 +1000453 elif [ $res -gt 0 ]
454 then
Jon Seymour6021be82011-08-05 21:31:30 +1000455 state='bad'
456 else
457 state='good'
458 fi
Christian Coudera17c4102007-03-23 08:49:59 +0100459
Jon Seymour6021be82011-08-05 21:31:30 +1000460 # We have to use a subshell because "bisect_state" can exit.
461 ( bisect_state $state > "$GIT_DIR/BISECT_RUN" )
462 res=$?
Christian Coudera17c4102007-03-23 08:49:59 +0100463
Jon Seymour6021be82011-08-05 21:31:30 +1000464 cat "$GIT_DIR/BISECT_RUN"
Christian Coudera17c4102007-03-23 08:49:59 +0100465
Jon Seymour6021be82011-08-05 21:31:30 +1000466 if sane_grep "first bad commit could be any of" "$GIT_DIR/BISECT_RUN" \
Jon Seymoureef12a92011-08-05 21:31:31 +1000467 > /dev/null
468 then
Jon Seymour3145b1a2011-08-31 09:09:47 +1000469 gettextln "bisect run cannot continue any more" >&2
Jon Seymour6021be82011-08-05 21:31:30 +1000470 exit $res
471 fi
Christian Couder71b02512007-10-26 05:39:37 +0200472
Jon Seymoureef12a92011-08-05 21:31:31 +1000473 if [ $res -ne 0 ]
474 then
Jon Seymour3145b1a2011-08-31 09:09:47 +1000475 eval_gettextln "bisect run failed:
476'bisect_state \$state' exited with error code \$res" >&2
Jon Seymour6021be82011-08-05 21:31:30 +1000477 exit $res
478 fi
Christian Coudera17c4102007-03-23 08:49:59 +0100479
Jon Seymoureef12a92011-08-05 21:31:31 +1000480 if sane_grep "is the first bad commit" "$GIT_DIR/BISECT_RUN" > /dev/null
481 then
Jon Seymour3145b1a2011-08-31 09:09:47 +1000482 gettextln "bisect run success"
Jon Seymour6021be82011-08-05 21:31:30 +1000483 exit 0;
484 fi
Christian Coudera17c4102007-03-23 08:49:59 +0100485
Jon Seymour6021be82011-08-05 21:31:30 +1000486 done
Christian Coudera17c4102007-03-23 08:49:59 +0100487}
488
SZEDER Gábor412ff732010-10-10 23:48:56 +0200489bisect_log () {
Ævar Arnfjörð Bjarmason9570fc12011-05-21 18:44:23 +0000490 test -s "$GIT_DIR/BISECT_LOG" || die "$(gettext "We are not bisecting.")"
SZEDER Gábor412ff732010-10-10 23:48:56 +0200491 cat "$GIT_DIR/BISECT_LOG"
492}
Christian Coudera17c4102007-03-23 08:49:59 +0100493
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700494case "$#" in
4950)
Jon Seymour6021be82011-08-05 21:31:30 +1000496 usage ;;
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700497*)
Jon Seymour6021be82011-08-05 21:31:30 +1000498 cmd="$1"
499 shift
500 case "$cmd" in
501 help)
502 git bisect -h ;;
503 start)
504 bisect_start "$@" ;;
505 bad|good)
506 bisect_state "$cmd" "$@" ;;
507 skip)
508 bisect_skip "$@" ;;
509 next)
510 # Not sure we want "next" at the UI level anymore.
511 bisect_next "$@" ;;
512 visualize|view)
513 bisect_visualize "$@" ;;
514 reset)
515 bisect_reset "$@" ;;
516 replay)
517 bisect_replay "$@" ;;
518 log)
519 bisect_log ;;
520 run)
521 bisect_run "$@" ;;
522 *)
523 usage ;;
524 esac
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700525esac