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"
71 if [ -s "$GIT_DIR/BISECT_START" ]; then
72 branch
=`cat "$GIT_DIR/BISECT_START"`
76 git checkout
$branch ||
exit
79 # This error message should only be triggered by cogito usage,
80 # and cogito users should understand it relates to cg-seek.
81 [ -s "$GIT_DIR/head-name" ] && die
"won't bisect on seeked tree"
82 start_head
="${head#refs/heads/}"
85 die
"Bad HEAD - strange symbolic ref"
90 # Get rid of any old bisect state
95 # Check for one bad and then some good revisions.
99 case "$arg" in --) has_double_dash
=1; break ;; esac
104 while [ $# -gt 0 ]; do
112 rev=$
(git rev-parse
--verify "$arg^{commit}" 2>/dev
/null
) ||
{
113 test $has_double_dash -eq 1 &&
114 die
"'$arg' does not appear to be a valid revision"
118 0) state
='bad' ; bad_seen
=1 ;;
121 eval="$eval bisect_write '$state' '$rev' 'nolog'; "
127 sq "$@" >"$GIT_DIR/BISECT_NAMES"
128 test -n "$start_head" && echo "$start_head" >"$GIT_DIR/BISECT_START"
130 echo "git-bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG"
140 good|skip
) tag
="$state"-"$rev" ;;
141 *) die
"Bad bisect_write argument: $state" ;;
143 git update-ref
"refs/bisect/$tag" "$rev"
144 echo "# $state: $(git show-branch $rev)" >>"$GIT_DIR/BISECT_LOG"
145 test -z "$nolog" && echo "git-bisect $state $rev" >>"$GIT_DIR/BISECT_LOG"
153 die
"Please call 'bisect_state' with at least one argument." ;;
155 rev=$
(git rev-parse
--verify HEAD
) ||
156 die
"Bad rev input: HEAD"
157 bisect_write
"$state" "$rev" ;;
163 sha
=$
(git rev-parse
--verify "$rev^{commit}") ||
164 die
"Bad rev input: $rev"
165 eval="$eval bisect_write '$state' '$sha'; "
169 die
"'git bisect bad' can take only one argument." ;;
176 bisect_next_check
() {
177 missing_good
= missing_bad
=
178 git show-ref
-q --verify refs
/bisect
/bad || missing_bad
=t
179 test -n "$(git for-each-ref "refs
/bisect
/good-
*")" || missing_good
=t
181 case "$missing_good,$missing_bad,$1" in
183 : have both good and bad
- ok
186 # do not have both but not asked to fail - just report.
190 # have bad but not good. we could bisect although
191 # this is less optimum.
192 echo >&2 'Warning: bisecting only with a bad commit.'
195 printf >&2 'Are you sure [Y/n]? '
196 case "$(read yesno)" in [Nn
]*) exit 1 ;; esac
198 : bisect without good...
202 test -f "$GIT_DIR/BISECT_NAMES" ||
{
203 echo >&2 'You need to start by "git bisect start".'
206 echo >&2 'You '$THEN'need to give me at least one good' \
207 'and one bad revisions.'
208 echo >&2 '(You can use "git bisect bad" and' \
209 '"git bisect good" for that.)'
215 bisect_next_check
&& bisect_next ||
:
222 if [ -z "$_skip" ]; then
227 # Let's parse the output of:
228 # "git rev-list --bisect-vars --bisect-all ..."
229 eval $_eval |
while read hash line
231 case "$VARS,$FOUND,$TRIED,$hash" in
232 # We display some vars.
233 1,*,*,*) echo "$hash $line" ;;
238 # We had nothing to search.
244 # We did not find a good bisect rev.
245 # This should happen only if the "bad"
246 # commit is also a "skip" commit.
248 echo "bisect_rev=$TRIED"
254 TRIED
="${TRIED:+$TRIED|}$hash"
258 echo "bisect_rev=$hash"
259 echo "bisect_tried=\"$TRIED\""
265 # We have already found a rev to be tested.
266 ,1,*,bisect_rev
*) VARS
=1 ;;
270 *) die
"filter_skipped error " \
281 exit_if_skipped_commits
() {
283 if expr "$_tried" : ".*[|].*" > /dev
/null
; then
284 echo "There are only 'skip'ped commit left to test."
285 echo "The first bad commit could be any of:"
286 echo "$_tried" |
tr '[|]' '[\012]'
287 echo "We cannot bisect more!"
293 case "$#" in 0) ;; *) usage
;; esac
295 bisect_next_check good
297 skip
=$
(git for-each-ref
--format='%(objectname)' \
298 "refs/bisect/skip-*" |
tr '[\012]' ' ') ||
exit
301 test -n "$skip" && BISECT_OPT
='--bisect-all'
303 bad
=$
(git rev-parse
--verify refs
/bisect
/bad
) &&
304 good
=$
(git for-each-ref
--format='^%(objectname)' \
305 "refs/bisect/good-*" |
tr '[\012]' ' ') &&
306 eval="git rev-list --bisect-vars $BISECT_OPT $good $bad --" &&
307 eval="$eval $(cat "$GIT_DIR/BISECT_NAMES
")" &&
308 eval=$
(filter_skipped
"$eval" "$skip") &&
311 if [ -z "$bisect_rev" ]; then
312 echo "$bad was both good and bad"
315 if [ "$bisect_rev" = "$bad" ]; then
316 exit_if_skipped_commits
"$bisect_tried"
317 echo "$bisect_rev is first bad commit"
318 git diff-tree
--pretty $bisect_rev
322 # We should exit here only if the "bad"
323 # commit is also a "skip" commit (see above).
324 exit_if_skipped_commits
"$bisect_rev"
326 echo "Bisecting: $bisect_nr revisions left to test after this"
327 git branch
-f new-bisect
"$bisect_rev"
328 git checkout
-q new-bisect ||
exit
329 git branch
-M new-bisect bisect
330 git show-branch
"$bisect_rev"
334 bisect_next_check fail
338 case "${DISPLAY+set}" in
345 -*) set git log
"$@" ;;
350 not
=$
(git for-each-ref
--format='%(refname)' "refs/bisect/good-*")
351 eval '"$@"' refs
/bisect
/bad
--not $not -- $
(cat "$GIT_DIR/BISECT_NAMES")
355 test -f "$GIT_DIR/BISECT_NAMES" ||
{
356 echo "We are not bisecting."
360 0) if [ -s "$GIT_DIR/BISECT_START" ]; then
361 branch
=`cat "$GIT_DIR/BISECT_START"`
365 1) git show-ref
--verify --quiet -- "refs/heads/$1" ||
366 die
"$1 does not seem to be a valid branch"
371 if git checkout
"$branch"; then
372 # Cleanup head-name if it got left by an old version of git-bisect
373 rm -f "$GIT_DIR/head-name"
374 rm -f "$GIT_DIR/BISECT_START"
379 bisect_clean_state
() {
380 # There may be some refs packed during bisection.
381 git for-each-ref
--format='%(refname) %(objectname)' refs
/bisect
/\
* refs
/heads
/bisect |
384 git update-ref
-d $ref $hash
386 rm -f "$GIT_DIR/BISECT_LOG"
387 rm -f "$GIT_DIR/BISECT_NAMES"
388 rm -f "$GIT_DIR/BISECT_RUN"
392 test -r "$1" || die
"cannot read $1 for replaying"
394 while read bisect
command rev
396 test "$bisect" = "git-bisect" ||
continue
399 cmd
="bisect_start $rev"
402 bisect_write
"$command" "$rev" ;;
404 die
"?? what are you talking about?" ;;
411 bisect_next_check fail
419 # Check for really bad run error.
420 if [ $res -lt 0 -o $res -ge 128 ]; then
421 echo >&2 "bisect run failed:"
422 echo >&2 "exit code $res from '$@' is < 0 or >= 128"
426 # Find current state depending on run success or failure.
427 # A special exit code of 125 means cannot test.
428 if [ $res -eq 125 ]; then
430 elif [ $res -gt 0 ]; then
436 # We have to use a subshell because "bisect_state" can exit.
437 ( bisect_state
$state > "$GIT_DIR/BISECT_RUN" )
440 cat "$GIT_DIR/BISECT_RUN"
442 if grep "first bad commit could be any of" "$GIT_DIR/BISECT_RUN" \
444 echo >&2 "bisect run cannot continue any more"
448 if [ $res -ne 0 ]; then
449 echo >&2 "bisect run failed:"
450 echo >&2 "'bisect_state $state' exited with error code $res"
454 if grep "is first bad commit" "$GIT_DIR/BISECT_RUN" > /dev
/null
; then
455 echo "bisect run success"
473 bisect_state
"$cmd" "$@" ;;
475 # Not sure we want "next" at the UI level anymore.
478 bisect_visualize
"$@" ;;
482 bisect_replay
"$@" ;;
484 cat "$GIT_DIR/BISECT_LOG" ;;