]> Pileus Git - ~andy/git/blobdiff - git-bisect.sh
Revert "filter-branch: subdirectory filter needs --full-history"
[~andy/git] / git-bisect.sh
index c8be9f7e8a33db81d9dbbfcd943eaa341aee7595..b1800edaf713f972131431fcd26b5e7f64f089fc 100755 (executable)
@@ -62,23 +62,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"
@@ -99,6 +105,7 @@ bisect_start() {
        done
        orig_args=$(sq "$@")
        bad_seen=0
+       eval=''
        while [ $# -gt 0 ]; do
            arg="$1"
            case "$arg" in
@@ -116,13 +123,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
 }
@@ -153,12 +162,14 @@ bisect_state() {
                bisect_write "$state" "$rev" ;;
        2,bad|*,good|*,skip)
                shift
+               eval=''
                for rev in "$@"
                do
-                       rev=$(git rev-parse --verify "$rev^{commit}") ||
+                       sha=$(git rev-parse --verify "$rev^{commit}") ||
                                die "Bad rev input: $rev"
-                       bisect_write "$state" "$rev"
-               done ;;
+                       eval="$eval bisect_write '$state' '$sha'; "
+               done
+               eval "$eval" ;;
        *,bad)
                die "'git bisect bad' can take only one argument." ;;
        *)
@@ -209,18 +220,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.
@@ -289,14 +315,14 @@ bisect_next() {
        bisect_next_check good
 
        skip=$(git for-each-ref --format='%(objectname)' \
-               "refs/bisect/skip-*" | tr '[\012]' ' ') || exit
+               "refs/bisect/skip-*" | tr '\012' ' ') || exit
 
        BISECT_OPT=''
        test -n "$skip" && BISECT_OPT='--bisect-all'
 
        bad=$(git rev-parse --verify refs/bisect/bad) &&
        good=$(git for-each-ref --format='^%(objectname)' \
-               "refs/bisect/good-*" | tr '[\012]' ' ') &&
+               "refs/bisect/good-*" | tr '\012' ' ') &&
        eval="git rev-list --bisect-vars $BISECT_OPT $good $bad --" &&
        eval="$eval $(cat "$GIT_DIR/BISECT_NAMES")" &&
        eval=$(filter_skipped "$eval" "$skip") &&
@@ -318,8 +344,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"
 }
@@ -329,9 +355,9 @@ bisect_visualize() {
 
        if test $# = 0
        then
-               case "${DISPLAY+set}" in
+               case "${DISPLAY+set}${MSYSTEM+set}${SECURITYSESSIONID+set}" in
                '')     set git log ;;
-               set   set gitk ;;
+               set*)   set gitk ;;
                esac
        else
                case "$1" in