From: Junio C Hamano Date: Wed, 27 Apr 2011 18:36:42 +0000 (-0700) Subject: Merge branch 'dm/stash-k-i-p' X-Git-Tag: v1.7.6-rc0~146 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/65bc83d704b82b613f1f61b4ad97412376ab4a69?ds=inline;hp=-c Merge branch 'dm/stash-k-i-p' * 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 --- 65bc83d704b82b613f1f61b4ad97412376ab4a69 diff --combined git-stash.sh index 07ac323590,fd66884090..0a9403653d --- 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 @@@ -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 @@@ -310,6 -311,16 +311,6 @@@ 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 a27d778624,bca2df1570..5c72540642 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@@ -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 '