blob: 99efbe884528ffa730d6c0297e20d9de93d5ad9e [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
Christian Couder5a1d31c2009-04-19 11:56:16 +0200314 test $res -eq 10 && exit 0
Junio C Hamano0a5280a2007-04-05 23:27:44 -0700315
Christian Couder5a1d31c2009-04-19 11:56:16 +0200316 # Check for an error in the bisection process
317 test $res -ne 0 && exit $res
318
319 return 0
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700320}
321
Junio C Hamanocc9f24d2005-08-30 12:45:41 -0700322bisect_visualize() {
323 bisect_next_check fail
Junio C Hamano235997c2007-12-07 02:25:34 -0800324
325 if test $# = 0
326 then
Jeff Kingc4e4644e2011-03-21 09:14:22 -0400327 if test -n "${DISPLAY+set}${SESSIONNAME+set}${MSYSTEM+set}${SECURITYSESSIONID+set}" &&
Junio C Hamano43b8ff42011-08-05 10:09:23 -0700328 type gitk >/dev/null 2>&1
Jon Seymoureef12a92011-08-05 21:31:31 +1000329 then
Jeff Kingc4e4644e2011-03-21 09:14:22 -0400330 set gitk
331 else
332 set git log
333 fi
Junio C Hamano235997c2007-12-07 02:25:34 -0800334 else
335 case "$1" in
336 git*|tig) ;;
337 -*) set git log "$@" ;;
338 *) set git "$@" ;;
339 esac
340 fi
341
Christian Couderfc13aa32009-11-23 05:16:14 +0100342 eval '"$@"' --bisect -- $(cat "$GIT_DIR/BISECT_NAMES")
Junio C Hamanocc9f24d2005-08-30 12:45:41 -0700343}
344
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700345bisect_reset() {
Christian Couder823ea122008-05-28 18:57:02 +0200346 test -s "$GIT_DIR/BISECT_START" || {
Jon Seymour3145b1a2011-08-31 09:09:47 +1000347 gettextln "We are not bisecting."
Christian Couderfce04992007-11-20 06:39:53 +0100348 return
349 }
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700350 case "$#" in
Christian Couder823ea122008-05-28 18:57:02 +0200351 0) branch=$(cat "$GIT_DIR/BISECT_START") ;;
Ævar Arnfjörð Bjarmason7d0c2d62011-05-21 18:44:26 +0000352 1) git rev-parse --quiet --verify "$1^{commit}" > /dev/null || {
Jon Seymour6021be82011-08-05 21:31:30 +1000353 invalid="$1"
354 die "$(eval_gettext "'\$invalid' is not a valid commit")"
355 }
356 branch="$1" ;;
Christian Couder8fe26f42007-10-22 07:48:23 +0200357 *)
Jon Seymour6021be82011-08-05 21:31:30 +1000358 usage ;;
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700359 esac
Junio C Hamano43b8ff42011-08-05 10:09:23 -0700360
361 if ! test -f "$GIT_DIR/BISECT_HEAD" && ! git checkout "$branch" --
Jon Seymour4796e822011-08-04 22:01:01 +1000362 then
Junio C Hamano43b8ff42011-08-05 10:09:23 -0700363 die "$(eval_gettext "Could not check out original HEAD '\$branch'.
Ævar Arnfjörð Bjarmason15eaa042011-05-21 18:44:24 +0000364Try 'git bisect reset <commit>'.")"
SZEDER Gábor3bb8cf82010-10-10 23:48:57 +0200365 fi
Jon Seymour4796e822011-08-04 22:01:01 +1000366 bisect_clean_state
Junio C Hamanoe204de22005-09-10 15:18:31 -0700367}
368
Christian Couder38a47fd2007-04-04 07:12:02 +0200369bisect_clean_state() {
Christian Couder947a6042007-11-15 08:18:07 +0100370 # There may be some refs packed during bisection.
Christian Couder634f2462008-05-23 01:28:57 +0200371 git for-each-ref --format='%(refname) %(objectname)' refs/bisect/\* |
Christian Couder947a6042007-11-15 08:18:07 +0100372 while read ref hash
373 do
Christian Couder823ea122008-05-28 18:57:02 +0200374 git update-ref -d $ref $hash || exit
Christian Couder947a6042007-11-15 08:18:07 +0100375 done
Christian Couderc9c4e2d2008-08-22 05:52:29 +0200376 rm -f "$GIT_DIR/BISECT_EXPECTED_REV" &&
377 rm -f "$GIT_DIR/BISECT_ANCESTORS_OK" &&
Christian Couder823ea122008-05-28 18:57:02 +0200378 rm -f "$GIT_DIR/BISECT_LOG" &&
379 rm -f "$GIT_DIR/BISECT_NAMES" &&
380 rm -f "$GIT_DIR/BISECT_RUN" &&
Christian Couder9d0cd912008-05-23 00:38:59 +0200381 # Cleanup head-name if it got left by an old version of git-bisect
Christian Couder823ea122008-05-28 18:57:02 +0200382 rm -f "$GIT_DIR/head-name" &&
Jon Seymour4796e822011-08-04 22:01:01 +1000383 git update-ref -d --no-deref BISECT_HEAD &&
384 # clean up BISECT_START last
Christian Couder823ea122008-05-28 18:57:02 +0200385 rm -f "$GIT_DIR/BISECT_START"
Christian Couder38a47fd2007-04-04 07:12:02 +0200386}
387
Junio C Hamanoe204de22005-09-10 15:18:31 -0700388bisect_replay () {
Ævar Arnfjörð Bjarmason55a9fc82011-05-21 18:44:27 +0000389 file="$1"
390 test "$#" -eq 1 || die "$(gettext "No logfile given")"
391 test -r "$file" || die "$(eval_gettext "cannot read \$file for replaying")"
Junio C Hamanoe204de22005-09-10 15:18:31 -0700392 bisect_reset
Miklos Vajna6c98c052008-07-11 18:01:29 +0200393 while read git bisect command rev
Junio C Hamanoe204de22005-09-10 15:18:31 -0700394 do
Miklos Vajna6c98c052008-07-11 18:01:29 +0200395 test "$git $bisect" = "git bisect" -o "$git" = "git-bisect" || continue
Jon Seymoureef12a92011-08-05 21:31:31 +1000396 if test "$git" = "git-bisect"
397 then
Miklos Vajna6c98c052008-07-11 18:01:29 +0200398 rev="$command"
399 command="$bisect"
400 fi
Junio C Hamanoe204de22005-09-10 15:18:31 -0700401 case "$command" in
402 start)
Junio C Hamanoe9a45d72005-11-27 17:42:05 -0800403 cmd="bisect_start $rev"
Christian Couder737c74e2007-10-24 07:01:13 +0200404 eval "$cmd" ;;
405 good|bad|skip)
406 bisect_write "$command" "$rev" ;;
Junio C Hamanoe204de22005-09-10 15:18:31 -0700407 *)
Ævar Arnfjörð Bjarmason9570fc12011-05-21 18:44:23 +0000408 die "$(gettext "?? what are you talking about?")" ;;
Junio C Hamanoe204de22005-09-10 15:18:31 -0700409 esac
Ævar Arnfjörð Bjarmason55a9fc82011-05-21 18:44:27 +0000410 done <"$file"
Junio C Hamanoe204de22005-09-10 15:18:31 -0700411 bisect_auto_next
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700412}
413
Christian Coudera17c4102007-03-23 08:49:59 +0100414bisect_run () {
Jon Seymour6021be82011-08-05 21:31:30 +1000415 bisect_next_check fail
Christian Couder83020122007-03-27 06:49:57 +0200416
Jon Seymour6021be82011-08-05 21:31:30 +1000417 while true
418 do
419 command="$@"
Jon Seymour3145b1a2011-08-31 09:09:47 +1000420 eval_gettextln "running \$command"
Jon Seymour6021be82011-08-05 21:31:30 +1000421 "$@"
422 res=$?
Christian Coudera17c4102007-03-23 08:49:59 +0100423
Jon Seymour6021be82011-08-05 21:31:30 +1000424 # Check for really bad run error.
Jon Seymoureef12a92011-08-05 21:31:31 +1000425 if [ $res -lt 0 -o $res -ge 128 ]
426 then
Jon Seymour3145b1a2011-08-31 09:09:47 +1000427 eval_gettextln "bisect run failed:
428exit code \$res from '\$command' is < 0 or >= 128" >&2
Jon Seymour6021be82011-08-05 21:31:30 +1000429 exit $res
430 fi
Christian Coudera17c4102007-03-23 08:49:59 +0100431
Jon Seymour6021be82011-08-05 21:31:30 +1000432 # Find current state depending on run success or failure.
433 # A special exit code of 125 means cannot test.
Jon Seymoureef12a92011-08-05 21:31:31 +1000434 if [ $res -eq 125 ]
435 then
Jon Seymour6021be82011-08-05 21:31:30 +1000436 state='skip'
Jon Seymoureef12a92011-08-05 21:31:31 +1000437 elif [ $res -gt 0 ]
438 then
Jon Seymour6021be82011-08-05 21:31:30 +1000439 state='bad'
440 else
441 state='good'
442 fi
Christian Coudera17c4102007-03-23 08:49:59 +0100443
Jon Seymour6021be82011-08-05 21:31:30 +1000444 # We have to use a subshell because "bisect_state" can exit.
445 ( bisect_state $state > "$GIT_DIR/BISECT_RUN" )
446 res=$?
Christian Coudera17c4102007-03-23 08:49:59 +0100447
Jon Seymour6021be82011-08-05 21:31:30 +1000448 cat "$GIT_DIR/BISECT_RUN"
Christian Coudera17c4102007-03-23 08:49:59 +0100449
Jon Seymour6021be82011-08-05 21:31:30 +1000450 if sane_grep "first bad commit could be any of" "$GIT_DIR/BISECT_RUN" \
Jon Seymoureef12a92011-08-05 21:31:31 +1000451 > /dev/null
452 then
Jon Seymour3145b1a2011-08-31 09:09:47 +1000453 gettextln "bisect run cannot continue any more" >&2
Jon Seymour6021be82011-08-05 21:31:30 +1000454 exit $res
455 fi
Christian Couder71b02512007-10-26 05:39:37 +0200456
Jon Seymoureef12a92011-08-05 21:31:31 +1000457 if [ $res -ne 0 ]
458 then
Jon Seymour3145b1a2011-08-31 09:09:47 +1000459 eval_gettextln "bisect run failed:
460'bisect_state \$state' exited with error code \$res" >&2
Jon Seymour6021be82011-08-05 21:31:30 +1000461 exit $res
462 fi
Christian Coudera17c4102007-03-23 08:49:59 +0100463
Jon Seymoureef12a92011-08-05 21:31:31 +1000464 if sane_grep "is the first bad commit" "$GIT_DIR/BISECT_RUN" > /dev/null
465 then
Jon Seymour3145b1a2011-08-31 09:09:47 +1000466 gettextln "bisect run success"
Jon Seymour6021be82011-08-05 21:31:30 +1000467 exit 0;
468 fi
Christian Coudera17c4102007-03-23 08:49:59 +0100469
Jon Seymour6021be82011-08-05 21:31:30 +1000470 done
Christian Coudera17c4102007-03-23 08:49:59 +0100471}
472
SZEDER Gábor412ff732010-10-10 23:48:56 +0200473bisect_log () {
Ævar Arnfjörð Bjarmason9570fc12011-05-21 18:44:23 +0000474 test -s "$GIT_DIR/BISECT_LOG" || die "$(gettext "We are not bisecting.")"
SZEDER Gábor412ff732010-10-10 23:48:56 +0200475 cat "$GIT_DIR/BISECT_LOG"
476}
Christian Coudera17c4102007-03-23 08:49:59 +0100477
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700478case "$#" in
4790)
Jon Seymour6021be82011-08-05 21:31:30 +1000480 usage ;;
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700481*)
Jon Seymour6021be82011-08-05 21:31:30 +1000482 cmd="$1"
483 shift
484 case "$cmd" in
485 help)
486 git bisect -h ;;
487 start)
488 bisect_start "$@" ;;
489 bad|good)
490 bisect_state "$cmd" "$@" ;;
491 skip)
492 bisect_skip "$@" ;;
493 next)
494 # Not sure we want "next" at the UI level anymore.
495 bisect_next "$@" ;;
496 visualize|view)
497 bisect_visualize "$@" ;;
498 reset)
499 bisect_reset "$@" ;;
500 replay)
501 bisect_replay "$@" ;;
502 log)
503 bisect_log ;;
504 run)
505 bisect_run "$@" ;;
506 *)
507 usage ;;
508 esac
Linus Torvalds8cc6a082005-07-30 10:08:20 -0700509esac