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.'
29 _x40
='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
30 _x40
="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
35 s/'\''/'\'\\\\\'\''/g;
43 test -f "$GIT_DIR/BISECT_NAMES" ||
{
44 echo >&2 'You need to start by "git bisect start"'
47 echo >&2 -n 'Do you want me to do it for you [Y/n]? '
62 # Verify HEAD. If we were bisecting before this, reset to the
63 # top-of-line master first!
65 head=$
(GIT_DIR
="$GIT_DIR" git symbolic-ref
-q HEAD
) ||
66 head=$
(GIT_DIR
="$GIT_DIR" git rev-parse
--verify HEAD
) ||
67 die
"Bad HEAD - I need a HEAD"
69 # Check that we either already have BISECT_START, or that the
70 # branches bisect, new-bisect don't exist, to not override them.
72 test -s "$GIT_DIR/BISECT_START" ||
73 if git show-ref
--verify -q refs
/heads
/bisect ||
74 git show-ref
--verify -q refs
/heads
/new-bisect
; then
75 die
'The branches "bisect" and "new-bisect" must not exist.'
80 branch
=`cat "$GIT_DIR/BISECT_START"`
81 git checkout
$branch ||
exit
84 # This error message should only be triggered by cogito usage,
85 # and cogito users should understand it relates to cg-seek.
86 [ -s "$GIT_DIR/head-name" ] && die
"won't bisect on seeked tree"
87 start_head
="${head#refs/heads/}"
90 die
"Bad HEAD - strange symbolic ref"
95 # Get rid of any old bisect state
100 # Check for one bad and then some good revisions.
104 case "$arg" in --) has_double_dash
=1; break ;; esac
109 while [ $# -gt 0 ]; do
117 rev=$
(git rev-parse
--verify "$arg^{commit}" 2>/dev
/null
) ||
{
118 test $has_double_dash -eq 1 &&
119 die
"'$arg' does not appear to be a valid revision"
123 0) state
='bad' ; bad_seen
=1 ;;
126 eval="$eval bisect_write '$state' '$rev' 'nolog'; "
132 sq "$@" >"$GIT_DIR/BISECT_NAMES"
133 test -n "$start_head" && echo "$start_head" >"$GIT_DIR/BISECT_START"
135 echo "git-bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG"
145 good|skip
) tag
="$state"-"$rev" ;;
146 *) die
"Bad bisect_write argument: $state" ;;
148 git update-ref
"refs/bisect/$tag" "$rev"
149 echo "# $state: $(git show-branch $rev)" >>"$GIT_DIR/BISECT_LOG"
150 test -z "$nolog" && echo "git-bisect $state $rev" >>"$GIT_DIR/BISECT_LOG"
158 die
"Please call 'bisect_state' with at least one argument." ;;
160 rev=$
(git rev-parse
--verify HEAD
) ||
161 die
"Bad rev input: HEAD"
162 bisect_write
"$state" "$rev" ;;
168 sha
=$
(git rev-parse
--verify "$rev^{commit}") ||
169 die
"Bad rev input: $rev"
170 eval="$eval bisect_write '$state' '$sha'; "
174 die
"'git bisect bad' can take only one argument." ;;
181 bisect_next_check
() {
182 missing_good
= missing_bad
=
183 git show-ref
-q --verify refs
/bisect
/bad || missing_bad
=t
184 test -n "$(git for-each-ref "refs
/bisect
/good-
*")" || missing_good
=t
186 case "$missing_good,$missing_bad,$1" in
188 : have both good and bad
- ok
191 # do not have both but not asked to fail - just report.
195 # have bad but not good. we could bisect although
196 # this is less optimum.
197 echo >&2 'Warning: bisecting only with a bad commit.'
200 printf >&2 'Are you sure [Y/n]? '
201 case "$(read yesno)" in [Nn
]*) exit 1 ;; esac
203 : bisect without good...
207 test -f "$GIT_DIR/BISECT_NAMES" ||
{
208 echo >&2 'You need to start by "git bisect start".'
211 echo >&2 'You '$THEN'need to give me at least one good' \
212 'and one bad revisions.'
213 echo >&2 '(You can use "git bisect bad" and' \
214 '"git bisect good" for that.)'
220 bisect_next_check
&& bisect_next ||
:
229 if [ $res -ne 0 ]; then
230 echo >&2 "'git rev-list --bisect-vars' failed:"
231 echo >&2 "maybe you mistake good and bad revs?"
242 if [ -z "$_skip" ]; then
243 eval_rev_list
"$_eval"
247 # Let's parse the output of:
248 # "git rev-list --bisect-vars --bisect-all ..."
249 eval_rev_list
"$_eval" |
while read hash line
251 case "$VARS,$FOUND,$TRIED,$hash" in
252 # We display some vars.
253 1,*,*,*) echo "$hash $line" ;;
258 # We had nothing to search.
264 # We did not find a good bisect rev.
265 # This should happen only if the "bad"
266 # commit is also a "skip" commit.
268 echo "bisect_rev=$TRIED"
274 TRIED
="${TRIED:+$TRIED|}$hash"
278 echo "bisect_rev=$hash"
279 echo "bisect_tried=\"$TRIED\""
285 # We have already found a rev to be tested.
286 ,1,*,bisect_rev
*) VARS
=1 ;;
290 *) die
"filter_skipped error " \
301 exit_if_skipped_commits
() {
303 if expr "$_tried" : ".*[|].*" > /dev
/null
; then
304 echo "There are only 'skip'ped commit left to test."
305 echo "The first bad commit could be any of:"
306 echo "$_tried" |
tr '[|]' '[\012]'
307 echo "We cannot bisect more!"
313 case "$#" in 0) ;; *) usage
;; esac
315 bisect_next_check good
317 skip
=$
(git for-each-ref
--format='%(objectname)' \
318 "refs/bisect/skip-*" |
tr '\012' ' ') ||
exit
321 test -n "$skip" && BISECT_OPT
='--bisect-all'
323 bad
=$
(git rev-parse
--verify refs
/bisect
/bad
) &&
324 good
=$
(git for-each-ref
--format='^%(objectname)' \
325 "refs/bisect/good-*" |
tr '\012' ' ') &&
326 eval="git rev-list --bisect-vars $BISECT_OPT $good $bad --" &&
327 eval="$eval $(cat "$GIT_DIR/BISECT_NAMES
")" &&
328 eval=$
(filter_skipped
"$eval" "$skip") &&
331 if [ -z "$bisect_rev" ]; then
332 echo "$bad was both good and bad"
335 if [ "$bisect_rev" = "$bad" ]; then
336 exit_if_skipped_commits
"$bisect_tried"
337 echo "$bisect_rev is first bad commit"
338 git diff-tree
--pretty $bisect_rev
342 # We should exit here only if the "bad"
343 # commit is also a "skip" commit (see above).
344 exit_if_skipped_commits
"$bisect_rev"
346 echo "Bisecting: $bisect_nr revisions left to test after this"
347 git branch
-D new-bisect
2> /dev
/null
348 git checkout
-q -b new-bisect
"$bisect_rev" ||
exit
349 git branch
-M new-bisect bisect
350 git show-branch
"$bisect_rev"
354 bisect_next_check fail
358 case "${DISPLAY+set}${MSYSTEM+set}${SECURITYSESSIONID+set}" in
365 -*) set git log
"$@" ;;
370 not
=$
(git for-each-ref
--format='%(refname)' "refs/bisect/good-*")
371 eval '"$@"' refs
/bisect
/bad
--not $not -- $
(cat "$GIT_DIR/BISECT_NAMES")
375 test -f "$GIT_DIR/BISECT_NAMES" ||
{
376 echo "We are not bisecting."
380 0) if [ -s "$GIT_DIR/BISECT_START" ]; then
381 branch
=`cat "$GIT_DIR/BISECT_START"`
385 1) git show-ref
--verify --quiet -- "refs/heads/$1" ||
386 die
"$1 does not seem to be a valid branch"
391 if git checkout
"$branch"; then
392 # Cleanup head-name if it got left by an old version of git-bisect
393 rm -f "$GIT_DIR/head-name"
394 rm -f "$GIT_DIR/BISECT_START"
399 bisect_clean_state
() {
400 # There may be some refs packed during bisection.
401 git for-each-ref
--format='%(refname) %(objectname)' refs
/bisect
/\
* refs
/heads
/bisect |
404 git update-ref
-d $ref $hash
406 rm -f "$GIT_DIR/BISECT_LOG"
407 rm -f "$GIT_DIR/BISECT_NAMES"
408 rm -f "$GIT_DIR/BISECT_RUN"
412 test -r "$1" || die
"cannot read $1 for replaying"
414 while read bisect
command rev
416 test "$bisect" = "git-bisect" ||
continue
419 cmd
="bisect_start $rev"
422 bisect_write
"$command" "$rev" ;;
424 die
"?? what are you talking about?" ;;
431 bisect_next_check fail
439 # Check for really bad run error.
440 if [ $res -lt 0 -o $res -ge 128 ]; then
441 echo >&2 "bisect run failed:"
442 echo >&2 "exit code $res from '$@' is < 0 or >= 128"
446 # Find current state depending on run success or failure.
447 # A special exit code of 125 means cannot test.
448 if [ $res -eq 125 ]; then
450 elif [ $res -gt 0 ]; then
456 # We have to use a subshell because "bisect_state" can exit.
457 ( bisect_state
$state > "$GIT_DIR/BISECT_RUN" )
460 cat "$GIT_DIR/BISECT_RUN"
462 if grep "first bad commit could be any of" "$GIT_DIR/BISECT_RUN" \
464 echo >&2 "bisect run cannot continue any more"
468 if [ $res -ne 0 ]; then
469 echo >&2 "bisect run failed:"
470 echo >&2 "'bisect_state $state' exited with error code $res"
474 if grep "is first bad commit" "$GIT_DIR/BISECT_RUN" > /dev
/null
; then
475 echo "bisect run success"
493 bisect_state
"$cmd" "$@" ;;
495 # Not sure we want "next" at the UI level anymore.
498 bisect_visualize
"$@" ;;
502 bisect_replay
"$@" ;;
504 cat "$GIT_DIR/BISECT_LOG" ;;