From: Junio C Hamano Date: Wed, 4 May 2011 21:57:49 +0000 (-0700) Subject: Merge branch 'dm/stash-k-i-p' into maint X-Git-Tag: v1.7.5.1~5 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/e9f1878da7be816042c915cdf0542f9325c36209?ds=inline;hp=-c Merge branch 'dm/stash-k-i-p' into maint * 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 --- e9f1878da7be816042c915cdf0542f9325c36209 diff --combined git-stash.sh index fbd4bc152d,fd66884090..81a59a250e --- a/git-stash.sh +++ b/git-stash.sh @@@ -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 @@@ -185,7 -186,7 +186,7 @@@ 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 @@@ -193,7 -194,7 +194,7 @@@ 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 5fcf52a071,bca2df1570..0bd667f04b --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@@ -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 &&