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 git checkout master || exit
57 die "Bad HEAD - strange symbolic ref"
62 # Get rid of any old bisect state
64 rm -f "$GIT_DIR/refs/heads/bisect"
65 rm -rf "$GIT_DIR/refs/bisect/"
66 mkdir "$GIT_DIR/refs/bisect"
68 printf "git-bisect start"
70 } >"$GIT_DIR/BISECT_LOG"
71 sq "$@" >"$GIT_DIR/BISECT_NAMES"
78 rev=$(git-rev-parse --verify HEAD) ;;
80 rev=$(git-rev-parse --verify "$1") ;;
84 echo "$rev" >"$GIT_DIR/refs/bisect/bad"
85 echo "# bad: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
86 echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
93 0) revs=$(git-rev-parse --verify HEAD) || exit ;;
94 *) revs=$(git-rev-parse --revs-only --no-flags "$@") &&
95 test '' != "$revs" || die "Bad rev input: $@" ;;
99 rev=$(git-rev-parse --verify "$rev") || exit
100 echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
101 echo "# good: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
102 echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
107 bisect_next_check() {
109 test -f "$GIT_DIR/refs/bisect/bad" &&
110 case "$(cd "$GIT_DIR" && echo refs/bisect/good-*)" in
111 refs/bisect/good-\*) ;;
114 case "$next_ok,$1" in
117 echo >&2 'You need to give me at least one good and one bad revisions.'
125 bisect_next_check && bisect_next || :
129 case "$#" in 0) ;; *) usage ;; esac
131 bisect_next_check fail
132 bad=$(git-rev-parse --verify refs/bisect/bad) &&
133 good=$(git-rev-parse --sq --revs-only --not \
134 $(cd "$GIT_DIR" && ls refs/bisect/good-*)) &&
135 rev=$(eval "git-rev-list --bisect $good $bad -- $(cat $GIT_DIR/BISECT_NAMES)") || exit
136 if [ -z "$rev" ]; then
137 echo "$bad was both good and bad"
140 if [ "$rev" = "$bad" ]; then
141 echo "$rev is first bad commit"
142 git-diff-tree --pretty $rev
145 nr=$(eval "git-rev-list $rev $good -- $(cat $GIT_DIR/BISECT_NAMES)" | wc -l) || exit
146 echo "Bisecting: $nr revisions left to test after this"
147 echo "$rev" > "$GIT_DIR/refs/heads/new-bisect"
148 git checkout new-bisect || exit
149 mv "$GIT_DIR/refs/heads/new-bisect" "$GIT_DIR/refs/heads/bisect" &&
150 GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD refs/heads/bisect
151 git-show-branch "$rev"
155 bisect_next_check fail
156 not=`cd "$GIT_DIR/refs" && echo bisect/good-*`
157 eval gitk bisect/bad --not $not -- $(cat "$GIT_DIR/BISECT_NAMES")
163 1) test -f "$GIT_DIR/refs/heads/$1" || {
164 echo >&2 "$1 does not seem to be a valid branch"
171 git checkout "$branch" &&
172 rm -fr "$GIT_DIR/refs/bisect"
173 rm -f "$GIT_DIR/refs/heads/bisect"
174 rm -f "$GIT_DIR/BISECT_LOG"
179 echo >&2 "cannot read $1 for replaying"
183 while read bisect command rev
185 test "$bisect" = "git-bisect" || continue
188 cmd="bisect_start $rev"
192 echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
193 echo "# good: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
194 echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
197 echo "$rev" >"$GIT_DIR/refs/bisect/bad"
198 echo "# bad: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
199 echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
202 echo >&2 "?? what are you talking about?"
223 # Not sure we want "next" at the UI level anymore.
226 bisect_visualize "$@" ;;
230 bisect_replay "$@" ;;
232 cat "$GIT_DIR/BISECT_LOG" ;;