3 USAGE
='[start|bad|good|skip|next|reset|visualize|replay|log|run]'
4 LONG_USAGE
='git bisect start [<bad> [<good>...]] [--] [<pathspec>...]
5 reset bisect state and start bisection.
7 mark <rev> a known-bad revision.
8 git bisect good [<rev>...]
9 mark <rev>... known-good revisions.
10 git bisect skip [<rev>...]
11 mark <rev>... untestable revisions.
13 find next bisection to test and check it out.
14 git bisect reset [<branch>]
15 finish bisection search and go back to branch.
17 show bisect status in gitk.
18 git bisect replay <logfile>
22 git bisect run <cmd>...
23 use <cmd>... to automatically bisect.'
31 s/'\''/'\'\\\\\'\''/g;
39 test -f "$GIT_DIR/BISECT_NAMES" ||
{
40 echo >&2 'You need to start by "git bisect start"'
43 echo >&2 -n 'Do you want me to do it for you [Y/n]? '
58 # Verify HEAD. If we were bisecting before this, reset to the
59 # top-of-line master first!
61 head=$
(GIT_DIR
="$GIT_DIR" git symbolic-ref HEAD
) ||
62 die
"Bad HEAD - I need a symbolic ref"
65 if [ -s "$GIT_DIR/head-name" ]; then
66 branch
=`cat "$GIT_DIR/head-name"`
70 git checkout
$branch ||
exit
73 [ -s "$GIT_DIR/head-name" ] && die
"won't bisect on seeked tree"
74 echo "${head#refs/heads/}" >"$GIT_DIR/head-name"
77 die
"Bad HEAD - strange symbolic ref"
82 # Get rid of any old bisect state
87 # Check for one bad and then some good revisions.
91 case "$arg" in --) has_double_dash
=1; break ;; esac
95 while [ $# -gt 0 ]; do
103 rev=$
(git rev-parse
--verify "$arg^{commit}" 2>/dev
/null
) ||
{
104 test $has_double_dash -eq 1 &&
105 die
"'$arg' does not appear to be a valid revision"
109 0) state
='bad' ; bad_seen
=1 ;;
112 bisect_write
"$state" "$rev" 'nolog'
118 sq "$@" >"$GIT_DIR/BISECT_NAMES"
119 echo "git-bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG"
129 good|skip
) tag
="$state"-"$rev" ;;
130 *) die
"Bad bisect_write argument: $state" ;;
132 git update-ref
"refs/bisect/$tag" "$rev"
133 echo "# $state: "$
(git show-branch
$rev) >>"$GIT_DIR/BISECT_LOG"
134 test -z "$nolog" && echo "git-bisect $state $rev" >>"$GIT_DIR/BISECT_LOG"
142 die
"Please call 'bisect_state' with at least one argument." ;;
144 rev=$
(git rev-parse
--verify HEAD
) ||
145 die
"Bad rev input: HEAD"
146 bisect_write
"$state" "$rev" ;;
148 rev=$
(git rev-parse
--verify "$2^{commit}") ||
149 die
"Bad rev input: $2"
150 bisect_write
"$state" "$rev" ;;
153 revs
=$
(git rev-parse
--revs-only --no-flags "$@") &&
154 test '' != "$revs" || die
"Bad rev input: $@"
157 rev=$
(git rev-parse
--verify "$rev^{commit}") ||
158 die
"Bad rev commit: $rev^{commit}"
159 bisect_write
"$state" "$rev"
167 bisect_next_check
() {
168 missing_good
= missing_bad
=
169 git show-ref
-q --verify refs
/bisect
/bad || missing_bad
=t
170 test -n "$(git for-each-ref "refs
/bisect
/good-
*")" || missing_good
=t
172 case "$missing_good,$missing_bad,$1" in
174 : have both good and bad
- ok
177 # do not have both but not asked to fail - just report.
181 # have bad but not good. we could bisect although
182 # this is less optimum.
183 echo >&2 'Warning: bisecting only with a bad commit.'
186 printf >&2 'Are you sure [Y/n]? '
187 case "$(read yesno)" in [Nn
]*) exit 1 ;; esac
189 : bisect without good...
193 test -f "$GIT_DIR/BISECT_NAMES" ||
{
194 echo >&2 'You need to start by "git bisect start".'
197 echo >&2 'You '$THEN'need to give me at least one good' \
198 'and one bad revisions.'
199 echo >&2 '(You can use "git bisect bad" and' \
200 '"git bisect good" for that.)'
206 bisect_next_check
&& bisect_next ||
:
213 if [ -z "$_skip" ]; then
218 # Let's parse the output of:
219 # "git rev-list --bisect-vars --bisect-all ..."
220 eval $_eval |
while read hash line
222 case "$VARS,$FOUND,$TRIED,$hash" in
223 # We display some vars.
224 1,*,*,*) echo "$hash $line" ;;
229 # We had nothing to search.
235 # We did not find a good bisect rev.
236 # This should happen only if the "bad"
237 # commit is also a "skip" commit.
239 echo "bisect_rev=$TRIED"
245 TRIED
="${TRIED:+$TRIED|}$hash"
249 echo "bisect_rev=$hash"
250 echo "bisect_tried=\"$TRIED\""
256 # We have already found a rev to be tested.
257 ,1,*,bisect_rev
*) VARS
=1 ;;
261 *) die
"filter_skipped error " \
272 exit_if_skipped_commits
() {
274 if expr "$_tried" : ".*[|].*" > /dev
/null
; then
275 echo "There are only 'skip'ped commit left to test."
276 echo "The first bad commit could be any of:"
277 echo "$_tried" |
tr '[|]' '[\012]'
278 echo "We cannot bisect more!"
284 case "$#" in 0) ;; *) usage
;; esac
286 bisect_next_check good
288 skip
=$
(git for-each-ref
--format='%(objectname)' \
289 "refs/bisect/skip-*" |
tr '[\012]' ' ') ||
exit
292 test -n "$skip" && BISECT_OPT
='--bisect-all'
294 bad
=$
(git rev-parse
--verify refs
/bisect
/bad
) &&
295 good
=$
(git for-each-ref
--format='^%(objectname)' \
296 "refs/bisect/good-*" |
tr '[\012]' ' ') &&
297 eval="git rev-list --bisect-vars $BISECT_OPT $good $bad --" &&
298 eval="$eval $(cat "$GIT_DIR/BISECT_NAMES
")" &&
299 eval=$
(filter_skipped
"$eval" "$skip") &&
302 if [ -z "$bisect_rev" ]; then
303 echo "$bad was both good and bad"
306 if [ "$bisect_rev" = "$bad" ]; then
307 exit_if_skipped_commits
"$bisect_tried"
308 echo "$bisect_rev is first bad commit"
309 git diff-tree
--pretty $bisect_rev
313 # We should exit here only if the "bad"
314 # commit is also a "skip" commit (see above).
315 exit_if_skipped_commits
"$bisect_rev"
317 echo "Bisecting: $bisect_nr revisions left to test after this"
318 git branch
-f new-bisect
"$bisect_rev"
319 git checkout
-q new-bisect ||
exit
320 git branch
-M new-bisect bisect
321 git show-branch
"$bisect_rev"
325 bisect_next_check fail
326 not
=$
(git for-each-ref
--format='%(refname)' "refs/bisect/good-*")
327 eval gitk refs
/bisect
/bad
--not $not -- $
(cat "$GIT_DIR/BISECT_NAMES")
332 0) if [ -s "$GIT_DIR/head-name" ]; then
333 branch
=`cat "$GIT_DIR/head-name"`
337 1) git show-ref
--verify --quiet -- "refs/heads/$1" ||
338 die
"$1 does not seem to be a valid branch"
343 if git checkout
"$branch"; then
344 rm -f "$GIT_DIR/head-name"
349 bisect_clean_state
() {
350 # There may be some refs packed during bisection.
351 git for-each-ref
--format='%(refname) %(objectname)' refs
/bisect
/\
* refs
/heads
/bisect |
354 git update-ref
-d $ref $hash
356 rm -f "$GIT_DIR/BISECT_LOG"
357 rm -f "$GIT_DIR/BISECT_NAMES"
358 rm -f "$GIT_DIR/BISECT_RUN"
362 test -r "$1" || die
"cannot read $1 for replaying"
364 while read bisect
command rev
366 test "$bisect" = "git-bisect" ||
continue
369 cmd
="bisect_start $rev"
372 bisect_write
"$command" "$rev" ;;
374 die
"?? what are you talking about?" ;;
381 bisect_next_check fail
389 # Check for really bad run error.
390 if [ $res -lt 0 -o $res -ge 128 ]; then
391 echo >&2 "bisect run failed:"
392 echo >&2 "exit code $res from '$@' is < 0 or >= 128"
396 # Find current state depending on run success or failure.
397 # A special exit code of 125 means cannot test.
398 if [ $res -eq 125 ]; then
400 elif [ $res -gt 0 ]; then
406 # We have to use a subshell because "bisect_state" can exit.
407 ( bisect_state
$state > "$GIT_DIR/BISECT_RUN" )
410 cat "$GIT_DIR/BISECT_RUN"
412 if grep "first bad commit could be any of" "$GIT_DIR/BISECT_RUN" \
414 echo >&2 "bisect run cannot continue any more"
418 if [ $res -ne 0 ]; then
419 echo >&2 "bisect run failed:"
420 echo >&2 "'bisect_state $state' exited with error code $res"
424 if grep "is first bad commit" "$GIT_DIR/BISECT_RUN" > /dev
/null
; then
425 echo "bisect run success"
443 bisect_state
"$cmd" "$@" ;;
445 # Not sure we want "next" at the UI level anymore.
448 bisect_visualize
"$@" ;;
452 bisect_replay
"$@" ;;
454 cat "$GIT_DIR/BISECT_LOG" ;;