3 USAGE
='[start|bad|good|next|reset|visualize]'
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.'
18 s/'\''/'\'\\\\\'\''/g;
26 test -d "$GIT_DIR/refs/bisect" ||
{
27 echo >&2 'You need to start by "git bisect start"'
30 echo >&2 -n 'Do you want me to do it for you [Y/n]? '
45 # Verify HEAD. If we were bisecting before this, reset to the
46 # top-of-line master first!
48 head=$
(GIT_DIR
="$GIT_DIR" git-symbolic-ref HEAD
) ||
49 die
"Bad HEAD - I need a symbolic ref"
52 if [ -s "$GIT_DIR/head-name" ]; then
53 branch
=`cat "$GIT_DIR/head-name"`
57 git checkout
$branch ||
exit
60 [ -s "$GIT_DIR/head-name" ] && die
"won't bisect on seeked tree"
61 echo "$head" |
sed 's#^refs/heads/##' >"$GIT_DIR/head-name"
64 die
"Bad HEAD - strange symbolic ref"
69 # Get rid of any old bisect state
71 rm -f "$GIT_DIR/refs/heads/bisect"
72 rm -rf "$GIT_DIR/refs/bisect/"
73 mkdir
"$GIT_DIR/refs/bisect"
75 printf "git-bisect start"
77 } >"$GIT_DIR/BISECT_LOG"
78 sq "$@" >"$GIT_DIR/BISECT_NAMES"
85 rev=$
(git-rev-parse
--verify HEAD
) ;;
87 rev=$
(git-rev-parse
--verify "$1") ;;
91 echo "$rev" >"$GIT_DIR/refs/bisect/bad"
92 echo "# bad: "$
(git-show-branch
$rev) >>"$GIT_DIR/BISECT_LOG"
93 echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
100 0) revs
=$
(git-rev-parse
--verify HEAD
) ||
exit ;;
101 *) revs
=$
(git-rev-parse
--revs-only --no-flags "$@") &&
102 test '' != "$revs" || die
"Bad rev input: $@" ;;
106 rev=$
(git-rev-parse
--verify "$rev") ||
exit
107 echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
108 echo "# good: "$
(git-show-branch
$rev) >>"$GIT_DIR/BISECT_LOG"
109 echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
114 bisect_next_check
() {
116 test -f "$GIT_DIR/refs/bisect/bad" &&
117 case "$(cd "$GIT_DIR" && echo refs/bisect/good-*)" in
118 refs
/bisect
/good-\
*) ;;
121 case "$next_ok,$1" in
124 echo >&2 'You need to give me at least one good and one bad revisions.'
132 bisect_next_check
&& bisect_next ||
:
136 case "$#" in 0) ;; *) usage
;; esac
138 bisect_next_check fail
139 bad
=$
(git-rev-parse
--verify refs
/bisect
/bad
) &&
140 good
=$
(git-rev-parse
--sq --revs-only --not \
141 $
(cd "$GIT_DIR" && ls refs
/bisect
/good-
*)) &&
142 rev=$
(eval "git-rev-list --bisect $good $bad -- $(cat $GIT_DIR/BISECT_NAMES)") ||
exit
143 if [ -z "$rev" ]; then
144 echo "$bad was both good and bad"
147 if [ "$rev" = "$bad" ]; then
148 echo "$rev is first bad commit"
149 git-diff-tree
--pretty $rev
152 nr
=$
(eval "git-rev-list $rev $good -- $(cat $GIT_DIR/BISECT_NAMES)" |
wc -l) ||
exit
153 echo "Bisecting: $nr revisions left to test after this"
154 echo "$rev" > "$GIT_DIR/refs/heads/new-bisect"
155 git checkout
-q new-bisect ||
exit
156 mv "$GIT_DIR/refs/heads/new-bisect" "$GIT_DIR/refs/heads/bisect" &&
157 GIT_DIR
="$GIT_DIR" git-symbolic-ref HEAD refs
/heads
/bisect
158 git-show-branch
"$rev"
162 bisect_next_check fail
163 not
=`cd "$GIT_DIR/refs" && echo bisect/good-*`
164 eval gitk bisect
/bad
--not $not -- $
(cat "$GIT_DIR/BISECT_NAMES")
169 0) if [ -s "$GIT_DIR/head-name" ]; then
170 branch
=`cat "$GIT_DIR/head-name"`
174 1) test -f "$GIT_DIR/refs/heads/$1" ||
{
175 echo >&2 "$1 does not seem to be a valid branch"
182 if git checkout
"$branch"; then
183 rm -fr "$GIT_DIR/refs/bisect"
184 rm -f "$GIT_DIR/refs/heads/bisect" "$GIT_DIR/head-name"
185 rm -f "$GIT_DIR/BISECT_LOG"
186 rm -f "$GIT_DIR/BISECT_NAMES"
192 echo >&2 "cannot read $1 for replaying"
196 while read bisect
command rev
198 test "$bisect" = "git-bisect" ||
continue
201 cmd
="bisect_start $rev"
205 echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
206 echo "# good: "$
(git-show-branch
$rev) >>"$GIT_DIR/BISECT_LOG"
207 echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
210 echo "$rev" >"$GIT_DIR/refs/bisect/bad"
211 echo "# bad: "$
(git-show-branch
$rev) >>"$GIT_DIR/BISECT_LOG"
212 echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
215 echo >&2 "?? what are you talking about?"
236 # Not sure we want "next" at the UI level anymore.
239 bisect_visualize
"$@" ;;
243 bisect_replay
"$@" ;;
245 cat "$GIT_DIR/BISECT_LOG" ;;