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 run <cmd>...
21 use <cmd>... to automatically bisect.'
29 s/'\''/'\'\\\\\'\''/g;
37 test -d
"$GIT_DIR/refs/bisect" ||
{
38 echo >&2 'You need to start by "git bisect start"'
41 echo >&2 -n
'Do you want me to do it for you [Y/n]? '
56 # Verify HEAD. If we were bisecting before this, reset to the
57 # top-of-line master first!
59 head=$
(GIT_DIR
="$GIT_DIR" git-symbolic-ref HEAD
) ||
60 die
"Bad HEAD - I need a symbolic ref"
63 if [ -s
"$GIT_DIR/head-name" ]; then
64 branch
=`cat "$GIT_DIR/head-name"`
68 git checkout
$branch ||
exit
71 [ -s
"$GIT_DIR/head-name" ] && die
"won't bisect on seeked tree"
72 echo "$head" |
sed 's#^refs/heads/##' >"$GIT_DIR/head-name"
75 die
"Bad HEAD - strange symbolic ref"
80 # Get rid of any old bisect state
83 mkdir
"$GIT_DIR/refs/bisect"
86 # Check for one bad and then some good revisions.
90 case "$arg" in --) has_double_dash
=1; break ;; esac
94 while [ $# -gt
0 ]; do
102 rev=$
(git-rev-parse
--verify
"$arg^{commit}" 2>/dev
/null
) ||
{
103 test $has_double_dash -eq
1 &&
104 die
"'$arg' does not appear to be a valid revision"
107 if [ $bad_seen -eq
0 ]; then
109 bisect_write_bad
"$rev"
111 bisect_write_good
"$rev"
118 sq "$@" >"$GIT_DIR/BISECT_NAMES"
120 printf "git-bisect start"
122 } >>"$GIT_DIR/BISECT_LOG"
130 rev=$
(git-rev-parse
--verify HEAD
) ;;
132 rev=$
(git-rev-parse
--verify
"$1^{commit}") ;;
136 bisect_write_bad
"$rev"
137 echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
143 echo "$rev" >"$GIT_DIR/refs/bisect/bad"
144 echo "# bad: "$
(git-show-branch
$rev) >>"$GIT_DIR/BISECT_LOG"
150 0) revs
=$
(git-rev-parse
--verify HEAD
) ||
exit ;;
151 *) revs
=$
(git-rev-parse
--revs-only
--no-flags
"$@") &&
152 test '' != "$revs" || die
"Bad rev input: $@" ;;
156 rev=$
(git-rev-parse
--verify
"$rev^{commit}") ||
exit
157 bisect_write_good
"$rev"
158 echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
164 bisect_write_good
() {
166 echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
167 echo "# good: "$
(git-show-branch
$rev) >>"$GIT_DIR/BISECT_LOG"
170 bisect_next_check
() {
172 git show-ref
-q
--verify refs
/bisect
/bad
&&
173 test -n
"$(git for-each-ref "refs
/bisect
/good-
*")" &&
176 case "$next_ok,$1" in
180 test -d
"$GIT_DIR/refs/bisect" ||
{
181 echo >&2 'You need to start by "git bisect start".'
184 echo >&2 'You '$THEN'need to give me at least one good' \
185 'and one bad revisions.'
186 echo >&2 '(You can use "git bisect bad" and' \
187 '"git bisect good" for that.)'
195 bisect_next_check
&& bisect_next ||
:
199 case "$#" in 0) ;; *) usage
;; esac
201 bisect_next_check fail
202 bad
=$
(git-rev-parse
--verify refs
/bisect
/bad
) &&
203 good
=$
(git-rev-parse
--sq --revs-only
--not \
204 $
(cd "$GIT_DIR" && ls refs
/bisect
/good-
*)) &&
205 rev=$
(eval "git-rev-list --bisect $good $bad -- $(cat "$GIT_DIR/BISECT_NAMES
")") ||
exit
206 if [ -z
"$rev" ]; then
207 echo "$bad was both good and bad"
210 if [ "$rev" = "$bad" ]; then
211 echo "$rev is first bad commit"
212 git-diff-tree
--pretty
$rev
215 nr
=$
(eval "git-rev-list $rev $good -- $(cat $GIT_DIR/BISECT_NAMES)" |
wc -l
) ||
exit
216 echo "Bisecting: $nr revisions left to test after this"
217 echo "$rev" > "$GIT_DIR/refs/heads/new-bisect"
218 git checkout
-q new-bisect ||
exit
219 mv "$GIT_DIR/refs/heads/new-bisect" "$GIT_DIR/refs/heads/bisect" &&
220 GIT_DIR
="$GIT_DIR" git-symbolic-ref HEAD refs
/heads
/bisect
221 git-show-branch
"$rev"
225 bisect_next_check fail
226 not
=`cd "$GIT_DIR/refs" && echo bisect/good-*`
227 eval gitk bisect
/bad
--not
$not -- $
(cat "$GIT_DIR/BISECT_NAMES")
232 0) if [ -s
"$GIT_DIR/head-name" ]; then
233 branch
=`cat "$GIT_DIR/head-name"`
237 1) git-show-ref
--verify
--quiet
-- "refs/heads/$1" ||
{
238 echo >&2 "$1 does not seem to be a valid branch"
245 if git checkout
"$branch"; then
246 rm -f
"$GIT_DIR/head-name"
251 bisect_clean_state
() {
252 rm -fr
"$GIT_DIR/refs/bisect"
253 rm -f
"$GIT_DIR/refs/heads/bisect"
254 rm -f
"$GIT_DIR/BISECT_LOG"
255 rm -f
"$GIT_DIR/BISECT_NAMES"
256 rm -f
"$GIT_DIR/BISECT_RUN"
261 echo >&2 "cannot read $1 for replaying"
265 while read bisect
command rev
267 test "$bisect" = "git-bisect" ||
continue
270 cmd
="bisect_start $rev"
274 echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
275 echo "# good: "$
(git-show-branch
$rev) >>"$GIT_DIR/BISECT_LOG"
276 echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
279 echo "$rev" >"$GIT_DIR/refs/bisect/bad"
280 echo "# bad: "$
(git-show-branch
$rev) >>"$GIT_DIR/BISECT_LOG"
281 echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
284 echo >&2 "?? what are you talking about?"
292 bisect_next_check fail
300 # Check for really bad run error.
301 if [ $res -lt
0 -o
$res -ge
128 ]; then
302 echo >&2 "bisect run failed:"
303 echo >&2 "exit code $res from '$@' is < 0 or >= 128"
307 # Use "bisect_good" or "bisect_bad"
308 # depending on run success or failure.
309 if [ $res -gt
0 ]; then
310 next_bisect
='bisect_bad'
312 next_bisect
='bisect_good'
315 # We have to use a subshell because bisect_good or
316 # bisect_bad functions can exit.
317 ( $next_bisect > "$GIT_DIR/BISECT_RUN" )
320 cat "$GIT_DIR/BISECT_RUN"
322 if [ $res -ne
0 ]; then
323 echo >&2 "bisect run failed:"
324 echo >&2 "$next_bisect exited with error code $res"
328 if grep "is first bad commit" "$GIT_DIR/BISECT_RUN" > /dev
/null
; then
329 echo "bisect run success"
351 # Not sure we want "next" at the UI level anymore.
354 bisect_visualize
"$@" ;;
358 bisect_replay
"$@" ;;
360 cat "$GIT_DIR/BISECT_LOG" ;;