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=$(readlink $GIT_DIR/HEAD) || die "Bad HEAD - I need a symlink"
44 git checkout master || exit
49 die "Bad HEAD - strange symlink"
54 # Get rid of any old bisect state
56 rm -f "$GIT_DIR/refs/heads/bisect"
57 rm -rf "$GIT_DIR/refs/bisect/"
58 mkdir "$GIT_DIR/refs/bisect"
59 echo "git-bisect start" >"$GIT_DIR/BISECT_LOG"
66 rev=$(git-rev-parse --verify HEAD) ;;
68 rev=$(git-rev-parse --verify "$1") ;;
72 echo "$rev" >"$GIT_DIR/refs/bisect/bad"
73 echo "# bad: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
74 echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
81 0) revs=$(git-rev-parse --verify HEAD) || exit ;;
82 *) revs=$(git-rev-parse --revs-only --no-flags "$@") &&
83 test '' != "$revs" || die "Bad rev input: $@" ;;
87 rev=$(git-rev-parse --verify "$rev") || exit
88 echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
89 echo "# good: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
90 echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
97 test -f "$GIT_DIR/refs/bisect/bad" &&
98 case "$(cd "$GIT_DIR" && echo refs/bisect/good-*)" in
99 refs/bisect/good-\*) ;;
102 case "$next_ok,$1" in
105 echo >&2 'You need to give me at least one good and one bad revisions.'
113 bisect_next_check && bisect_next
117 case "$#" in 0) ;; *) usage ;; esac
119 bisect_next_check fail
120 bad=$(git-rev-parse --verify refs/bisect/bad) &&
121 good=$(git-rev-parse --sq --revs-only --not \
122 $(cd "$GIT_DIR" && ls refs/bisect/good-*)) &&
123 rev=$(eval "git-rev-list --bisect $good $bad") || exit
124 if [ -z "$rev" ]; then
125 echo "$bad was both good and bad"
128 if [ "$rev" = "$bad" ]; then
129 echo "$rev is first bad commit"
130 git-diff-tree --pretty $rev
133 nr=$(eval "git-rev-list $rev $good" | wc -l) || exit
134 echo "Bisecting: $nr revisions left to test after this"
135 echo "$rev" > "$GIT_DIR/refs/heads/new-bisect"
136 git checkout new-bisect || exit
137 mv "$GIT_DIR/refs/heads/new-bisect" "$GIT_DIR/refs/heads/bisect" &&
138 ln -sf refs/heads/bisect "$GIT_DIR/HEAD"
139 git-show-branch "$rev"
143 bisect_next_check fail
144 gitk bisect/bad --not `cd "$GIT_DIR/refs" && echo bisect/good-*`
150 1) test -f "$GIT_DIR/refs/heads/$1" || {
151 echo >&2 "$1 does not seem to be a valid branch"
158 git checkout "$branch" &&
159 rm -fr "$GIT_DIR/refs/bisect"
160 rm -f "$GIT_DIR/refs/heads/bisect"
161 rm -f "$GIT_DIR/BISECT_LOG"
166 echo >&2 "cannot read $1 for replaying"
170 while read bisect command rev
172 test "$bisect" = "git-bisect" || continue
178 echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
179 echo "# good: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
180 echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
183 echo "$rev" >"$GIT_DIR/refs/bisect/bad"
184 echo "# bad: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
185 echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
188 echo >&2 "?? what are you talking about?"
209 # Not sure we want "next" at the UI level anymore.
212 bisect_visualize "$@" ;;
216 bisect_replay "$@" ;;
218 cat "$GIT_DIR/BISECT_LOG" ;;