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.'
32 s/'\''/'\'\\\\\'\''/g;
40 test -d "$GIT_DIR/refs/bisect" ||
{
41 echo >&2 'You need to start by "git bisect start"'
44 echo >&2 -n 'Do you want me to do it for you [Y/n]? '
59 # Verify HEAD. If we were bisecting before this, reset to the
60 # top-of-line master first!
62 head=$
(GIT_DIR
="$GIT_DIR" git symbolic-ref HEAD
) ||
63 die
"Bad HEAD - I need a symbolic ref"
66 if [ -s "$GIT_DIR/head-name" ]; then
67 branch
=`cat "$GIT_DIR/head-name"`
71 git checkout
$branch ||
exit
74 [ -s "$GIT_DIR/head-name" ] && die
"won't bisect on seeked tree"
75 echo "$head" |
sed 's#^refs/heads/##' >"$GIT_DIR/head-name"
78 die
"Bad HEAD - strange symbolic ref"
83 # Get rid of any old bisect state
86 mkdir
"$GIT_DIR/refs/bisect"
89 # Check for one bad and then some good revisions.
93 case "$arg" in --) has_double_dash
=1; break ;; esac
97 while [ $# -gt 0 ]; do
105 rev=$
(git rev-parse
--verify "$arg^{commit}" 2>/dev
/null
) ||
{
106 test $has_double_dash -eq 1 &&
107 die
"'$arg' does not appear to be a valid revision"
111 0) state
='bad' ; bad_seen
=1 ;;
114 bisect_write
"$state" "$rev" 'nolog'
120 sq "$@" >"$GIT_DIR/BISECT_NAMES"
121 echo "git-bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG"
131 good|skip
) tag
="$state"-"$rev" ;;
132 *) die
"Bad bisect_write argument: $state" ;;
134 echo "$rev" >"$GIT_DIR/refs/bisect/$tag"
135 echo "# $state: "$
(git show-branch
$rev) >>"$GIT_DIR/BISECT_LOG"
136 test -z "$nolog" && echo "git-bisect $state $rev" >>"$GIT_DIR/BISECT_LOG"
144 die
"Please call 'bisect_state' with at least one argument." ;;
146 rev=$
(git rev-parse
--verify HEAD
) ||
147 die
"Bad rev input: HEAD"
148 bisect_write
"$state" "$rev" ;;
150 rev=$
(git rev-parse
--verify "$2^{commit}") ||
151 die
"Bad rev input: $2"
152 bisect_write
"$state" "$rev" ;;
155 revs
=$
(git rev-parse
--revs-only --no-flags "$@") &&
156 test '' != "$revs" || die
"Bad rev input: $@"
159 rev=$
(git rev-parse
--verify "$rev^{commit}") ||
160 die
"Bad rev commit: $rev^{commit}"
161 bisect_write
"$state" "$rev"
169 bisect_next_check
() {
170 missing_good
= missing_bad
=
171 git show-ref
-q --verify refs
/bisect
/bad || missing_bad
=t
172 test -n "$(git for-each-ref "refs
/bisect
/good-
*")" || missing_good
=t
174 case "$missing_good,$missing_bad,$1" in
176 : have both good and bad
- ok
179 # do not have both but not asked to fail - just report.
183 # have bad but not good. we could bisect although
184 # this is less optimum.
185 echo >&2 'Warning: bisecting only with a bad commit.'
188 printf >&2 'Are you sure [Y/n]? '
189 case "$(read yesno)" in [Nn
]*) exit 1 ;; esac
191 : bisect without good...
195 test -d "$GIT_DIR/refs/bisect" ||
{
196 echo >&2 'You need to start by "git bisect start".'
199 echo >&2 'You '$THEN'need to give me at least one good' \
200 'and one bad revisions.'
201 echo >&2 '(You can use "git bisect bad" and' \
202 '"git bisect good" for that.)'
208 bisect_next_check
&& bisect_next ||
:
215 if [ -z "$_skip" ]; then
220 # Let's parse the output of:
221 # "git rev-list --bisect-vars --bisect-all ..."
222 eval $_eval |
while read hash line
224 case "$VARS,$FOUND,$TRIED,$hash" in
225 # We display some vars.
226 1,*,*,*) echo "$hash $line" ;;
231 # We had nothing to search.
237 # We did not find a good bisect rev.
238 # This should happen only if the "bad"
239 # commit is also a "skip" commit.
241 echo "bisect_rev=$TRIED"
247 TRIED
="${TRIED:+$TRIED|}$hash"
251 echo "bisect_rev=$hash"
252 echo "bisect_tried=\"$TRIED\""
258 # We have already found a rev to be tested.
259 ,1,*,bisect_rev
*) VARS
=1 ;;
263 *) die
"filter_skipped error " \
274 exit_if_skipped_commits
() {
276 if expr "$_tried" : ".*[|].*" > /dev
/null
; then
277 echo "There are only 'skip'ped commit left to test."
278 echo "The first bad commit could be any of:"
279 echo "$_tried" |
sed -e 's/[|]/\n/g'
280 echo "We cannot bisect more!"
286 case "$#" in 0) ;; *) usage
;; esac
288 bisect_next_check good
290 skip
=$
(git for-each-ref
--format='%(objectname)' \
291 "refs/bisect/skip-*" |
tr '[\012]' ' ') ||
exit
294 test -n "$skip" && BISECT_OPT
='--bisect-all'
296 bad
=$
(git rev-parse
--verify refs
/bisect
/bad
) &&
297 good
=$
(git for-each-ref
--format='^%(objectname)' \
298 "refs/bisect/good-*" |
tr '[\012]' ' ') &&
299 eval="git rev-list --bisect-vars $BISECT_OPT $good $bad --" &&
300 eval="$eval $(cat "$GIT_DIR/BISECT_NAMES
")" &&
301 eval=$
(filter_skipped
"$eval" "$skip") &&
304 if [ -z "$bisect_rev" ]; then
305 echo "$bad was both good and bad"
308 if [ "$bisect_rev" = "$bad" ]; then
309 exit_if_skipped_commits
"$bisect_tried"
310 echo "$bisect_rev is first bad commit"
311 git diff-tree
--pretty $bisect_rev
315 # We should exit here only if the "bad"
316 # commit is also a "skip" commit (see above).
317 exit_if_skipped_commits
"$bisect_rev"
319 echo "Bisecting: $bisect_nr revisions left to test after this"
320 echo "$bisect_rev" >"$GIT_DIR/refs/heads/new-bisect"
321 git checkout
-q new-bisect ||
exit
322 mv "$GIT_DIR/refs/heads/new-bisect" "$GIT_DIR/refs/heads/bisect" &&
323 GIT_DIR
="$GIT_DIR" git symbolic-ref HEAD refs
/heads
/bisect
324 git show-branch
"$bisect_rev"
328 bisect_next_check fail
329 not
=`cd "$GIT_DIR/refs" && echo bisect/good-*`
330 eval gitk bisect
/bad
--not $not -- $
(cat "$GIT_DIR/BISECT_NAMES")
335 0) if [ -s "$GIT_DIR/head-name" ]; then
336 branch
=`cat "$GIT_DIR/head-name"`
340 1) git show-ref
--verify --quiet -- "refs/heads/$1" ||
341 die
"$1 does not seem to be a valid branch"
346 if git checkout
"$branch"; then
347 rm -f "$GIT_DIR/head-name"
352 bisect_clean_state
() {
353 rm -fr "$GIT_DIR/refs/bisect"
354 rm -f "$GIT_DIR/refs/heads/bisect"
355 rm -f "$GIT_DIR/BISECT_LOG"
356 rm -f "$GIT_DIR/BISECT_NAMES"
357 rm -f "$GIT_DIR/BISECT_RUN"
361 test -r "$1" || die
"cannot read $1 for replaying"
363 while read bisect
command rev
365 test "$bisect" = "git-bisect" ||
continue
368 cmd
="bisect_start $rev"
371 bisect_write
"$command" "$rev" ;;
373 die
"?? what are you talking about?" ;;
380 bisect_next_check fail
388 # Check for really bad run error.
389 if [ $res -lt 0 -o $res -ge 128 ]; then
390 echo >&2 "bisect run failed:"
391 echo >&2 "exit code $res from '$@' is < 0 or >= 128"
395 # Find current state depending on run success or failure.
396 # A special exit code of 125 means cannot test.
397 if [ $res -eq 125 ]; then
399 elif [ $res -gt 0 ]; then
405 # We have to use a subshell because "bisect_state" can exit.
406 ( bisect_state
$state > "$GIT_DIR/BISECT_RUN" )
409 cat "$GIT_DIR/BISECT_RUN"
411 if grep "first bad commit could be any of" "$GIT_DIR/BISECT_RUN" \
413 echo >&2 "bisect run cannot continue any more"
417 if [ $res -ne 0 ]; then
418 echo >&2 "bisect run failed:"
419 echo >&2 "'bisect_state $state' exited with error code $res"
423 if grep "is first bad commit" "$GIT_DIR/BISECT_RUN" > /dev
/null
; then
424 echo "bisect run success"
442 bisect_state
"$cmd" "$@" ;;
444 # Not sure we want "next" at the UI level anymore.
447 bisect_visualize
"$@" ;;
451 bisect_replay
"$@" ;;
453 cat "$GIT_DIR/BISECT_LOG" ;;