Merge branch 'dm/stash-k-i-p'
authorJunio C Hamano <gitster@pobox.com>
Wed, 27 Apr 2011 18:36:42 +0000 (11:36 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 27 Apr 2011 18:36:42 +0000 (11:36 -0700)
* dm/stash-k-i-p:
stash: ensure --no-keep-index and --patch can be used in any order
stash: add two more tests for --no-keep-index

1  2 
git-stash.sh
t/t3903-stash.sh
diff --combined git-stash.sh
index 07ac3235904d7f0ac6c2e79af8b35f84c8f0874c,fd6688409062b05cf7d3139036a12c4d5f7cb882..0a9403653d7dbbb6927973dcfcc41bfd9a904e05
@@@ -136,11 -136,12 +136,12 @@@ save_stash () 
                        keep_index=t
                        ;;
                --no-keep-index)
-                       keep_index=
+                       keep_index=n
                        ;;
                -p|--patch)
                        patch_mode=t
-                       keep_index=t
+                       # only default to keep if we don't already have an override
+                       test -z "$keep_index" && keep_index=t
                        ;;
                -q|--quiet)
                        GIT_QUIET=t
        then
                git reset --hard ${GIT_QUIET:+-q}
  
-               if test -n "$keep_index" && test -n $i_tree
+               if test "$keep_index" = "t" && test -n $i_tree
                then
                        git read-tree --reset -u $i_tree
                fi
                git apply -R < "$TMP-patch" ||
                die "Cannot remove worktree changes"
  
-               if test -z "$keep_index"
+               if test "$keep_index" != "t"
                then
                        git reset
                fi
@@@ -264,7 -265,7 +265,7 @@@ parse_flags_and_rev(
        b_tree=
        i_tree=
  
 -      REV=$(git rev-parse --no-flags --symbolic "$@" 2>/dev/null)
 +      REV=$(git rev-parse --no-flags --symbolic "$@") || exit 1
  
        FLAGS=
        for opt
        IS_STASH_LIKE=t &&
        test "$ref_stash" = "$(git rev-parse --symbolic-full-name "${REV%@*}")" &&
        IS_STASH_REF=t
 -
 -      if test "${REV}" != "${REV%{*\}}"
 -      then
 -              # maintainers: it would be better if git rev-parse indicated
 -              # this condition with a non-zero status code but as of 1.7.2.1 it
 -              # it did not. So, we use non-empty stderr output as a proxy for the
 -              # condition of interest.
 -              test -z "$(git rev-parse "$REV" 2>&1 >/dev/null)" || die "$REV does not exist in the stash log"
 -      fi
 -
  }
  
  is_stash_like()
@@@ -334,7 -345,9 +335,7 @@@ apply_stash () 
  
        assert_stash_like "$@"
  
 -      git update-index -q --refresh &&
 -      git diff-files --quiet --ignore-submodules ||
 -              die 'Cannot apply to a dirty working tree, please stage your changes'
 +      git update-index -q --refresh || die 'unable to refresh index'
  
        # current index state
        c_tree=$(git write-tree) ||
diff --combined t/t3903-stash.sh
index a27d778624c1fe8ca39038f5913eb34a822b23a3,bca2df157023d046c417d4eb9cbaf3c517c464cf..5c725406422dcedb6c6d5e5d61cfc80f87d3595c
@@@ -37,32 -37,14 +37,32 @@@ test_expect_success 'parents of stash' 
        test_cmp output expect
  '
  
 -test_expect_success 'apply needs clean working directory' '
 -      echo 4 > other-file &&
 +test_expect_success 'applying bogus stash does nothing' '
 +      test_must_fail git stash apply stash@{1} &&
 +      echo 1 >expect &&
 +      test_cmp expect file
 +'
 +
 +test_expect_success 'apply does not need clean working directory' '
 +      echo 4 >other-file &&
        git add other-file &&
 -      echo 5 > other-file &&
 -      test_must_fail git stash apply
 +      echo 5 >other-file &&
 +      git stash apply &&
 +      echo 3 >expect &&
 +      test_cmp expect file
 +'
 +
 +test_expect_success 'apply does not clobber working directory changes' '
 +      git reset --hard &&
 +      echo 4 >file &&
 +      test_must_fail git stash apply &&
 +      echo 4 >expect &&
 +      test_cmp expect file
  '
  
  test_expect_success 'apply stashed changes' '
 +      git reset --hard &&
 +      echo 5 >other-file &&
        git add other-file &&
        test_tick &&
        git commit -m other-file &&
@@@ -236,6 -218,14 +236,14 @@@ test_expect_success 'stash -k' 
        test bar,bar4 = $(cat file),$(cat file2)
  '
  
+ test_expect_success 'stash --no-keep-index' '
+       echo bar33 > file &&
+       echo bar44 > file2 &&
+       git add file2 &&
+       git stash --no-keep-index &&
+       test bar,bar2 = $(cat file),$(cat file2)
+ '
  test_expect_success 'stash --invalid-option' '
        echo bar5 > file &&
        echo bar6 > file2 &&
@@@ -555,11 -545,11 +563,11 @@@ test_expect_success 'invalid ref of th
        echo bar6 > file2 &&
        git add file2 &&
        git stash &&
 -      test_must_fail git drop stash@{1} &&
 -      test_must_fail git pop stash@{1} &&
 -      test_must_fail git apply stash@{1} &&
 -      test_must_fail git show stash@{1} &&
 -      test_must_fail git branch tmp stash@{1} &&
 +      test_must_fail git stash drop stash@{1} &&
 +      test_must_fail git stash pop stash@{1} &&
 +      test_must_fail git stash apply stash@{1} &&
 +      test_must_fail git stash show stash@{1} &&
 +      test_must_fail git stash branch tmp stash@{1} &&
        git stash drop
  '