3 USAGE
='[start|bad|good|next|reset|visualize|replay|log]'
4 LONG_USAGE
='git bisect start [<pathspec>] reset bisect state and start bisection.
5 git bisect bad [<rev>] mark <rev> a known-bad revision.
6 git bisect good [<rev>...] mark <rev>... known-good revisions.
7 git bisect next find next bisection to test and check it out.
8 git bisect reset [<branch>] finish bisection search and go back to branch.
9 git bisect visualize show bisect status in gitk.
10 git bisect replay <logfile> replay bisection log
11 git bisect log show bisect log.'
19 s/'\''/'\'\\\\\'\''/g;
27 test -d "$GIT_DIR/refs/bisect" ||
{
28 echo >&2 'You need to start by "git bisect start"'
31 echo >&2 -n 'Do you want me to do it for you [Y/n]? '
46 # Verify HEAD. If we were bisecting before this, reset to the
47 # top-of-line master first!
49 head=$
(GIT_DIR
="$GIT_DIR" git-symbolic-ref HEAD
) ||
50 die
"Bad HEAD - I need a symbolic ref"
53 if [ -s "$GIT_DIR/head-name" ]; then
54 branch
=`cat "$GIT_DIR/head-name"`
58 git checkout
$branch ||
exit
61 [ -s "$GIT_DIR/head-name" ] && die
"won't bisect on seeked tree"
62 echo "$head" |
sed 's#^refs/heads/##' >"$GIT_DIR/head-name"
65 die
"Bad HEAD - strange symbolic ref"
70 # Get rid of any old bisect state
72 rm -f "$GIT_DIR/refs/heads/bisect"
73 rm -rf "$GIT_DIR/refs/bisect/"
74 mkdir
"$GIT_DIR/refs/bisect"
76 printf "git-bisect start"
78 } >"$GIT_DIR/BISECT_LOG"
79 sq "$@" >"$GIT_DIR/BISECT_NAMES"
86 rev=$
(git-rev-parse
--verify HEAD
) ;;
88 rev=$
(git-rev-parse
--verify "$1") ;;
92 echo "$rev" >"$GIT_DIR/refs/bisect/bad"
93 echo "# bad: "$
(git-show-branch
$rev) >>"$GIT_DIR/BISECT_LOG"
94 echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
101 0) revs
=$
(git-rev-parse
--verify HEAD
) ||
exit ;;
102 *) revs
=$
(git-rev-parse
--revs-only --no-flags "$@") &&
103 test '' != "$revs" || die
"Bad rev input: $@" ;;
107 rev=$
(git-rev-parse
--verify "$rev") ||
exit
108 echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
109 echo "# good: "$
(git-show-branch
$rev) >>"$GIT_DIR/BISECT_LOG"
110 echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
115 bisect_next_check
() {
117 test -f "$GIT_DIR/refs/bisect/bad" &&
118 case "$(cd "$GIT_DIR" && echo refs/bisect/good-*)" in
119 refs
/bisect
/good-\
*) ;;
122 case "$next_ok,$1" in
125 echo >&2 'You need to give me at least one good and one bad revisions.'
133 bisect_next_check
&& bisect_next ||
:
137 case "$#" in 0) ;; *) usage
;; esac
139 bisect_next_check fail
140 bad
=$
(git-rev-parse
--verify refs
/bisect
/bad
) &&
141 good
=$
(git-rev-parse
--sq --revs-only --not \
142 $
(cd "$GIT_DIR" && ls refs
/bisect
/good-
*)) &&
143 rev=$
(eval "git-rev-list --bisect $good $bad -- $(cat $GIT_DIR/BISECT_NAMES)") ||
exit
144 if [ -z "$rev" ]; then
145 echo "$bad was both good and bad"
148 if [ "$rev" = "$bad" ]; then
149 echo "$rev is first bad commit"
150 git-diff-tree
--pretty $rev
153 nr
=$
(eval "git-rev-list $rev $good -- $(cat $GIT_DIR/BISECT_NAMES)" |
wc -l) ||
exit
154 echo "Bisecting: $nr revisions left to test after this"
155 echo "$rev" > "$GIT_DIR/refs/heads/new-bisect"
156 git checkout
-q new-bisect ||
exit
157 mv "$GIT_DIR/refs/heads/new-bisect" "$GIT_DIR/refs/heads/bisect" &&
158 GIT_DIR
="$GIT_DIR" git-symbolic-ref HEAD refs
/heads
/bisect
159 git-show-branch
"$rev"
163 bisect_next_check fail
164 not
=`cd "$GIT_DIR/refs" && echo bisect/good-*`
165 eval gitk bisect
/bad
--not $not -- $
(cat "$GIT_DIR/BISECT_NAMES")
170 0) if [ -s "$GIT_DIR/head-name" ]; then
171 branch
=`cat "$GIT_DIR/head-name"`
175 1) test -f "$GIT_DIR/refs/heads/$1" ||
{
176 echo >&2 "$1 does not seem to be a valid branch"
183 if git checkout
"$branch"; then
184 rm -fr "$GIT_DIR/refs/bisect"
185 rm -f "$GIT_DIR/refs/heads/bisect" "$GIT_DIR/head-name"
186 rm -f "$GIT_DIR/BISECT_LOG"
187 rm -f "$GIT_DIR/BISECT_NAMES"
193 echo >&2 "cannot read $1 for replaying"
197 while read bisect
command rev
199 test "$bisect" = "git-bisect" ||
continue
202 cmd
="bisect_start $rev"
206 echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
207 echo "# good: "$
(git-show-branch
$rev) >>"$GIT_DIR/BISECT_LOG"
208 echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
211 echo "$rev" >"$GIT_DIR/refs/bisect/bad"
212 echo "# bad: "$
(git-show-branch
$rev) >>"$GIT_DIR/BISECT_LOG"
213 echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
216 echo >&2 "?? what are you talking about?"
237 # Not sure we want "next" at the UI level anymore.
240 bisect_visualize
"$@" ;;
244 bisect_replay
"$@" ;;
246 cat "$GIT_DIR/BISECT_LOG" ;;