2 . git-sh-setup || dir "Not a git archive"
5 echo >&2 'usage: git bisect [start|bad|good|next|reset|visualize]
6 git bisect start reset bisect state and start bisection.
7 git bisect bad [<rev>] mark <rev> a known-bad revision.
8 git bisect good [<rev>...] mark <rev>... known-good revisions.
9 git bisect next find next bisection to test and check it out.
10 git bisect reset [<branch>] finish bisection search and go back to branch.
11 git bisect visualize show bisect status in gitk.
12 git bisect replay <logfile> replay bisection log
13 git bisect log show bisect log.'
18 test -d "$GIT_DIR/refs/bisect" || {
19 echo >&2 'You need to start by "git bisect start"'
22 echo >&2 -n 'Do you want me to do it for you [Y/n]? '
36 case "$#" in 0) ;; *) usage ;; esac
38 # Verify HEAD. If we were bisecting before this, reset to the
39 # top-of-line master first!
41 head=$(GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD) ||
42 die "Bad HEAD - I need a symbolic ref"
45 git checkout master || exit
50 die "Bad HEAD - strange symbolic ref"
55 # Get rid of any old bisect state
57 rm -f "$GIT_DIR/refs/heads/bisect"
58 rm -rf "$GIT_DIR/refs/bisect/"
59 mkdir "$GIT_DIR/refs/bisect"
60 echo "git-bisect start" >"$GIT_DIR/BISECT_LOG"
67 rev=$(git-rev-parse --verify HEAD) ;;
69 rev=$(git-rev-parse --verify "$1") ;;
73 echo "$rev" >"$GIT_DIR/refs/bisect/bad"
74 echo "# bad: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
75 echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
82 0) revs=$(git-rev-parse --verify HEAD) || exit ;;
83 *) revs=$(git-rev-parse --revs-only --no-flags "$@") &&
84 test '' != "$revs" || die "Bad rev input: $@" ;;
88 rev=$(git-rev-parse --verify "$rev") || exit
89 echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
90 echo "# good: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
91 echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
98 test -f "$GIT_DIR/refs/bisect/bad" &&
99 case "$(cd "$GIT_DIR" && echo refs/bisect/good-*)" in
100 refs/bisect/good-\*) ;;
103 case "$next_ok,$1" in
106 echo >&2 'You need to give me at least one good and one bad revisions.'
114 bisect_next_check && bisect_next || :
118 case "$#" in 0) ;; *) usage ;; esac
120 bisect_next_check fail
121 bad=$(git-rev-parse --verify refs/bisect/bad) &&
122 good=$(git-rev-parse --sq --revs-only --not \
123 $(cd "$GIT_DIR" && ls refs/bisect/good-*)) &&
124 rev=$(eval "git-rev-list --bisect $good $bad") || exit
125 if [ -z "$rev" ]; then
126 echo "$bad was both good and bad"
129 if [ "$rev" = "$bad" ]; then
130 echo "$rev is first bad commit"
131 git-diff-tree --pretty $rev
134 nr=$(eval "git-rev-list $rev $good" | wc -l) || exit
135 echo "Bisecting: $nr revisions left to test after this"
136 echo "$rev" > "$GIT_DIR/refs/heads/new-bisect"
137 git checkout new-bisect || exit
138 mv "$GIT_DIR/refs/heads/new-bisect" "$GIT_DIR/refs/heads/bisect" &&
139 GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD refs/heads/bisect
140 git-show-branch "$rev"
144 bisect_next_check fail
145 gitk bisect/bad --not `cd "$GIT_DIR/refs" && echo bisect/good-*`
151 1) test -f "$GIT_DIR/refs/heads/$1" || {
152 echo >&2 "$1 does not seem to be a valid branch"
159 git checkout "$branch" &&
160 rm -fr "$GIT_DIR/refs/bisect"
161 rm -f "$GIT_DIR/refs/heads/bisect"
162 rm -f "$GIT_DIR/BISECT_LOG"
167 echo >&2 "cannot read $1 for replaying"
171 while read bisect command rev
173 test "$bisect" = "git-bisect" || continue
179 echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
180 echo "# good: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
181 echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
184 echo "$rev" >"$GIT_DIR/refs/bisect/bad"
185 echo "# bad: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
186 echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
189 echo >&2 "?? what are you talking about?"
210 # Not sure we want "next" at the UI level anymore.
213 bisect_visualize "$@" ;;
217 bisect_replay "$@" ;;
219 cat "$GIT_DIR/BISECT_LOG" ;;