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"
109 if [ $bad_seen -eq 0 ]; then
111 bisect_write_bad
"$rev"
113 bisect_write_good
"$rev"
120 sq "$@" >"$GIT_DIR/BISECT_NAMES"
121 echo "git-bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG"
129 rev=$
(git rev-parse
--verify HEAD
) ;;
131 rev=$
(git rev-parse
--verify "$1^{commit}") ;;
135 bisect_write_bad
"$rev"
136 echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
142 echo "$rev" >"$GIT_DIR/refs/bisect/bad"
143 echo "# bad: "$
(git show-branch
$rev) >>"$GIT_DIR/BISECT_LOG"
149 0) revs
=$
(git rev-parse
--verify HEAD
) ||
exit ;;
150 *) revs
=$
(git rev-parse
--revs-only --no-flags "$@") &&
151 test '' != "$revs" || die
"Bad rev input: $@" ;;
155 rev=$
(git rev-parse
--verify "$rev^{commit}") ||
exit
156 bisect_write_good
"$rev"
157 echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
162 bisect_write_good
() {
164 echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
165 echo "# good: "$
(git show-branch
$rev) >>"$GIT_DIR/BISECT_LOG"
171 0) revs
=$
(git rev-parse
--verify HEAD
) ||
exit ;;
172 *) revs
=$
(git rev-parse
--revs-only --no-flags "$@") &&
173 test '' != "$revs" || die
"Bad rev input: $@" ;;
177 rev=$
(git rev-parse
--verify "$rev^{commit}") ||
exit
178 bisect_write_skip
"$rev"
179 echo "git-bisect skip $rev" >>"$GIT_DIR/BISECT_LOG"
184 bisect_write_skip
() {
186 echo "$rev" >"$GIT_DIR/refs/bisect/skip-$rev"
187 echo "# skip: "$
(git show-branch
$rev) >>"$GIT_DIR/BISECT_LOG"
190 bisect_next_check
() {
191 missing_good
= missing_bad
=
192 git show-ref
-q --verify refs
/bisect
/bad || missing_bad
=t
193 test -n "$(git for-each-ref "refs
/bisect
/good-
*")" || missing_good
=t
195 case "$missing_good,$missing_bad,$1" in
197 : have both good and bad
- ok
200 # do not have both but not asked to fail - just report.
204 # have bad but not good. we could bisect although
205 # this is less optimum.
206 echo >&2 'Warning: bisecting only with a bad commit.'
209 printf >&2 'Are you sure [Y/n]? '
210 case "$(read yesno)" in [Nn
]*) exit 1 ;; esac
212 : bisect without good...
216 test -d "$GIT_DIR/refs/bisect" ||
{
217 echo >&2 'You need to start by "git bisect start".'
220 echo >&2 'You '$THEN'need to give me at least one good' \
221 'and one bad revisions.'
222 echo >&2 '(You can use "git bisect bad" and' \
223 '"git bisect good" for that.)'
229 bisect_next_check
&& bisect_next ||
:
236 if [ -z "$_skip" ]; then
241 # Let's parse the output of:
242 # "git rev-list --bisect-vars --bisect-all ..."
243 eval $_eval |
while read hash line
245 case "$VARS,$FOUND,$TRIED,$hash" in
246 # We display some vars.
247 1,*,*,*) echo "$hash $line" ;;
252 # We had nothing to search.
258 # We did not find a good bisect rev.
259 # This should happen only if the "bad"
260 # commit is also a "skip" commit.
262 echo "bisect_rev=$TRIED"
268 TRIED
="${TRIED:+$TRIED|}$hash"
272 echo "bisect_rev=$hash"
273 echo "bisect_tried=\"$TRIED\""
279 # We have already found a rev to be tested.
280 ,1,*,bisect_rev
*) VARS
=1 ;;
284 *) die
"filter_skipped error " \
295 exit_if_skipped_commits
() {
297 if expr "$_tried" : ".*[|].*" > /dev
/null
; then
298 echo "There are only 'skip'ped commit left to test."
299 echo "The first bad commit could be any of:"
300 echo "$_tried" |
sed -e 's/[|]/\n/g'
301 echo "We cannot bisect more!"
307 case "$#" in 0) ;; *) usage
;; esac
309 bisect_next_check good
311 skip
=$
(git for-each-ref
--format='%(objectname)' \
312 "refs/bisect/skip-*" |
tr '[\012]' ' ') ||
exit
315 test -n "$skip" && BISECT_OPT
='--bisect-all'
317 bad
=$
(git rev-parse
--verify refs
/bisect
/bad
) &&
318 good
=$
(git for-each-ref
--format='^%(objectname)' \
319 "refs/bisect/good-*" |
tr '[\012]' ' ') &&
320 eval="git rev-list --bisect-vars $BISECT_OPT $good $bad --" &&
321 eval="$eval $(cat "$GIT_DIR/BISECT_NAMES
")" &&
322 eval=$
(filter_skipped
"$eval" "$skip") &&
325 if [ -z "$bisect_rev" ]; then
326 echo "$bad was both good and bad"
329 if [ "$bisect_rev" = "$bad" ]; then
330 exit_if_skipped_commits
"$bisect_tried"
331 echo "$bisect_rev is first bad commit"
332 git diff-tree
--pretty $bisect_rev
336 # We should exit here only if the "bad"
337 # commit is also a "skip" commit (see above).
338 exit_if_skipped_commits
"$bisect_rev"
340 echo "Bisecting: $bisect_nr revisions left to test after this"
341 echo "$bisect_rev" >"$GIT_DIR/refs/heads/new-bisect"
342 git checkout
-q new-bisect ||
exit
343 mv "$GIT_DIR/refs/heads/new-bisect" "$GIT_DIR/refs/heads/bisect" &&
344 GIT_DIR
="$GIT_DIR" git symbolic-ref HEAD refs
/heads
/bisect
345 git show-branch
"$bisect_rev"
349 bisect_next_check fail
350 not
=`cd "$GIT_DIR/refs" && echo bisect/good-*`
351 eval gitk bisect
/bad
--not $not -- $
(cat "$GIT_DIR/BISECT_NAMES")
356 0) if [ -s "$GIT_DIR/head-name" ]; then
357 branch
=`cat "$GIT_DIR/head-name"`
361 1) git show-ref
--verify --quiet -- "refs/heads/$1" ||
{
362 echo >&2 "$1 does not seem to be a valid branch"
369 if git checkout
"$branch"; then
370 rm -f "$GIT_DIR/head-name"
375 bisect_clean_state
() {
376 rm -fr "$GIT_DIR/refs/bisect"
377 rm -f "$GIT_DIR/refs/heads/bisect"
378 rm -f "$GIT_DIR/BISECT_LOG"
379 rm -f "$GIT_DIR/BISECT_NAMES"
380 rm -f "$GIT_DIR/BISECT_RUN"
385 echo >&2 "cannot read $1 for replaying"
389 while read bisect
command rev
391 test "$bisect" = "git-bisect" ||
continue
394 cmd
="bisect_start $rev"
398 bisect_write_good
"$rev"
399 echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
402 bisect_write_bad
"$rev"
403 echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
406 bisect_write_skip
"$rev"
407 echo "git-bisect skip $rev" >>"$GIT_DIR/BISECT_LOG"
410 echo >&2 "?? what are you talking about?"
418 bisect_next_check fail
426 # Check for really bad run error.
427 if [ $res -lt 0 -o $res -ge 128 ]; then
428 echo >&2 "bisect run failed:"
429 echo >&2 "exit code $res from '$@' is < 0 or >= 128"
433 # Use "bisect_good" or "bisect_bad"
434 # depending on run success or failure.
435 if [ $res -gt 0 ]; then
436 next_bisect
='bisect_bad'
438 next_bisect
='bisect_good'
441 # We have to use a subshell because bisect_good or
442 # bisect_bad functions can exit.
443 ( $next_bisect > "$GIT_DIR/BISECT_RUN" )
446 cat "$GIT_DIR/BISECT_RUN"
448 if [ $res -ne 0 ]; then
449 echo >&2 "bisect run failed:"
450 echo >&2 "$next_bisect exited with error code $res"
454 if grep "is first bad commit" "$GIT_DIR/BISECT_RUN" > /dev
/null
; then
455 echo "bisect run success"
479 # Not sure we want "next" at the UI level anymore.
482 bisect_visualize
"$@" ;;
486 bisect_replay
"$@" ;;
488 cat "$GIT_DIR/BISECT_LOG" ;;