]> git.ipfire.org Git - thirdparty/git.git/blobdiff - git-bisect.sh
Test and fix normalize_path_copy()
[thirdparty/git.git] / git-bisect.sh
index 57168b0ae43b07ec3c412e0c5bc19307a0770d95..97ac600873ebd0dff6310071343403a41a867b8a 100755 (executable)
@@ -44,7 +44,7 @@ sq() {
 }
 
 bisect_autostart() {
-       test -f "$GIT_DIR/BISECT_NAMES" || {
+       test -s "$GIT_DIR/BISECT_START" || {
                echo >&2 'You need to start by "git bisect start"'
                if test -t 0
                then
@@ -63,42 +63,42 @@ bisect_autostart() {
 
 bisect_start() {
        #
-       # Verify HEAD. If we were bisecting before this, reset to the
-       # top-of-line master first!
+       # Verify 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.
+       # Check if we are bisecting.
        #
-       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 test -s "$GIT_DIR/BISECT_START"
+       then
+               # Reset to the rev from where we started.
                start_head=$(cat "$GIT_DIR/BISECT_START")
                git checkout "$start_head" || 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"
-               start_head="${head#refs/heads/}"
-               ;;
-       *)
-               die "Bad HEAD - strange symbolic ref"
-               ;;
-       esac
+       else
+               # Get rev from where we start.
+               case "$head" in
+               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"
+                       start_head="${head#refs/heads/}"
+                       ;;
+               *)
+                       die "Bad HEAD - strange symbolic ref"
+                       ;;
+               esac
+       fi
 
        #
-       # Get rid of any old bisect state
+       # Get rid of any old bisect state.
        #
-       bisect_clean_state
+       bisect_clean_state || exit
 
        #
        # Check for one bad and then some good revisions.
@@ -118,7 +118,7 @@ bisect_start() {
                break
                ;;
            *)
-               rev=$(git rev-parse --verify "$arg^{commit}" 2>/dev/null) || {
+               rev=$(git rev-parse -q --verify "$arg^{commit}") || {
                    test $has_double_dash -eq 1 &&
                        die "'$arg' does not appear to be a valid revision"
                    break
@@ -146,10 +146,10 @@ bisect_start() {
        #
        # Write new start state.
        #
-       sq "$@" >"$GIT_DIR/BISECT_NAMES" &&
        echo "$start_head" >"$GIT_DIR/BISECT_START" &&
+       sq "$@" >"$GIT_DIR/BISECT_NAMES" &&
        eval "$eval" &&
-       echo "git-bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG" || exit
+       echo "git bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG" || exit
        #
        # Check if we can proceed to the next bisect state.
        #
@@ -169,7 +169,7 @@ bisect_write() {
        esac
        git update-ref "refs/bisect/$tag" "$rev" || exit
        echo "# $state: $(git show-branch $rev)" >>"$GIT_DIR/BISECT_LOG"
-       test -n "$nolog" || echo "git-bisect $state $rev" >>"$GIT_DIR/BISECT_LOG"
+       test -n "$nolog" || echo "git bisect $state $rev" >>"$GIT_DIR/BISECT_LOG"
 }
 
 bisect_state() {
@@ -220,13 +220,14 @@ bisect_next_check() {
                if test -t 0
                then
                        printf >&2 'Are you sure [Y/n]? '
-                       case "$(read yesno)" in [Nn]*) exit 1 ;; esac
+                       read yesno
+                       case "$yesno" in [Nn]*) exit 1 ;; esac
                fi
                : bisect without good...
                ;;
        *)
                THEN=''
-               test -f "$GIT_DIR/BISECT_NAMES" || {
+               test -s "$GIT_DIR/BISECT_START" || {
                        echo >&2 'You need to start by "git bisect start".'
                        THEN='then '
                }
@@ -366,9 +367,7 @@ bisect_next() {
        exit_if_skipped_commits "$bisect_rev"
 
        echo "Bisecting: $bisect_nr revisions left to test after this"
-       git branch -D new-bisect 2> /dev/null
-       git checkout -q -b new-bisect "$bisect_rev" || exit
-       git branch -M new-bisect bisect
+       git checkout -q "$bisect_rev" || exit
        git show-branch "$bisect_rev"
 }
 
@@ -394,16 +393,12 @@ bisect_visualize() {
 }
 
 bisect_reset() {
-       test -f "$GIT_DIR/BISECT_NAMES" || {
+       test -s "$GIT_DIR/BISECT_START" || {
                echo "We are not bisecting."
                return
        }
        case "$#" in
-       0) if [ -s "$GIT_DIR/BISECT_START" ]; then
-              branch=`cat "$GIT_DIR/BISECT_START"`
-          else
-              branch=master
-          fi ;;
+       0) branch=$(cat "$GIT_DIR/BISECT_START") ;;
        1) git show-ref --verify --quiet -- "refs/heads/$1" ||
               die "$1 does not seem to be a valid branch"
           branch="$1" ;;
@@ -415,25 +410,30 @@ bisect_reset() {
 
 bisect_clean_state() {
        # There may be some refs packed during bisection.
-       git for-each-ref --format='%(refname) %(objectname)' refs/bisect/\* refs/heads/bisect |
+       git for-each-ref --format='%(refname) %(objectname)' refs/bisect/\* |
        while read ref hash
        do
-               git update-ref -d $ref $hash
+               git update-ref -d $ref $hash || exit
        done
-       rm -f "$GIT_DIR/BISECT_START"
-       rm -f "$GIT_DIR/BISECT_LOG"
-       rm -f "$GIT_DIR/BISECT_NAMES"
-       rm -f "$GIT_DIR/BISECT_RUN"
+       rm -f "$GIT_DIR/BISECT_LOG" &&
+       rm -f "$GIT_DIR/BISECT_NAMES" &&
+       rm -f "$GIT_DIR/BISECT_RUN" &&
        # Cleanup head-name if it got left by an old version of git-bisect
-       rm -f "$GIT_DIR/head-name"
+       rm -f "$GIT_DIR/head-name" &&
+
+       rm -f "$GIT_DIR/BISECT_START"
 }
 
 bisect_replay () {
        test -r "$1" || die "cannot read $1 for replaying"
        bisect_reset
-       while read bisect command rev
+       while read git bisect command rev
        do
-               test "$bisect" = "git-bisect" || continue
+               test "$git $bisect" = "git bisect" -o "$git" = "git-bisect" || continue
+               if test "$git" = "git-bisect"; then
+                       rev="$command"
+                       command="$bisect"
+               fi
                case "$command" in
                start)
                        cmd="bisect_start $rev"