15 echo >&2 'usage: git bisect [start|bad|good|next|reset|visualize]
16 git bisect start [<pathspec>] reset bisect state and start bisection.
17 git bisect bad [<rev>] mark <rev> a known-bad revision.
18 git bisect good [<rev>...] mark <rev>... known-good revisions.
19 git bisect next find next bisection to test and check it out.
20 git bisect reset [<branch>] finish bisection search and go back to branch.
21 git bisect visualize show bisect status in gitk.
22 git bisect replay <logfile> replay bisection log
23 git bisect log show bisect log.'
28 test -d "$GIT_DIR/refs/bisect" ||
{
29 echo >&2 'You need to start by "git bisect start"'
32 echo >&2 -n 'Do you want me to do it for you [Y/n]? '
47 # Verify HEAD. If we were bisecting before this, reset to the
48 # top-of-line master first!
50 head=$
(GIT_DIR
="$GIT_DIR" git-symbolic-ref HEAD
) ||
51 die
"Bad HEAD - I need a symbolic ref"
54 git checkout master ||
exit
59 die
"Bad HEAD - strange symbolic ref"
64 # Get rid of any old bisect state
66 rm -f "$GIT_DIR/refs/heads/bisect"
67 rm -rf "$GIT_DIR/refs/bisect/"
68 mkdir
"$GIT_DIR/refs/bisect"
70 echo -n "git-bisect start"
72 } >"$GIT_DIR/BISECT_LOG"
73 sq "$@" >"$GIT_DIR/BISECT_NAMES"
80 rev=$
(git-rev-parse
--verify HEAD
) ;;
82 rev=$
(git-rev-parse
--verify "$1") ;;
86 echo "$rev" >"$GIT_DIR/refs/bisect/bad"
87 echo "# bad: "$
(git-show-branch
$rev) >>"$GIT_DIR/BISECT_LOG"
88 echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
95 0) revs
=$
(git-rev-parse
--verify HEAD
) ||
exit ;;
96 *) revs
=$
(git-rev-parse
--revs-only --no-flags "$@") &&
97 test '' != "$revs" || die
"Bad rev input: $@" ;;
101 rev=$
(git-rev-parse
--verify "$rev") ||
exit
102 echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
103 echo "# good: "$
(git-show-branch
$rev) >>"$GIT_DIR/BISECT_LOG"
104 echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
109 bisect_next_check
() {
111 test -f "$GIT_DIR/refs/bisect/bad" &&
112 case "$(cd "$GIT_DIR" && echo refs/bisect/good-*)" in
113 refs
/bisect
/good-\
*) ;;
116 case "$next_ok,$1" in
119 echo >&2 'You need to give me at least one good and one bad revisions.'
127 bisect_next_check
&& bisect_next ||
:
131 case "$#" in 0) ;; *) usage
;; esac
133 bisect_next_check fail
134 bad
=$
(git-rev-parse
--verify refs
/bisect
/bad
) &&
135 good
=$
(git-rev-parse
--sq --revs-only --not \
136 $
(cd "$GIT_DIR" && ls refs
/bisect
/good-
*)) &&
137 rev=$
(eval "git-rev-list --bisect $good $bad -- $(cat $GIT_DIR/BISECT_NAMES)") ||
exit
138 if [ -z "$rev" ]; then
139 echo "$bad was both good and bad"
142 if [ "$rev" = "$bad" ]; then
143 echo "$rev is first bad commit"
144 git-diff-tree
--pretty $rev
147 nr
=$
(eval "git-rev-list $rev $good -- $(cat $GIT_DIR/BISECT_NAMES)" |
wc -l) ||
exit
148 echo "Bisecting: $nr revisions left to test after this"
149 echo "$rev" > "$GIT_DIR/refs/heads/new-bisect"
150 git checkout new-bisect ||
exit
151 mv "$GIT_DIR/refs/heads/new-bisect" "$GIT_DIR/refs/heads/bisect" &&
152 GIT_DIR
="$GIT_DIR" git-symbolic-ref HEAD refs
/heads
/bisect
153 git-show-branch
"$rev"
157 bisect_next_check fail
158 not
=`cd "$GIT_DIR/refs" && echo bisect/good-*`
159 eval gitk bisect
/bad
--not $not -- $
(cat "$GIT_DIR/BISECT_NAMES")
165 1) test -f "$GIT_DIR/refs/heads/$1" ||
{
166 echo >&2 "$1 does not seem to be a valid branch"
173 git checkout
"$branch" &&
174 rm -fr "$GIT_DIR/refs/bisect"
175 rm -f "$GIT_DIR/refs/heads/bisect"
176 rm -f "$GIT_DIR/BISECT_LOG"
181 echo >&2 "cannot read $1 for replaying"
185 while read bisect
command rev
187 test "$bisect" = "git-bisect" ||
continue
190 cmd
="bisect_start $rev"
194 echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
195 echo "# good: "$
(git-show-branch
$rev) >>"$GIT_DIR/BISECT_LOG"
196 echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
199 echo "$rev" >"$GIT_DIR/refs/bisect/bad"
200 echo "# bad: "$
(git-show-branch
$rev) >>"$GIT_DIR/BISECT_LOG"
201 echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
204 echo >&2 "?? what are you talking about?"
225 # Not sure we want "next" at the UI level anymore.
228 bisect_visualize
"$@" ;;
232 bisect_replay
"$@" ;;
234 cat "$GIT_DIR/BISECT_LOG" ;;