Code

git-checkout.txt: clarify that <branch> applies when no path is given.
[git.git] / git-bisect.sh
index 4bcbaceb8bd6a5dc9021b2525f43ae5317a7d46a..b95dbbbbb243069f5e673869b3867cfa4151aff7 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
@@ -98,7 +98,7 @@ bisect_start() {
        #
        # Get rid of any old bisect state.
        #
-       bisect_clean_state
+       bisect_clean_state || exit
 
        #
        # Check for one bad and then some good revisions.
@@ -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 '
                }
@@ -262,62 +263,74 @@ filter_skipped() {
        _skip="$2"
 
        if [ -z "$_skip" ]; then
-               eval_rev_list "$_eval"
+               eval_rev_list "$_eval" | {
+                       while read line
+                       do
+                               echo "$line &&"
+                       done
+                       echo ':'
+               }
                return
        fi
 
        # Let's parse the output of:
        # "git rev-list --bisect-vars --bisect-all ..."
-       eval_rev_list "$_eval" | while read hash line
-       do
-               case "$VARS,$FOUND,$TRIED,$hash" in
-                       # We display some vars.
-                       1,*,*,*) echo "$hash $line" ;;
-
-                       # Split line.
-                       ,*,*,---*) ;;
-
-                       # We had nothing to search.
+       eval_rev_list "$_eval" | {
+               VARS= FOUND= TRIED=
+               while read hash line
+               do
+                       case "$VARS,$FOUND,$TRIED,$hash" in
+                       1,*,*,*)
+                               # "bisect_foo=bar" read from rev-list output.
+                               echo "$hash &&"
+                               ;;
+                       ,*,*,---*)
+                               # Separator
+                               ;;
                        ,,,bisect_rev*)
-                               echo "bisect_rev="
+                               # We had nothing to search.
+                               echo "bisect_rev= &&"
                                VARS=1
                                ;;
-
-                       # We did not find a good bisect rev.
-                       # This should happen only if the "bad"
-                       # commit is also a "skip" commit.
                        ,,*,bisect_rev*)
-                               echo "bisect_rev=$TRIED"
+                               # We did not find a good bisect rev.
+                               # This should happen only if the "bad"
+                               # commit is also a "skip" commit.
+                               echo "bisect_rev='$TRIED' &&"
                                VARS=1
                                ;;
-
-                       # We are searching.
                        ,,*,*)
+                               # We are searching.
                                TRIED="${TRIED:+$TRIED|}$hash"
                                case "$_skip" in
                                *$hash*) ;;
                                *)
-                                       echo "bisect_rev=$hash"
-                                       echo "bisect_tried=\"$TRIED\""
+                                       echo "bisect_rev=$hash &&"
+                                       echo "bisect_tried='$TRIED' &&"
                                        FOUND=1
                                        ;;
                                esac
                                ;;
-
-                       # We have already found a rev to be tested.
-                       ,1,*,bisect_rev*) VARS=1 ;;
-                       ,1,*,*) ;;
-
-                       # ???
-                       *) die "filter_skipped error " \
-                           "VARS: '$VARS' " \
-                           "FOUND: '$FOUND' " \
-                           "TRIED: '$TRIED' " \
-                           "hash: '$hash' " \
-                           "line: '$line'"
-                       ;;
-               esac
-       done
+                       ,1,*,bisect_rev*)
+                               # We have already found a rev to be tested.
+                               VARS=1
+                               ;;
+                       ,1,*,*)
+                               ;;
+                       *)
+                               # Unexpected input
+                               echo "die 'filter_skipped error'"
+                               die "filter_skipped error " \
+                                   "VARS: '$VARS' " \
+                                   "FOUND: '$FOUND' " \
+                                   "TRIED: '$TRIED' " \
+                                   "hash: '$hash' " \
+                                   "line: '$line'"
+                               ;;
+                       esac
+               done
+               echo ':'
+       }
 }
 
 exit_if_skipped_commits () {
@@ -392,16 +405,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" ;;
@@ -416,22 +425,27 @@ bisect_clean_state() {
        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"