Code

Merge branch 'mf/curl-select-fdset' into maint
[git.git] / t / t3903-stash.sh
index 903a122efe0c54cb44eb6c3e7ed04bdbab81439d..fcdb18217a777f5dbb77b0071af7159c6985656d 100755 (executable)
@@ -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 &&
@@ -157,7 +175,7 @@ EOF
 
 test_expect_success 'stash branch' '
        echo foo > file &&
-       git commit file -m first
+       git commit file -m first &&
        echo bar > file &&
        echo bar2 > file2 &&
        git add file2 &&
@@ -218,6 +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 &&
@@ -255,7 +281,7 @@ test_expect_success 'stash rm and ignore' '
        echo file >.gitignore &&
        git stash save "rm and ignore" &&
        test bar = "$(cat file)" &&
-       test file = "$(cat .gitignore)"
+       test file = "$(cat .gitignore)" &&
        git stash apply &&
        ! test -r file &&
        test file = "$(cat .gitignore)"
@@ -268,7 +294,7 @@ test_expect_success 'stash rm and ignore (stage .gitignore)' '
        git add .gitignore &&
        git stash save "rm and ignore (stage .gitignore)" &&
        test bar = "$(cat file)" &&
-       ! test -r .gitignore
+       ! test -r .gitignore &&
        git stash apply &&
        ! test -r file &&
        test file = "$(cat .gitignore)"
@@ -510,13 +536,13 @@ test_expect_success 'stash pop - fail early if specified stash is not a stash re
        git reset --hard HEAD
 '
 
-test_expect_success 'ref with non-existant reflog' '
+test_expect_success 'ref with non-existent reflog' '
        git stash clear &&
        echo bar5 > file &&
        echo bar6 > file2 &&
        git add file2 &&
        git stash &&
-       ! "git rev-parse --quiet --verify does-not-exist" &&
+       test_must_fail git rev-parse --quiet --verify does-not-exist &&
        test_must_fail git stash drop does-not-exist &&
        test_must_fail git stash drop does-not-exist@{0} &&
        test_must_fail git stash pop does-not-exist &&
@@ -537,11 +563,11 @@ test_expect_success 'invalid ref of the form stash@{n}, n >= N' '
        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
 '
 
@@ -556,4 +582,23 @@ test_expect_success 'stash branch should not drop the stash if the branch exists
        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