Merge branch 'dm/stash-k-i-p' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 4 May 2011 21:57:49 +0000 (14:57 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 4 May 2011 21:57:49 +0000 (14:57 -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 fbd4bc152d7fb0ba81f0dd5c999ffba3c2276108,fd6688409062b05cf7d3139036a12c4d5f7cb882..81a59a250e0c69b0ead2819d91389146ac8504d7
@@@ -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
@@@ -344,7 -345,9 +345,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 5fcf52a0715138d98aa62a1e75be7005dc4faf3f,bca2df157023d046c417d4eb9cbaf3c517c464cf..0bd667f04b8e7c5a55fd0025bcf93e7f894ef394
@@@ -37,26 -37,14 +37,26 @@@ 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 '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 &&
@@@ -230,6 -218,14 +230,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 &&