3 # Copyright (c) 2007 Johannes E Schindelin
6 test_description
='Test git stash'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
13 test_expect_success
'usage on cmd and subcommand invalid option' '
14 test_expect_code 129 git stash --invalid-option 2>usage &&
15 grep "or: git stash" usage &&
17 test_expect_code 129 git stash push --invalid-option 2>usage &&
18 ! grep "or: git stash" usage
21 test_expect_success
'usage on main command -h emits a summary of subcommands' '
22 test_expect_code 129 git stash -h >usage &&
23 grep -F "usage: git stash list" usage &&
24 grep -F "or: git stash show" usage
27 test_expect_failure
'usage for subcommands should emit subcommand usage' '
28 test_expect_code 129 git stash push -h >usage &&
29 grep -F "usage: git stash [push" usage
35 sed -e 's/^index 0000000\.\.[0-9a-f]*/index 0000000..1234567/' \
36 -e 's/^index [0-9a-f]*\.\.[0-9a-f]*/index 1234567..89abcde/' \
37 -e 's/^index [0-9a-f]*,[0-9a-f]*\.\.[0-9a-f]*/index 1234567,7654321..89abcde/' \
38 "$i" >"$i.compare" ||
return 1
40 test_cmp
"$1.compare" "$2.compare" &&
41 rm -f "$1.compare" "$2.compare"
44 test_expect_success
'stash some dirty working directory' '
47 echo unrelated >other-file &&
50 git commit -m initial &&
56 git diff-files --quiet &&
57 git diff-index --cached --quiet HEAD
61 diff --git a/file b/file
62 index 0cfbf08..00750ed 100644
70 test_expect_success
'parents of stash' '
71 test $(git rev-parse stash^) = $(git rev-parse HEAD) &&
72 git diff stash^2..stash >output &&
73 diff_cmp expect output
76 test_expect_success
'applying bogus stash does nothing' '
77 test_must_fail git stash apply stash@{1} &&
82 test_expect_success
'apply does not need clean working directory' '
89 test_expect_success
'apply does not clobber working directory changes' '
92 test_must_fail git stash apply &&
97 test_expect_success
'apply stashed changes' '
100 git add other-file &&
102 git commit -m other-file &&
104 test 3 = $(cat file) &&
105 test 1 = $(git show :file) &&
106 test 1 = $(git show HEAD:file)
109 test_expect_success
'apply stashed changes (including index)' '
110 git reset --hard HEAD^ &&
111 echo 6 >other-file &&
112 git add other-file &&
114 git commit -m other-file &&
115 git stash apply --index &&
116 test 3 = $(cat file) &&
117 test 2 = $(git show :file) &&
118 test 1 = $(git show HEAD:file)
121 test_expect_success
'unstashing in a subdirectory' '
122 git reset --hard HEAD &&
130 test_expect_success
'stash drop complains of extra options' '
131 test_must_fail git stash drop --foo
134 test_expect_success
'drop top stash' '
136 git stash list >expected &&
140 git stash list >actual &&
141 test_cmp expected actual &&
143 test 3 = $(cat file) &&
144 test 1 = $(git show :file) &&
145 test 1 = $(git show HEAD:file)
148 test_expect_success
'drop middle stash' '
154 git stash drop stash@{1} &&
155 test 2 = $(git stash list | wc -l) &&
157 test 9 = $(cat file) &&
158 test 1 = $(git show :file) &&
159 test 1 = $(git show HEAD:file) &&
163 test 3 = $(cat file) &&
164 test 1 = $(git show :file) &&
165 test 1 = $(git show HEAD:file)
168 test_expect_success
'drop middle stash by index' '
175 test 2 = $(git stash list | wc -l) &&
177 test 9 = $(cat file) &&
178 test 1 = $(git show :file) &&
179 test 1 = $(git show HEAD:file) &&
183 test 3 = $(cat file) &&
184 test 1 = $(git show :file) &&
185 test 1 = $(git show HEAD:file)
188 test_expect_success
'stash pop' '
191 test 3 = $(cat file) &&
192 test 1 = $(git show :file) &&
193 test 1 = $(git show HEAD:file) &&
194 test 0 = $(git stash list | wc -l)
198 diff --git a/file2 b/file2
200 index 0000000..1fe912c
208 diff --git a/file b/file
209 index 257cc56..5716ca5 100644
218 diff --git a/file b/file
219 index 7601807..5716ca5 100644
225 diff --git a/file2 b/file2
227 index 0000000..1fe912c
234 test_expect_success
'stash branch' '
236 git commit file -m first &&
242 git commit file -m second &&
243 git stash branch stashbranch &&
244 test refs/heads/stashbranch = $(git symbolic-ref HEAD) &&
245 test $(git rev-parse HEAD) = $(git rev-parse main^) &&
246 git diff --cached >output &&
247 diff_cmp expect output &&
249 diff_cmp expect1 output &&
251 git commit -m alternate\ second &&
252 git diff main..stashbranch >output &&
253 diff_cmp output expect2 &&
254 test 0 = $(git stash list | wc -l)
257 test_expect_success
'apply -q is quiet' '
260 git stash apply -q >output.out 2>&1 &&
261 test_must_be_empty output.out
264 test_expect_success
'save -q is quiet' '
265 git stash save --quiet >output.out 2>&1 &&
266 test_must_be_empty output.out
269 test_expect_success
'pop -q works and is quiet' '
270 git stash pop -q >output.out 2>&1 &&
272 git show :file >actual &&
273 test_cmp expect actual &&
274 test_must_be_empty output.out
277 test_expect_success
'pop -q --index works and is quiet' '
280 git stash save --quiet &&
281 git stash pop -q --index >output.out 2>&1 &&
282 git diff-files file2 >file2.diff &&
283 test_must_be_empty file2.diff &&
284 test foo = "$(git show :file)" &&
285 test_must_be_empty output.out
288 test_expect_success
'drop -q is quiet' '
290 git stash drop -q >output.out 2>&1 &&
291 test_must_be_empty output.out
294 test_expect_success
'stash -k' '
299 test bar,bar4 = $(cat file),$(cat file2)
302 test_expect_success
'stash --no-keep-index' '
306 git stash --no-keep-index &&
307 test bar,bar2 = $(cat file),$(cat file2)
310 test_expect_success
'stash --staged' '
314 git stash --staged &&
315 test bar3,bar2 = $(cat file),$(cat file2) &&
318 test bar,bar4 = $(cat file),$(cat file2)
321 test_expect_success
'dont assume push with non-option args' '
322 test_must_fail git stash -q drop 2>err &&
323 test_i18ngrep -e "subcommand wasn'\''t specified; '\''push'\'' can'\''t be assumed due to unexpected token '\''drop'\''" err
326 test_expect_success
'stash --invalid-option' '
330 test_must_fail git stash --invalid-option &&
331 test_must_fail git stash save --invalid-option &&
332 test bar5,bar6 = $(cat file),$(cat file2)
335 test_expect_success
'stash an added file' '
339 git stash save "added file" &&
342 test new = "$(cat file3)"
345 test_expect_success
'stash --intent-to-add file' '
348 git add --intent-to-add file4 &&
349 test_when_finished "git rm -f file4" &&
350 test_must_fail git stash
353 test_expect_success
'stash rm then recreate' '
357 git stash save "rm then recreate" &&
358 test bar = "$(cat file)" &&
360 test bar7 = "$(cat file)"
363 test_expect_success
'stash rm and ignore' '
366 echo file >.gitignore &&
367 git stash save "rm and ignore" &&
368 test bar = "$(cat file)" &&
369 test file = "$(cat .gitignore)" &&
372 test file = "$(cat .gitignore)"
375 test_expect_success
'stash rm and ignore (stage .gitignore)' '
378 echo file >.gitignore &&
379 git add .gitignore &&
380 git stash save "rm and ignore (stage .gitignore)" &&
381 test bar = "$(cat file)" &&
382 ! test -r .gitignore &&
385 test file = "$(cat .gitignore)"
388 test_expect_success SYMLINKS
'stash file to symlink' '
392 git stash save "file to symlink" &&
394 test bar = "$(cat file)" &&
396 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
399 test_expect_success SYMLINKS
'stash file to symlink (stage rm)' '
403 git stash save "file to symlink (stage rm)" &&
405 test bar = "$(cat file)" &&
407 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
410 test_expect_success SYMLINKS
'stash file to symlink (full stage)' '
415 git stash save "file to symlink (full stage)" &&
417 test bar = "$(cat file)" &&
419 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
422 # This test creates a commit with a symlink used for the following tests
424 test_expect_success
'stash symlink to file' '
426 test_ln_s_add file filelink &&
427 git commit -m "Add symlink" &&
430 git stash save "symlink to file"
433 test_expect_success SYMLINKS
'this must have re-created the symlink' '
435 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
438 test_expect_success
'unstash must re-create the file' '
440 ! test -h filelink &&
441 test bar = "$(cat file)"
444 test_expect_success
'stash symlink to file (stage rm)' '
448 git stash save "symlink to file (stage rm)"
451 test_expect_success SYMLINKS
'this must have re-created the symlink' '
453 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
456 test_expect_success
'unstash must re-create the file' '
458 ! test -h filelink &&
459 test bar = "$(cat file)"
462 test_expect_success
'stash symlink to file (full stage)' '
467 git stash save "symlink to file (full stage)"
470 test_expect_success SYMLINKS
'this must have re-created the symlink' '
472 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
475 test_expect_success
'unstash must re-create the file' '
477 ! test -h filelink &&
478 test bar = "$(cat file)"
481 test_expect_failure
'stash directory to file' '
484 echo foo >dir/file &&
486 git commit -m "Add file in dir" &&
489 git stash save "directory to file" &&
491 test foo = "$(cat dir/file)" &&
492 test_must_fail git stash apply &&
493 test bar = "$(cat dir)" &&
494 git reset --soft HEAD^
497 test_expect_failure
'stash file to directory' '
501 echo foo >file/file &&
502 git stash save "file to directory" &&
504 test bar = "$(cat file)" &&
507 test foo = "$(cat file/file)"
510 test_expect_success
'giving too many ref arguments does not modify files' '
512 test_when_finished "git reset --hard HEAD" &&
517 test-tool chmtime =123456789 file2 &&
518 for type in apply pop "branch stash-branch"
520 test_must_fail git stash $type stash@{0} stash@{1} 2>err &&
521 test_i18ngrep "Too many revisions" err &&
522 test 123456789 = $(test-tool chmtime -g file2) || return 1
526 test_expect_success
'drop: too many arguments errors out (does nothing)' '
527 git stash list >expect &&
528 test_must_fail git stash drop stash@{0} stash@{1} 2>err &&
529 test_i18ngrep "Too many revisions" err &&
530 git stash list >actual &&
531 test_cmp expect actual
534 test_expect_success
'show: too many arguments errors out (does nothing)' '
535 test_must_fail git stash show stash@{0} stash@{1} 2>err 1>out &&
536 test_i18ngrep "Too many revisions" err &&
537 test_must_be_empty out
540 test_expect_success
'stash create - no changes' '
542 test_when_finished "git reset --hard HEAD" &&
544 git stash create >actual &&
545 test_must_be_empty actual
548 test_expect_success
'stash branch - no stashes on stack, stash-like argument' '
550 test_when_finished "git reset --hard HEAD" &&
553 STASH_ID=$(git stash create) &&
555 git stash branch stash-branch ${STASH_ID} &&
556 test_when_finished "git reset --hard HEAD && git checkout main &&
557 git branch -D stash-branch" &&
558 test $(git ls-files --modified | wc -l) -eq 1
561 test_expect_success
'stash branch - stashes on stack, stash-like argument' '
563 test_when_finished "git reset --hard HEAD" &&
567 test_when_finished "git stash drop" &&
569 STASH_ID=$(git stash create) &&
571 git stash branch stash-branch ${STASH_ID} &&
572 test_when_finished "git reset --hard HEAD && git checkout main &&
573 git branch -D stash-branch" &&
574 test $(git ls-files --modified | wc -l) -eq 1
577 test_expect_success
'stash branch complains with no arguments' '
578 test_must_fail git stash branch 2>err &&
579 test_i18ngrep "No branch name specified" err
582 test_expect_success
'stash show format defaults to --stat' '
584 test_when_finished "git reset --hard HEAD" &&
588 test_when_finished "git stash drop" &&
590 STASH_ID=$(git stash create) &&
592 cat >expected <<-EOF &&
594 1 file changed, 1 insertion(+)
596 git stash show ${STASH_ID} >actual &&
597 test_cmp expected actual
600 test_expect_success
'stash show - stashes on stack, stash-like argument' '
602 test_when_finished "git reset --hard HEAD" &&
606 test_when_finished "git stash drop" &&
608 STASH_ID=$(git stash create) &&
610 echo "1 0 file" >expected &&
611 git stash show --numstat ${STASH_ID} >actual &&
612 test_cmp expected actual
615 test_expect_success
'stash show -p - stashes on stack, stash-like argument' '
617 test_when_finished "git reset --hard HEAD" &&
621 test_when_finished "git stash drop" &&
623 STASH_ID=$(git stash create) &&
625 cat >expected <<-EOF &&
626 diff --git a/file b/file
627 index 7601807..935fbd3 100644
634 git stash show -p ${STASH_ID} >actual &&
635 diff_cmp expected actual
638 test_expect_success
'stash show - no stashes on stack, stash-like argument' '
640 test_when_finished "git reset --hard HEAD" &&
643 STASH_ID=$(git stash create) &&
645 echo "1 0 file" >expected &&
646 git stash show --numstat ${STASH_ID} >actual &&
647 test_cmp expected actual
650 test_expect_success
'stash show -p - no stashes on stack, stash-like argument' '
652 test_when_finished "git reset --hard HEAD" &&
655 STASH_ID=$(git stash create) &&
657 cat >expected <<-EOF &&
658 diff --git a/file b/file
659 index 7601807..71b52c4 100644
666 git stash show -p ${STASH_ID} >actual &&
667 diff_cmp expected actual
670 test_expect_success
'stash show --patience shows diff' '
673 STASH_ID=$(git stash create) &&
675 cat >expected <<-EOF &&
676 diff --git a/file b/file
677 index 7601807..71b52c4 100644
684 git stash show --patience ${STASH_ID} >actual &&
685 diff_cmp expected actual
688 test_expect_success
'drop: fail early if specified stash is not a stash ref' '
690 test_when_finished "git reset --hard HEAD && git stash clear" &&
696 test_must_fail git stash drop $(git rev-parse stash@{0}) &&
698 test bar = "$(cat file)" &&
699 git reset --hard HEAD
702 test_expect_success
'pop: fail early if specified stash is not a stash ref' '
704 test_when_finished "git reset --hard HEAD && git stash clear" &&
710 test_must_fail git stash pop $(git rev-parse stash@{0}) &&
712 test bar = "$(cat file)" &&
713 git reset --hard HEAD
716 test_expect_success
'ref with non-existent reflog' '
722 test_must_fail git rev-parse --quiet --verify does-not-exist &&
723 test_must_fail git stash drop does-not-exist &&
724 test_must_fail git stash drop does-not-exist@{0} &&
725 test_must_fail git stash pop does-not-exist &&
726 test_must_fail git stash pop does-not-exist@{0} &&
727 test_must_fail git stash apply does-not-exist &&
728 test_must_fail git stash apply does-not-exist@{0} &&
729 test_must_fail git stash show does-not-exist &&
730 test_must_fail git stash show does-not-exist@{0} &&
731 test_must_fail git stash branch tmp does-not-exist &&
732 test_must_fail git stash branch tmp does-not-exist@{0} &&
736 test_expect_success
'invalid ref of the form stash@{n}, n >= N' '
738 test_must_fail git stash drop stash@{0} &&
743 test_must_fail git stash drop stash@{1} &&
744 test_must_fail git stash pop stash@{1} &&
745 test_must_fail git stash apply stash@{1} &&
746 test_must_fail git stash show stash@{1} &&
747 test_must_fail git stash branch tmp stash@{1} &&
751 test_expect_success
'invalid ref of the form "n", n >= N' '
753 test_must_fail git stash drop 0 &&
758 test_must_fail git stash drop 1 &&
759 test_must_fail git stash pop 1 &&
760 test_must_fail git stash apply 1 &&
761 test_must_fail git stash show 1 &&
762 test_must_fail git stash branch tmp 1 &&
766 test_expect_success
'valid ref of the form "n", n < N' '
773 git stash branch tmp 0 &&
781 test_must_fail git stash drop
784 test_expect_success
'branch: do not drop the stash if the branch exists' '
788 git commit -m initial &&
791 test_must_fail git stash branch main stash@{0} &&
792 git rev-parse stash@{0} --
795 test_expect_success
'branch: should not drop the stash if the apply fails' '
797 git reset HEAD~1 --hard &&
800 git commit -m initial &&
804 test_when_finished "git checkout main" &&
805 test_must_fail git stash branch new_branch stash@{0} &&
806 git rev-parse stash@{0} --
809 test_expect_success
'apply: show same status as git status (relative to ./)' '
811 echo 1 >subdir/subfile1 &&
812 echo 2 >subdir/subfile2 &&
813 git add subdir/subfile1 &&
814 git commit -m subdir &&
819 git status >../expect &&
821 sane_unset GIT_MERGE_VERBOSITY &&
824 sed -e 1d >actual && # drop "Saved..."
825 test_cmp expect actual
829 diff --git a/HEAD b/HEAD
831 index 0000000..fe0cbee
838 test_expect_success
'stash where working directory contains "HEAD" file' '
841 echo file-not-a-ref >HEAD &&
845 git diff-files --quiet &&
846 git diff-index --cached --quiet HEAD &&
847 test "$(git rev-parse stash^)" = "$(git rev-parse HEAD)" &&
848 git diff stash^..stash >output &&
849 diff_cmp expect output
852 test_expect_success
'store called with invalid commit' '
853 test_must_fail git stash store foo
856 test_expect_success
'store updates stash ref and reflog' '
861 STASH_ID=$(git stash create) &&
863 test_path_is_missing bazzy &&
864 git stash store -m quuxery $STASH_ID &&
865 test $(git rev-parse stash) = $STASH_ID &&
866 git reflog --format=%H stash| grep $STASH_ID &&
871 test_expect_success
'handle stash specification with spaces' '
875 stamp=$(git log -g --format="%cd" -1 refs/stash) &&
879 git stash apply "stash@{$stamp}" &&
883 test_expect_success
'setup stash with index and worktree changes' '
888 echo working >file &&
892 test_expect_success
'stash list -p shows simple diff' '
893 cat >expect <<-EOF &&
896 diff --git a/file b/file
897 index 257cc56..d26b33d 100644
904 git stash list --format=%gd -p >actual &&
905 diff_cmp expect actual
908 test_expect_success
'stash list --cc shows combined diff' '
909 cat >expect <<-\EOF &&
913 index 257cc56,9015a7a..d26b33d
916 @@@ -1,1 -1,1 +1,1 @@@
921 git stash list --format=%gd -p --cc >actual &&
922 diff_cmp expect actual
925 test_expect_success
'stash is not confused by partial renames' '
930 test_path_is_file renamed &&
931 test_path_is_missing file
934 test_expect_success
'push -m shows right message' '
937 git stash push -m "test message" &&
938 echo "stash@{0}: On main: test message" >expect &&
939 git stash list -1 >actual &&
940 test_cmp expect actual
943 test_expect_success
'push -m also works without space' '
946 git stash push -m"unspaced test message" &&
947 echo "stash@{0}: On main: unspaced test message" >expect &&
948 git stash list -1 >actual &&
949 test_cmp expect actual
952 test_expect_success
'store -m foo shows right message' '
957 STASH_ID=$(git stash create) &&
958 git stash store -m "store m" $STASH_ID &&
959 echo "stash@{0}: store m" >expect &&
960 git stash list -1 >actual &&
961 test_cmp expect actual
964 test_expect_success
'store -mfoo shows right message' '
969 STASH_ID=$(git stash create) &&
970 git stash store -m"store mfoo" $STASH_ID &&
971 echo "stash@{0}: store mfoo" >expect &&
972 git stash list -1 >actual &&
973 test_cmp expect actual
976 test_expect_success
'store --message=foo shows right message' '
981 STASH_ID=$(git stash create) &&
982 git stash store --message="store message=foo" $STASH_ID &&
983 echo "stash@{0}: store message=foo" >expect &&
984 git stash list -1 >actual &&
985 test_cmp expect actual
988 test_expect_success
'store --message foo shows right message' '
993 STASH_ID=$(git stash create) &&
994 git stash store --message "store message foo" $STASH_ID &&
995 echo "stash@{0}: store message foo" >expect &&
996 git stash list -1 >actual &&
997 test_cmp expect actual
1000 test_expect_success
'push -mfoo uses right message' '
1003 git stash push -m"test mfoo" &&
1004 echo "stash@{0}: On main: test mfoo" >expect &&
1005 git stash list -1 >actual &&
1006 test_cmp expect actual
1009 test_expect_success
'push --message foo is synonym for -mfoo' '
1012 git stash push --message "test message foo" &&
1013 echo "stash@{0}: On main: test message foo" >expect &&
1014 git stash list -1 >actual &&
1015 test_cmp expect actual
1018 test_expect_success
'push --message=foo is synonym for -mfoo' '
1021 git stash push --message="test message=foo" &&
1022 echo "stash@{0}: On main: test message=foo" >expect &&
1023 git stash list -1 >actual &&
1024 test_cmp expect actual
1027 test_expect_success
'push -m shows right message' '
1030 git stash push -m "test m foo" &&
1031 echo "stash@{0}: On main: test m foo" >expect &&
1032 git stash list -1 >actual &&
1033 test_cmp expect actual
1036 test_expect_success
'create stores correct message' '
1039 STASH_ID=$(git stash create "create test message") &&
1040 echo "On main: create test message" >expect &&
1041 git show --pretty=%s -s ${STASH_ID} >actual &&
1042 test_cmp expect actual
1045 test_expect_success
'create with multiple arguments for the message' '
1048 STASH_ID=$(git stash create test untracked) &&
1049 echo "On main: test untracked" >expect &&
1050 git show --pretty=%s -s ${STASH_ID} >actual &&
1051 test_cmp expect actual
1054 test_expect_success
'create in a detached state' '
1055 test_when_finished "git checkout main" &&
1056 git checkout HEAD~1 &&
1059 STASH_ID=$(git stash create) &&
1060 HEAD_ID=$(git rev-parse --short HEAD) &&
1061 echo "WIP on (no branch): ${HEAD_ID} initial" >expect &&
1062 git show --pretty=%s -s ${STASH_ID} >actual &&
1063 test_cmp expect actual
1066 test_expect_success
'stash -- <pathspec> stashes and restores the file' '
1070 git stash push -- foo &&
1071 test_path_is_file bar &&
1072 test_path_is_missing foo &&
1074 test_path_is_file foo &&
1075 test_path_is_file bar
1078 test_expect_success
'stash -- <pathspec> stashes in subdirectory' '
1085 git stash push -- ../foo
1087 test_path_is_file bar &&
1088 test_path_is_missing foo &&
1090 test_path_is_file foo &&
1091 test_path_is_file bar
1094 test_expect_success
'stash with multiple pathspec arguments' '
1098 git add foo bar extra &&
1099 git stash push -- foo bar &&
1100 test_path_is_missing bar &&
1101 test_path_is_missing foo &&
1102 test_path_is_file extra &&
1104 test_path_is_file foo &&
1105 test_path_is_file bar &&
1106 test_path_is_file extra
1109 test_expect_success
'stash with file including $IFS character' '
1114 git stash push -- "foo b*" &&
1115 test_path_is_missing "foo bar" &&
1116 test_path_is_file foo &&
1117 test_path_is_file bar &&
1119 test_path_is_file "foo bar" &&
1120 test_path_is_file foo &&
1121 test_path_is_file bar
1124 test_expect_success
'stash with pathspec matching multiple paths' '
1125 echo original >file &&
1126 echo original >other-file &&
1127 git commit -m "two" file other-file &&
1128 echo modified >file &&
1129 echo modified >other-file &&
1130 git stash push -- "*file" &&
1131 echo original >expect &&
1132 test_cmp expect file &&
1133 test_cmp expect other-file &&
1135 echo modified >expect &&
1136 test_cmp expect file &&
1137 test_cmp expect other-file
1140 test_expect_success
'stash push -p with pathspec shows no changes only once' '
1143 git commit -m "tmp" &&
1144 git stash push -p foo >actual &&
1145 echo "No local changes to save" >expect &&
1146 git reset --hard HEAD~ &&
1147 test_cmp expect actual
1150 test_expect_success
'push <pathspec>: show no changes when there are none' '
1153 git commit -m "tmp" &&
1154 git stash push foo >actual &&
1155 echo "No local changes to save" >expect &&
1156 git reset --hard HEAD~ &&
1157 test_cmp expect actual
1160 test_expect_success
'push: <pathspec> not in the repository errors out' '
1162 test_must_fail git stash push untracked &&
1163 test_path_is_file untracked
1166 test_expect_success
'push: -q is quiet with changes' '
1169 git stash push -q >output 2>&1 &&
1170 test_must_be_empty output
1173 test_expect_success
'push: -q is quiet with no changes' '
1174 git stash push -q >output 2>&1 &&
1175 test_must_be_empty output
1178 test_expect_success
'push: -q is quiet even if there is no initial commit' '
1180 test_when_finished rm -rf foo_dir &&
1184 test_must_fail git stash push -q >output 2>&1 &&
1185 test_must_be_empty output
1189 test_expect_success
'untracked files are left in place when -u is not given' '
1193 git stash push file &&
1194 test_path_is_file untracked
1197 test_expect_success
'stash without verb with pathspec' '
1202 git stash -- "foo b*" &&
1203 test_path_is_missing "foo bar" &&
1204 test_path_is_file foo &&
1205 test_path_is_file bar &&
1207 test_path_is_file "foo bar" &&
1208 test_path_is_file foo &&
1209 test_path_is_file bar
1212 test_expect_success
'stash -k -- <pathspec> leaves unstaged files intact' '
1217 git commit -m "test" &&
1220 git stash -k -- foo &&
1221 test "",bar = $(cat foo),$(cat bar) &&
1223 test foo,bar = $(cat foo),$(cat bar)
1226 test_expect_success
'stash -- <subdir> leaves untracked files in subdir intact' '
1228 >subdir/untracked &&
1231 git add subdir/tracked* &&
1232 git stash -- subdir/ &&
1233 test_path_is_missing subdir/tracked1 &&
1234 test_path_is_missing subdir/tracked2 &&
1235 test_path_is_file subdir/untracked &&
1237 test_path_is_file subdir/tracked1 &&
1238 test_path_is_file subdir/tracked2 &&
1239 test_path_is_file subdir/untracked
1242 test_expect_success
'stash -- <subdir> works with binary files' '
1244 >subdir/untracked &&
1246 cp "$TEST_DIRECTORY"/test-binary-1.png subdir/tracked-binary &&
1247 git add subdir/tracked* &&
1248 git stash -- subdir/ &&
1249 test_path_is_missing subdir/tracked &&
1250 test_path_is_missing subdir/tracked-binary &&
1251 test_path_is_file subdir/untracked &&
1253 test_path_is_file subdir/tracked &&
1254 test_path_is_file subdir/tracked-binary &&
1255 test_path_is_file subdir/untracked
1258 test_expect_success
'stash with user.name and user.email set works' '
1259 test_config user.name "A U Thor" &&
1260 test_config user.email "a.u@thor" &&
1264 test_expect_success
'stash works when user.name and user.email are not set' '
1268 echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" >expect &&
1270 git show -s --format="%an <%ae>" refs/stash >actual &&
1271 test_cmp expect actual &&
1274 test_config user.useconfigonly true &&
1275 test_config stash.usebuiltin true &&
1277 sane_unset GIT_AUTHOR_NAME &&
1278 sane_unset GIT_AUTHOR_EMAIL &&
1279 sane_unset GIT_COMMITTER_NAME &&
1280 sane_unset GIT_COMMITTER_EMAIL &&
1281 test_unconfig user.email &&
1282 test_unconfig user.name &&
1283 test_must_fail git commit -m "should fail" &&
1284 echo "git stash <git@stash>" >expect &&
1287 git show -s --format="%an <%ae>" refs/stash >actual &&
1288 test_cmp expect actual
1292 test_expect_success
'stash --keep-index with file deleted in index does not resurrect it on disk' '
1293 test_commit to-remove to-remove &&
1295 git stash --keep-index &&
1296 test_path_is_missing to-remove
1299 test_expect_success
'stash apply should succeed with unmodified file' '
1302 git commit -m base &&
1304 # now stash a modification
1305 echo modified >file &&
1308 # make the file stat dirty
1315 test_expect_success
'stash handles skip-worktree entries nicely' '
1317 echo changed >A.t &&
1319 git update-index --skip-worktree A.t &&
1323 git rev-parse --verify refs/stash:A.t
1326 test_expect_success
'stash -c stash.useBuiltin=false warning ' '
1327 expected="stash.useBuiltin support has been removed" &&
1329 git -c stash.useBuiltin=false stash 2>err &&
1330 test_i18ngrep "$expected" err &&
1331 env GIT_TEST_STASH_USE_BUILTIN=false git stash 2>err &&
1332 test_i18ngrep "$expected" err &&
1334 git -c stash.useBuiltin=true stash 2>err &&
1335 test_must_be_empty err &&
1336 env GIT_TEST_STASH_USE_BUILTIN=true git stash 2>err &&
1337 test_must_be_empty err
1340 test_expect_success
'git stash succeeds despite directory/file change' '
1341 test_create_repo directory_file_switch_v1 &&
1343 cd directory_file_switch_v1 &&
1346 test_write_lines this file has some words >filler &&
1348 git commit -m filler &&
1352 echo contents >filler/file &&
1357 test_expect_success
'git stash can pop file -> directory saved changes' '
1358 test_create_repo directory_file_switch_v2 &&
1360 cd directory_file_switch_v2 &&
1363 test_write_lines this file has some words >filler &&
1365 git commit -m filler &&
1369 echo contents >filler/file &&
1370 cp filler/file expect &&
1371 git stash push --include-untracked &&
1372 git stash apply --index &&
1373 test_cmp expect filler/file
1377 test_expect_success
'git stash can pop directory -> file saved changes' '
1378 test_create_repo directory_file_switch_v3 &&
1380 cd directory_file_switch_v3 &&
1384 test_write_lines some words >filler/file1 &&
1385 test_write_lines and stuff >filler/file2 &&
1387 git commit -m filler &&
1389 git rm -rf filler &&
1390 echo contents >filler &&
1392 git stash push --include-untracked &&
1393 git stash apply --index &&
1394 test_cmp expect filler