Merge branch 'rr/rebase-stash-store'
authorJunio C Hamano <gitster@pobox.com>
Thu, 27 Jun 2013 21:29:41 +0000 (14:29 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 27 Jun 2013 21:29:41 +0000 (14:29 -0700)
Finishing touches for the "git rebase --autostash" feature
introduced earlier.

* rr/rebase-stash-store:
rebase: use 'git stash store' to simplify logic
stash: introduce 'git stash store'
stash: simplify option parser for create
stash doc: document short form -p in synopsis
stash doc: add a warning about using create

1  2 
git-rebase.sh
t/t3903-stash.sh
diff --combined git-rebase.sh
index 54015e3eaf5e091a387841d9a6e7cdd3085174f8,17be3922f8dd0263f89d0595414d13798114386a..81b0346a5da2386c94f72ac777f11887fef7fa70
@@@ -84,8 -84,6 +84,8 @@@ keep_empty
  test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
  
  read_basic_state () {
 +      test -f "$state_dir/head-name" &&
 +      test -f "$state_dir/onto" &&
        head_name=$(cat "$state_dir"/head-name) &&
        onto=$(cat "$state_dir"/onto) &&
        # We always write to orig-head, but interactive rebase used to write to
@@@ -155,11 -153,8 +155,8 @@@ finish_rebase () 
                then
                        echo "$(gettext 'Applied autostash.')"
                else
-                       ref_stash=refs/stash &&
-                       >>"$GIT_DIR/logs/$ref_stash" &&
-                       git update-ref -m "autostash" $ref_stash $stash_sha1 ||
-                       die "$(eval_gettext 'Cannot store $stash_sha1')"
+                       git stash store -m "autostash" -q $stash_sha1 ||
+                       die "$(eval_gettext "Cannot store \$stash_sha1")"
                        gettext 'Applying autostash resulted in conflicts.
  Your changes are safe in the stash.
  You can run "git stash pop" or "git stash drop" it at any time.
@@@ -436,7 -431,7 +433,7 @@@ the
                shift
                ;;
        esac
 -      upstream=`git rev-parse --verify "${upstream_name}^0"` ||
 +      upstream=$(peel_committish "${upstream_name}") ||
        die "$(eval_gettext "invalid upstream \$upstream_name")"
        upstream_arg="$upstream_name"
  else
@@@ -472,7 -467,7 +469,7 @@@ case "$onto_name" i
        fi
        ;;
  *)
 -      onto=$(git rev-parse --verify "${onto_name}^0") ||
 +      onto=$(peel_committish "$onto_name") ||
        die "$(eval_gettext "Does not point to a valid commit: \$onto_name")"
        ;;
  esac
@@@ -547,7 -542,6 +544,7 @@@ the
                # Lazily switch to the target branch if needed...
                test -z "$switch_to" || git checkout "$switch_to" --
                say "$(eval_gettext "Current branch \$branch_name is up to date.")"
 +              finish_rebase
                exit 0
        else
                say "$(eval_gettext "Current branch \$branch_name is up to date, rebase forced.")"
@@@ -580,7 -574,6 +577,7 @@@ if test "$mb" = "$orig_head
  then
        say "$(eval_gettext "Fast-forwarded \$branch_name to \$onto_name.")"
        move_to_original_branch
 +      finish_rebase
        exit 0
  fi
  
diff --combined t/t3903-stash.sh
index 634b2b74f49558781f612e3044d99cbc6fa3e657,75189ec8e8b1dc2d778e4f7ca15dd0ffe8c49bac..debda7a678277e1198ba6620210b66984caf03a2
@@@ -200,17 -200,17 +200,17 @@@ test_expect_success 'apply -q is quiet
        echo foo > file &&
        git stash &&
        git stash apply -q > output.out 2>&1 &&
 -      test ! -s output.out
 +      test_must_be_empty output.out
  '
  
  test_expect_success 'save -q is quiet' '
        git stash save --quiet > output.out 2>&1 &&
 -      test ! -s output.out
 +      test_must_be_empty output.out
  '
  
  test_expect_success 'pop -q is quiet' '
        git stash pop -q > output.out 2>&1 &&
 -      test ! -s output.out
 +      test_must_be_empty output.out
  '
  
  test_expect_success 'pop -q --index works and is quiet' '
        git stash save --quiet &&
        git stash pop -q --index > output.out 2>&1 &&
        test foo = "$(git show :file)" &&
 -      test ! -s output.out
 +      test_must_be_empty output.out
  '
  
  test_expect_success 'drop -q is quiet' '
        git stash &&
        git stash drop -q > output.out 2>&1 &&
 -      test ! -s output.out
 +      test_must_be_empty output.out
  '
  
  test_expect_success 'stash -k' '
@@@ -336,58 -336,41 +336,58 @@@ test_expect_success SYMLINKS 'stash fil
  
  # This test creates a commit with a symlink used for the following tests
  
 -test_expect_success SYMLINKS 'stash symlink to file' '
 +test_expect_success 'stash symlink to file' '
        git reset --hard &&
 -      ln -s file filelink &&
 -      git add filelink &&
 +      test_ln_s_add file filelink &&
        git commit -m "Add symlink" &&
        rm filelink &&
        cp file filelink &&
 -      git stash save "symlink to file" &&
 +      git stash save "symlink to file"
 +'
 +
 +test_expect_success SYMLINKS 'this must have re-created the symlink' '
        test -h filelink &&
 -      case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac &&
 +      case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
 +'
 +
 +test_expect_success 'unstash must re-create the file' '
        git stash apply &&
        ! test -h filelink &&
        test bar = "$(cat file)"
  '
  
 -test_expect_success SYMLINKS 'stash symlink to file (stage rm)' '
 +test_expect_success 'stash symlink to file (stage rm)' '
        git reset --hard &&
        git rm filelink &&
        cp file filelink &&
 -      git stash save "symlink to file (stage rm)" &&
 +      git stash save "symlink to file (stage rm)"
 +'
 +
 +test_expect_success SYMLINKS 'this must have re-created the symlink' '
        test -h filelink &&
 -      case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac &&
 +      case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
 +'
 +
 +test_expect_success 'unstash must re-create the file' '
        git stash apply &&
        ! test -h filelink &&
        test bar = "$(cat file)"
  '
  
 -test_expect_success SYMLINKS 'stash symlink to file (full stage)' '
 +test_expect_success 'stash symlink to file (full stage)' '
        git reset --hard &&
        rm filelink &&
        cp file filelink &&
        git add filelink &&
 -      git stash save "symlink to file (full stage)" &&
 +      git stash save "symlink to file (full stage)"
 +'
 +
 +test_expect_success SYMLINKS 'this must have re-created the symlink' '
        test -h filelink &&
 -      case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac &&
 +      case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
 +'
 +
 +test_expect_success 'unstash must re-create the file' '
        git stash apply &&
        ! test -h filelink &&
        test bar = "$(cat file)"
@@@ -654,4 -637,23 +654,23 @@@ test_expect_success 'stash where workin
        test_cmp output expect
  '
  
+ test_expect_success 'store called with invalid commit' '
+       test_must_fail git stash store foo
+ '
+ test_expect_success 'store updates stash ref and reflog' '
+       git stash clear &&
+       git reset --hard &&
+       echo quux >bazzy &&
+       git add bazzy &&
+       STASH_ID=$(git stash create) &&
+       git reset --hard &&
+       ! grep quux bazzy &&
+       git stash store -m quuxery $STASH_ID &&
+       test $(cat .git/refs/stash) = $STASH_ID &&
+       grep $STASH_ID .git/logs/refs/stash &&
+       git stash pop &&
+       grep quux bazzy
+ '
  test_done