3 USAGE='[help|start|bad|good|skip|next|reset|visualize|replay|log|run]'
4 LONG_USAGE='git bisect help
5 print this long help message.
6 git bisect start [<bad> [<good>...]] [--] [<pathspec>...]
7 reset bisect state and start bisection.
9 mark <rev> a known-bad revision.
10 git bisect good [<rev>...]
11 mark <rev>... known-good revisions.
12 git bisect skip [<rev>...]
13 mark <rev>... untestable revisions.
15 find next bisection to test and check it out.
16 git bisect reset [<branch>]
17 finish bisection search and go back to branch.
19 show bisect status in gitk.
20 git bisect replay <logfile>
24 git bisect run <cmd>...
25 use <cmd>... to automatically bisect.
27 Please use "git help bisect" to get the full man page.'
33 _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"
39 s/'\''/'\'\\\\\'\''/g;
47 test -f "$GIT_DIR/BISECT_NAMES" || {
48 echo >&2 'You need to start by "git bisect start"'
51 echo >&2 -n 'Do you want me to do it for you [Y/n]? '
66 # Verify HEAD. If we were bisecting before this, reset to the
67 # top-of-line master first!
69 head=$(GIT_DIR="$GIT_DIR" git symbolic-ref -q HEAD) ||
70 head=$(GIT_DIR="$GIT_DIR" git rev-parse --verify HEAD) ||
71 die "Bad HEAD - I need a HEAD"
73 # Check that we either already have BISECT_START, or that the
74 # branches bisect, new-bisect don't exist, to not override them.
76 test -s "$GIT_DIR/BISECT_START" ||
77 if git show-ref --verify -q refs/heads/bisect ||
78 git show-ref --verify -q refs/heads/new-bisect; then
79 die 'The branches "bisect" and "new-bisect" must not exist.'
84 branch=`cat "$GIT_DIR/BISECT_START"`
85 git checkout $branch || exit
88 # This error message should only be triggered by cogito usage,
89 # and cogito users should understand it relates to cg-seek.
90 [ -s "$GIT_DIR/head-name" ] && die "won't bisect on seeked tree"
91 start_head="${head#refs/heads/}"
94 die "Bad HEAD - strange symbolic ref"
99 # Get rid of any old bisect state
104 # Check for one bad and then some good revisions.
108 case "$arg" in --) has_double_dash=1; break ;; esac
113 while [ $# -gt 0 ]; do
121 rev=$(git rev-parse --verify "$arg^{commit}" 2>/dev/null) || {
122 test $has_double_dash -eq 1 &&
123 die "'$arg' does not appear to be a valid revision"
127 0) state='bad' ; bad_seen=1 ;;
130 eval="$eval bisect_write '$state' '$rev' 'nolog'; "
136 sq "$@" >"$GIT_DIR/BISECT_NAMES"
137 test -n "$start_head" && echo "$start_head" >"$GIT_DIR/BISECT_START"
139 echo "git-bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG"
149 good|skip) tag="$state"-"$rev" ;;
150 *) die "Bad bisect_write argument: $state" ;;
152 git update-ref "refs/bisect/$tag" "$rev"
153 echo "# $state: $(git show-branch $rev)" >>"$GIT_DIR/BISECT_LOG"
154 test -z "$nolog" && echo "git-bisect $state $rev" >>"$GIT_DIR/BISECT_LOG"
162 die "Please call 'bisect_state' with at least one argument." ;;
164 rev=$(git rev-parse --verify HEAD) ||
165 die "Bad rev input: HEAD"
166 bisect_write "$state" "$rev" ;;
172 sha=$(git rev-parse --verify "$rev^{commit}") ||
173 die "Bad rev input: $rev"
174 eval="$eval bisect_write '$state' '$sha'; "
178 die "'git bisect bad' can take only one argument." ;;
185 bisect_next_check() {
186 missing_good= missing_bad=
187 git show-ref -q --verify refs/bisect/bad || missing_bad=t
188 test -n "$(git for-each-ref "refs/bisect/good-*")" || missing_good=t
190 case "$missing_good,$missing_bad,$1" in
192 : have both good and bad - ok
195 # do not have both but not asked to fail - just report.
199 # have bad but not good. we could bisect although
200 # this is less optimum.
201 echo >&2 'Warning: bisecting only with a bad commit.'
204 printf >&2 'Are you sure [Y/n]? '
205 case "$(read yesno)" in [Nn]*) exit 1 ;; esac
207 : bisect without good...
211 test -f "$GIT_DIR/BISECT_NAMES" || {
212 echo >&2 'You need to start by "git bisect start".'
215 echo >&2 'You '$THEN'need to give me at least one good' \
216 'and one bad revisions.'
217 echo >&2 '(You can use "git bisect bad" and' \
218 '"git bisect good" for that.)'
224 bisect_next_check && bisect_next || :
233 if [ $res -ne 0 ]; then
234 echo >&2 "'git rev-list --bisect-vars' failed:"
235 echo >&2 "maybe you mistake good and bad revs?"
246 if [ -z "$_skip" ]; then
247 eval_rev_list "$_eval"
251 # Let's parse the output of:
252 # "git rev-list --bisect-vars --bisect-all ..."
253 eval_rev_list "$_eval" | while read hash line
255 case "$VARS,$FOUND,$TRIED,$hash" in
256 # We display some vars.
257 1,*,*,*) echo "$hash $line" ;;
262 # We had nothing to search.
268 # We did not find a good bisect rev.
269 # This should happen only if the "bad"
270 # commit is also a "skip" commit.
272 echo "bisect_rev=$TRIED"
278 TRIED="${TRIED:+$TRIED|}$hash"
282 echo "bisect_rev=$hash"
283 echo "bisect_tried=\"$TRIED\""
289 # We have already found a rev to be tested.
290 ,1,*,bisect_rev*) VARS=1 ;;
294 *) die "filter_skipped error " \
305 exit_if_skipped_commits () {
307 if expr "$_tried" : ".*[|].*" > /dev/null ; then
308 echo "There are only 'skip'ped commit left to test."
309 echo "The first bad commit could be any of:"
310 echo "$_tried" | tr '[|]' '[\012]'
311 echo "We cannot bisect more!"
317 case "$#" in 0) ;; *) usage ;; esac
319 bisect_next_check good
321 skip=$(git for-each-ref --format='%(objectname)' \
322 "refs/bisect/skip-*" | tr '\012' ' ') || exit
325 test -n "$skip" && BISECT_OPT='--bisect-all'
327 bad=$(git rev-parse --verify refs/bisect/bad) &&
328 good=$(git for-each-ref --format='^%(objectname)' \
329 "refs/bisect/good-*" | tr '\012' ' ') &&
330 eval="git rev-list --bisect-vars $BISECT_OPT $good $bad --" &&
331 eval="$eval $(cat "$GIT_DIR/BISECT_NAMES")" &&
332 eval=$(filter_skipped "$eval" "$skip") &&
335 if [ -z "$bisect_rev" ]; then
336 echo "$bad was both good and bad"
339 if [ "$bisect_rev" = "$bad" ]; then
340 exit_if_skipped_commits "$bisect_tried"
341 echo "$bisect_rev is first bad commit"
342 git diff-tree --pretty $bisect_rev
346 # We should exit here only if the "bad"
347 # commit is also a "skip" commit (see above).
348 exit_if_skipped_commits "$bisect_rev"
350 echo "Bisecting: $bisect_nr revisions left to test after this"
351 git branch -D new-bisect 2> /dev/null
352 git checkout -q -b new-bisect "$bisect_rev" || exit
353 git branch -M new-bisect bisect
354 git show-branch "$bisect_rev"
358 bisect_next_check fail
362 case "${DISPLAY+set}${MSYSTEM+set}${SECURITYSESSIONID+set}" in
369 -*) set git log "$@" ;;
374 not=$(git for-each-ref --format='%(refname)' "refs/bisect/good-*")
375 eval '"$@"' refs/bisect/bad --not $not -- $(cat "$GIT_DIR/BISECT_NAMES")
379 test -f "$GIT_DIR/BISECT_NAMES" || {
380 echo "We are not bisecting."
384 0) if [ -s "$GIT_DIR/BISECT_START" ]; then
385 branch=`cat "$GIT_DIR/BISECT_START"`
389 1) git show-ref --verify --quiet -- "refs/heads/$1" ||
390 die "$1 does not seem to be a valid branch"
395 if git checkout "$branch"; then
396 # Cleanup head-name if it got left by an old version of git-bisect
397 rm -f "$GIT_DIR/head-name"
398 rm -f "$GIT_DIR/BISECT_START"
403 bisect_clean_state() {
404 # There may be some refs packed during bisection.
405 git for-each-ref --format='%(refname) %(objectname)' refs/bisect/\* refs/heads/bisect |
408 git update-ref -d $ref $hash
410 rm -f "$GIT_DIR/BISECT_LOG"
411 rm -f "$GIT_DIR/BISECT_NAMES"
412 rm -f "$GIT_DIR/BISECT_RUN"
416 test -r "$1" || die "cannot read $1 for replaying"
418 while read bisect command rev
420 test "$bisect" = "git-bisect" || continue
423 cmd="bisect_start $rev"
426 bisect_write "$command" "$rev" ;;
428 die "?? what are you talking about?" ;;
435 bisect_next_check fail
443 # Check for really bad run error.
444 if [ $res -lt 0 -o $res -ge 128 ]; then
445 echo >&2 "bisect run failed:"
446 echo >&2 "exit code $res from '$@' is < 0 or >= 128"
450 # Find current state depending on run success or failure.
451 # A special exit code of 125 means cannot test.
452 if [ $res -eq 125 ]; then
454 elif [ $res -gt 0 ]; then
460 # We have to use a subshell because "bisect_state" can exit.
461 ( bisect_state $state > "$GIT_DIR/BISECT_RUN" )
464 cat "$GIT_DIR/BISECT_RUN"
466 if grep "first bad commit could be any of" "$GIT_DIR/BISECT_RUN" \
468 echo >&2 "bisect run cannot continue any more"
472 if [ $res -ne 0 ]; then
473 echo >&2 "bisect run failed:"
474 echo >&2 "'bisect_state $state' exited with error code $res"
478 if grep "is first bad commit" "$GIT_DIR/BISECT_RUN" > /dev/null; then
479 echo "bisect run success"
499 bisect_state "$cmd" "$@" ;;
501 # Not sure we want "next" at the UI level anymore.
504 bisect_visualize "$@" ;;
508 bisect_replay "$@" ;;
510 cat "$GIT_DIR/BISECT_LOG" ;;