From: Junio C Hamano Date: Wed, 27 Apr 2011 18:36:42 +0000 (-0700) Subject: Merge branch 'jk/maint-stash-oob' X-Git-Tag: v1.7.6-rc0~150 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/fcbf164fcbf4110c7e2f96356d6707d56ba44ba4?hp=-c Merge branch 'jk/maint-stash-oob' * jk/maint-stash-oob: stash: fix false positive in the invalid ref test. stash: fix accidental apply of non-existent stashes Conflicts: t/t3903-stash.sh --- fcbf164fcbf4110c7e2f96356d6707d56ba44ba4 diff --combined git-stash.sh index fbd4bc152d,4f26deacca..07ac323590 --- a/git-stash.sh +++ b/git-stash.sh @@@ -12,14 -12,12 +12,14 @@@ USAGE="list [ SUBDIRECTORY_OK=Yes OPTIONS_SPEC= +START_DIR=`pwd` . git-sh-setup require_work_tree cd_to_toplevel TMP="$GIT_DIR/.git-stash.$$" -trap 'rm -f "$TMP-*"' 0 +TMPindex=${GIT_INDEX_FILE-"$GIT_DIR/index"}.stash.$$ +trap 'rm -f "$TMP-"* "$TMPindex"' 0 ref_stash=refs/stash @@@ -83,12 -81,14 +83,12 @@@ create_stash () # state of the working tree w_tree=$( ( - rm -f "$TMP-index" && - cp -p ${GIT_INDEX_FILE-"$GIT_DIR/index"} "$TMP-index" && - GIT_INDEX_FILE="$TMP-index" && + git read-tree --index-output="$TMPindex" -m $i_tree && + GIT_INDEX_FILE="$TMPindex" && export GIT_INDEX_FILE && - git read-tree -m $i_tree && git diff --name-only -z HEAD | git update-index -z --add --remove --stdin && git write-tree && - rm -f "$TMP-index" + rm -f "$TMPindex" ) ) || die "Cannot save the current worktree state" @@@ -264,7 -264,7 +264,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,16 -310,6 +310,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() @@@ -344,7 -334,9 +334,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) || @@@ -392,7 -384,7 +382,7 @@@ then squelch='>/dev/null 2>&1' fi - eval "git status $squelch" || : + (cd "$START_DIR" && eval "git status $squelch") || : else # Merge conflict; keep the exit status from merge-recursive status=$? diff --combined t/t3903-stash.sh index 5fcf52a071,3c91f48b20..a27d778624 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@@ -37,26 -37,20 +37,32 @@@ test_expect_success 'parents of stash' test_cmp output expect ' + 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 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 && @@@ -549,11 -543,11 +555,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 ' @@@ -568,23 -562,4 +574,23 @@@ test_expect_success 'stash branch shoul git rev-parse stash@{0} -- ' +test_expect_success 'stash apply shows status same as git status (relative to current directory)' ' + git stash clear && + echo 1 >subdir/subfile1 && + echo 2 >subdir/subfile2 && + git add subdir/subfile1 && + git commit -m subdir && + ( + cd subdir && + echo x >subfile1 && + echo x >../file && + git status >../expect && + git stash && + sane_unset GIT_MERGE_VERBOSITY && + git stash apply + ) | + sed -e 1,2d >actual && # drop "Saved..." and "HEAD is now..." + test_cmp expect actual +' + test_done