2 . git-sh-setup-script || dir "Not a git archive"
5 echo >&2 'usage: git bisect [start | bad | good | next | reset]
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.'
15 test -d "$GIT_DIR/refs/bisect" || {
16 echo >&2 'You need to start by "git bisect start"'
19 echo >&2 -n 'Do you want me to do it for you [Y/n]? '
33 case "$#" in 0) ;; *) usage ;; esac
35 # Verify HEAD. If we were bisecting before this, reset to the
36 # top-of-line master first!
38 head=$(readlink $GIT_DIR/HEAD) || die "Bad HEAD - I need a symlink"
41 git checkout master || exit
46 die "Bad HEAD - strange symlink"
51 # Get rid of any old bisect state
53 rm -f "$GIT_DIR/refs/heads/bisect"
54 rm -rf "$GIT_DIR/refs/bisect/"
55 mkdir "$GIT_DIR/refs/bisect"
60 case "$#" in 0 | 1) ;; *) usage ;; esac
61 rev=$(git-rev-parse --verify --default HEAD "$@") || exit
62 echo "$rev" > "$GIT_DIR/refs/bisect/bad"
69 0) revs=$(git-rev-parse --verify HEAD) || exit ;;
70 *) revs=$(git-rev-parse --revs-only --no-flags "$@") || exit ;;
74 echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
81 test -f "$GIT_DIR/refs/bisect/bad" &&
82 case "$(cd "$GIT_DIR" && echo refs/bisect/good-*)" in
83 refs/bisect/good-\*) ;;
89 echo >&2 'You need to give me at least one good and one bad revisions.'
97 bisect_next_check && bisect_next
101 case "$#" in 0) ;; *) usage ;; esac
103 bisect_next_check fail
104 bad=$(git-rev-parse --verify refs/bisect/bad) &&
105 good=$(git-rev-parse --sq --revs-only --not \
106 $(cd "$GIT_DIR" && ls refs/bisect/good-*)) &&
107 rev=$(eval "git-rev-list --bisect $good $bad") || exit
108 nr=$(eval "git-rev-list $rev $good" | wc -l) || exit
109 if [ "$nr" -le "1" ]; then
110 echo "$rev is first bad commit"
111 git-diff-tree --pretty $rev
114 echo "Bisecting: $nr revisions left to test after this"
115 echo "$rev" > "$GIT_DIR/refs/heads/new-bisect"
116 git checkout new-bisect || exit
117 mv "$GIT_DIR/refs/heads/new-bisect" "$GIT_DIR/refs/heads/bisect" &&
118 ln -sf refs/heads/bisect "$GIT_DIR/HEAD"
124 1) test -f "$GIT_DIR/refs/heads/$1" || {
125 echo >&2 "$1 does not seem to be a valid branch"
132 git checkout "$branch" &&
133 rm -fr "$GIT_DIR/refs/bisect"
134 rm -f "$GIT_DIR/refs/reads/bisect"
151 # Not sure we want "next" at the UI level anymore.