3 USAGE
='[start|bad|good|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.
11 find next bisection to test and check it out.
12 git bisect reset [<branch>]
13 finish bisection search and go back to branch.
15 show bisect status in gitk.
16 git bisect replay <logfile>
20 git bisect skip [<rev>...]
21 mark <rev>... untestable revisions.
22 git bisect run <cmd>...
23 use <cmd>... to automatically bisect.'
31 s/'\''/'\'\\\\\'\''/g;
39 test -d "$GIT_DIR/refs/bisect" ||
{
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" |
sed 's#^refs/heads/##' >"$GIT_DIR/head-name"
77 die
"Bad HEAD - strange symbolic ref"
82 # Get rid of any old bisect state
85 mkdir
"$GIT_DIR/refs/bisect"
88 # Check for one bad and then some good revisions.
92 case "$arg" in --) has_double_dash
=1; break ;; esac
96 while [ $# -gt 0 ]; do
104 rev=$
(git rev-parse
--verify "$arg^{commit}" 2>/dev
/null
) ||
{
105 test $has_double_dash -eq 1 &&
106 die
"'$arg' does not appear to be a valid revision"
110 0) state
='bad' ; bad_seen
=1 ;;
113 bisect_write
"$state" "$rev" 'nolog'
119 sq "$@" >"$GIT_DIR/BISECT_NAMES"
120 echo "git-bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG"
130 good|skip
) tag
="$state"-"$rev" ;;
131 *) die
"Bad bisect_write argument: $state" ;;
133 echo "$rev" >"$GIT_DIR/refs/bisect/$tag"
134 echo "# $state: "$
(git show-branch
$rev) >>"$GIT_DIR/BISECT_LOG"
135 test -z "$nolog" && echo "git-bisect $state $rev" >>"$GIT_DIR/BISECT_LOG"
142 rev=$
(git rev-parse
--verify HEAD
) ;;
144 rev=$
(git rev-parse
--verify "$1^{commit}") ;;
148 bisect_write
'bad' "$rev"
155 0) revs
=$
(git rev-parse
--verify HEAD
) ||
exit ;;
156 *) revs
=$
(git rev-parse
--revs-only --no-flags "$@") &&
157 test '' != "$revs" || die
"Bad rev input: $@" ;;
161 rev=$
(git rev-parse
--verify "$rev^{commit}") ||
exit
162 bisect_write
'good' "$rev"
170 0) revs
=$
(git rev-parse
--verify HEAD
) ||
exit ;;
171 *) revs
=$
(git rev-parse
--revs-only --no-flags "$@") &&
172 test '' != "$revs" || die
"Bad rev input: $@" ;;
176 rev=$
(git rev-parse
--verify "$rev^{commit}") ||
exit
177 bisect_write
'skip' "$rev"
182 bisect_next_check
() {
183 missing_good
= missing_bad
=
184 git show-ref
-q --verify refs
/bisect
/bad || missing_bad
=t
185 test -n "$(git for-each-ref "refs
/bisect
/good-
*")" || missing_good
=t
187 case "$missing_good,$missing_bad,$1" in
189 : have both good and bad
- ok
192 # do not have both but not asked to fail - just report.
196 # have bad but not good. we could bisect although
197 # this is less optimum.
198 echo >&2 'Warning: bisecting only with a bad commit.'
201 printf >&2 'Are you sure [Y/n]? '
202 case "$(read yesno)" in [Nn
]*) exit 1 ;; esac
204 : bisect without good...
208 test -d "$GIT_DIR/refs/bisect" ||
{
209 echo >&2 'You need to start by "git bisect start".'
212 echo >&2 'You '$THEN'need to give me at least one good' \
213 'and one bad revisions.'
214 echo >&2 '(You can use "git bisect bad" and' \
215 '"git bisect good" for that.)'
221 bisect_next_check
&& bisect_next ||
:
228 if [ -z "$_skip" ]; then
233 # Let's parse the output of:
234 # "git rev-list --bisect-vars --bisect-all ..."
235 eval $_eval |
while read hash line
237 case "$VARS,$FOUND,$TRIED,$hash" in
238 # We display some vars.
239 1,*,*,*) echo "$hash $line" ;;
244 # We had nothing to search.
250 # We did not find a good bisect rev.
251 # This should happen only if the "bad"
252 # commit is also a "skip" commit.
254 echo "bisect_rev=$TRIED"
260 TRIED
="${TRIED:+$TRIED|}$hash"
264 echo "bisect_rev=$hash"
265 echo "bisect_tried=\"$TRIED\""
271 # We have already found a rev to be tested.
272 ,1,*,bisect_rev
*) VARS
=1 ;;
276 *) die
"filter_skipped error " \
287 exit_if_skipped_commits
() {
289 if expr "$_tried" : ".*[|].*" > /dev
/null
; then
290 echo "There are only 'skip'ped commit left to test."
291 echo "The first bad commit could be any of:"
292 echo "$_tried" |
sed -e 's/[|]/\n/g'
293 echo "We cannot bisect more!"
299 case "$#" in 0) ;; *) usage
;; esac
301 bisect_next_check good
303 skip
=$
(git for-each-ref
--format='%(objectname)' \
304 "refs/bisect/skip-*" |
tr '[\012]' ' ') ||
exit
307 test -n "$skip" && BISECT_OPT
='--bisect-all'
309 bad
=$
(git rev-parse
--verify refs
/bisect
/bad
) &&
310 good
=$
(git for-each-ref
--format='^%(objectname)' \
311 "refs/bisect/good-*" |
tr '[\012]' ' ') &&
312 eval="git rev-list --bisect-vars $BISECT_OPT $good $bad --" &&
313 eval="$eval $(cat "$GIT_DIR/BISECT_NAMES
")" &&
314 eval=$
(filter_skipped
"$eval" "$skip") &&
317 if [ -z "$bisect_rev" ]; then
318 echo "$bad was both good and bad"
321 if [ "$bisect_rev" = "$bad" ]; then
322 exit_if_skipped_commits
"$bisect_tried"
323 echo "$bisect_rev is first bad commit"
324 git diff-tree
--pretty $bisect_rev
328 # We should exit here only if the "bad"
329 # commit is also a "skip" commit (see above).
330 exit_if_skipped_commits
"$bisect_rev"
332 echo "Bisecting: $bisect_nr revisions left to test after this"
333 echo "$bisect_rev" >"$GIT_DIR/refs/heads/new-bisect"
334 git checkout
-q new-bisect ||
exit
335 mv "$GIT_DIR/refs/heads/new-bisect" "$GIT_DIR/refs/heads/bisect" &&
336 GIT_DIR
="$GIT_DIR" git symbolic-ref HEAD refs
/heads
/bisect
337 git show-branch
"$bisect_rev"
341 bisect_next_check fail
342 not
=`cd "$GIT_DIR/refs" && echo bisect/good-*`
343 eval gitk bisect
/bad
--not $not -- $
(cat "$GIT_DIR/BISECT_NAMES")
348 0) if [ -s "$GIT_DIR/head-name" ]; then
349 branch
=`cat "$GIT_DIR/head-name"`
353 1) git show-ref
--verify --quiet -- "refs/heads/$1" ||
354 die
"$1 does not seem to be a valid branch"
359 if git checkout
"$branch"; then
360 rm -f "$GIT_DIR/head-name"
365 bisect_clean_state
() {
366 rm -fr "$GIT_DIR/refs/bisect"
367 rm -f "$GIT_DIR/refs/heads/bisect"
368 rm -f "$GIT_DIR/BISECT_LOG"
369 rm -f "$GIT_DIR/BISECT_NAMES"
370 rm -f "$GIT_DIR/BISECT_RUN"
374 test -r "$1" || die
"cannot read $1 for replaying"
376 while read bisect
command rev
378 test "$bisect" = "git-bisect" ||
continue
381 cmd
="bisect_start $rev"
384 bisect_write
"$command" "$rev" ;;
386 die
"?? what are you talking about?" ;;
393 bisect_next_check fail
401 # Check for really bad run error.
402 if [ $res -lt 0 -o $res -ge 128 ]; then
403 echo >&2 "bisect run failed:"
404 echo >&2 "exit code $res from '$@' is < 0 or >= 128"
408 # Use "bisect_good" or "bisect_bad"
409 # depending on run success or failure.
410 if [ $res -gt 0 ]; then
411 next_bisect
='bisect_bad'
413 next_bisect
='bisect_good'
416 # We have to use a subshell because bisect_good or
417 # bisect_bad functions can exit.
418 ( $next_bisect > "$GIT_DIR/BISECT_RUN" )
421 cat "$GIT_DIR/BISECT_RUN"
423 if [ $res -ne 0 ]; then
424 echo >&2 "bisect run failed:"
425 echo >&2 "$next_bisect exited with error code $res"
429 if grep "is first bad commit" "$GIT_DIR/BISECT_RUN" > /dev
/null
; then
430 echo "bisect run success"
454 # Not sure we want "next" at the UI level anymore.
457 bisect_visualize
"$@" ;;
461 bisect_replay
"$@" ;;
463 cat "$GIT_DIR/BISECT_LOG" ;;