]> asedeno.scripts.mit.edu Git - git.git/blobdiff - git-bisect.sh
cvsexportcommit: chomp only removes trailing whitespace
[git.git] / git-bisect.sh
index 408775a51e2ad7b3007ea8a0001516c26166318a..164e8ed81fc3ecb5d33dafb9af0992761bfe513d 100755 (executable)
@@ -66,23 +66,29 @@ bisect_start() {
        # Verify HEAD. If we were bisecting before this, reset to the
        # top-of-line master first!
        #
-       head=$(GIT_DIR="$GIT_DIR" git symbolic-ref HEAD) ||
+       head=$(GIT_DIR="$GIT_DIR" git symbolic-ref -q HEAD) ||
        head=$(GIT_DIR="$GIT_DIR" git rev-parse --verify HEAD) ||
        die "Bad HEAD - I need a HEAD"
+       #
+       # Check that we either already have BISECT_START, or that the
+       # branches bisect, new-bisect don't exist, to not override them.
+       #
+       test -s "$GIT_DIR/BISECT_START" ||
+               if git show-ref --verify -q refs/heads/bisect ||
+                   git show-ref --verify -q refs/heads/new-bisect; then
+                       die 'The branches "bisect" and "new-bisect" must not exist.'
+               fi
+       start_head=''
        case "$head" in
        refs/heads/bisect)
-               if [ -s "$GIT_DIR/BISECT_START" ]; then
-                   branch=`cat "$GIT_DIR/BISECT_START"`
-               else
-                   branch=master
-               fi
+               branch=`cat "$GIT_DIR/BISECT_START"`
                git checkout $branch || exit
                ;;
        refs/heads/*|$_x40)
                # This error message should only be triggered by cogito usage,
                # and cogito users should understand it relates to cg-seek.
                [ -s "$GIT_DIR/head-name" ] && die "won't bisect on seeked tree"
-               echo "${head#refs/heads/}" >"$GIT_DIR/BISECT_START"
+               start_head="${head#refs/heads/}"
                ;;
        *)
                die "Bad HEAD - strange symbolic ref"
@@ -103,6 +109,7 @@ bisect_start() {
        done
        orig_args=$(sq "$@")
        bad_seen=0
+       eval=''
        while [ $# -gt 0 ]; do
            arg="$1"
            case "$arg" in
@@ -120,13 +127,15 @@ bisect_start() {
                0) state='bad' ; bad_seen=1 ;;
                *) state='good' ;;
                esac
-               bisect_write "$state" "$rev" 'nolog'
+               eval="$eval bisect_write '$state' '$rev' 'nolog'; "
                shift
                ;;
            esac
        done
 
        sq "$@" >"$GIT_DIR/BISECT_NAMES"
+       test -n "$start_head" && echo "$start_head" >"$GIT_DIR/BISECT_START"
+       eval "$eval"
        echo "git-bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG"
        bisect_auto_next
 }
@@ -157,12 +166,14 @@ bisect_state() {
                bisect_write "$state" "$rev" ;;
        2,bad|*,good|*,skip)
                shift
+               eval=''
                for rev in "$@"
                do
                        sha=$(git rev-parse --verify "$rev^{commit}") ||
                                die "Bad rev input: $rev"
-                       bisect_write "$state" "$sha"
-               done ;;
+                       eval="$eval bisect_write '$state' '$sha'; "
+               done
+               eval "$eval" ;;
        *,bad)
                die "'git bisect bad' can take only one argument." ;;
        *)
@@ -213,18 +224,33 @@ bisect_auto_next() {
        bisect_next_check && bisect_next || :
 }
 
+eval_rev_list() {
+       _eval="$1"
+
+       eval $_eval
+       res=$?
+
+       if [ $res -ne 0 ]; then
+               echo >&2 "'git rev-list --bisect-vars' failed:"
+               echo >&2 "maybe you mistake good and bad revs?"
+               exit $res
+       fi
+
+       return $res
+}
+
 filter_skipped() {
        _eval="$1"
        _skip="$2"
 
        if [ -z "$_skip" ]; then
-               eval $_eval
+               eval_rev_list "$_eval"
                return
        fi
 
        # Let's parse the output of:
        # "git rev-list --bisect-vars --bisect-all ..."
-       eval $_eval | while read hash line
+       eval_rev_list "$_eval" | while read hash line
        do
                case "$VARS,$FOUND,$TRIED,$hash" in
                        # We display some vars.
@@ -322,8 +348,8 @@ bisect_next() {
        exit_if_skipped_commits "$bisect_rev"
 
        echo "Bisecting: $bisect_nr revisions left to test after this"
-       git branch -f new-bisect "$bisect_rev"
-       git checkout -q new-bisect || exit
+       git branch -D new-bisect 2> /dev/null
+       git checkout -q -b new-bisect "$bisect_rev" || exit
        git branch -M new-bisect bisect
        git show-branch "$bisect_rev"
 }