]> git.ipfire.org Git - thirdparty/git.git/blobdiff - git-bisect.sh
Bisect: convert revs given to good and bad to commits
[thirdparty/git.git] / git-bisect.sh
index 06a8d26945a679b06438308ceb96c69cd76c43db..dbce0dfec93e41f6c1246ce7648ca1c40aeef5b0 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-USAGE='[start|bad|good|next|reset|visualize]'
+USAGE='[start|bad|good|next|reset|visualize|replay|log]'
 LONG_USAGE='git bisect start [<pathspec>]      reset bisect state and start bisection.
 git bisect bad [<rev>]         mark <rev> a known-bad revision.
 git bisect good [<rev>...]     mark <rev>... known-good revisions.
@@ -11,6 +11,7 @@ git bisect replay <logfile>   replay bisection log
 git bisect log                 show bisect log.'
 
 . git-sh-setup
+require_work_tree
 
 sq() {
        @@PERL@@ -e '
@@ -84,7 +85,7 @@ bisect_bad() {
        0)
                rev=$(git-rev-parse --verify HEAD) ;;
        1)
-               rev=$(git-rev-parse --verify "$1") ;;
+               rev=$(git-rev-parse --verify "$1^{commit}") ;;
        *)
                usage ;;
        esac || exit
@@ -103,7 +104,7 @@ bisect_good() {
        esac
        for rev in $revs
        do
-               rev=$(git-rev-parse --verify "$rev") || exit
+               rev=$(git-rev-parse --verify "$rev^{commit}") || exit
                echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
                echo "# good: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
                echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
@@ -152,7 +153,7 @@ bisect_next() {
        nr=$(eval "git-rev-list $rev $good -- $(cat $GIT_DIR/BISECT_NAMES)" | wc -l) || exit
        echo "Bisecting: $nr revisions left to test after this"
        echo "$rev" > "$GIT_DIR/refs/heads/new-bisect"
-       git checkout new-bisect || exit
+       git checkout -q new-bisect || exit
        mv "$GIT_DIR/refs/heads/new-bisect" "$GIT_DIR/refs/heads/bisect" &&
        GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD refs/heads/bisect
        git-show-branch "$rev"
@@ -179,11 +180,12 @@ bisect_reset() {
         *)
            usage ;;
        esac
-       git checkout "$branch" &&
-       rm -fr "$GIT_DIR/refs/bisect"
-       rm -f "$GIT_DIR/refs/heads/bisect" "$GIT_DIR/head-name"
-       rm -f "$GIT_DIR/BISECT_LOG"
-       rm -f "$GIT_DIR/BISECT_NAMES"
+       if git checkout "$branch"; then
+               rm -fr "$GIT_DIR/refs/bisect"
+               rm -f "$GIT_DIR/refs/heads/bisect" "$GIT_DIR/head-name"
+               rm -f "$GIT_DIR/BISECT_LOG"
+               rm -f "$GIT_DIR/BISECT_NAMES"
+       fi
 }
 
 bisect_replay () {