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
'stash --staged with binary file' '
324 git stash --staged &&
326 printf "\0" >expect &&
330 test_expect_success
'dont assume push with non-option args' '
331 test_must_fail git stash -q drop 2>err &&
332 test_i18ngrep -e "subcommand wasn'\''t specified; '\''push'\'' can'\''t be assumed due to unexpected token '\''drop'\''" err
335 test_expect_success
'stash --invalid-option' '
339 test_must_fail git stash --invalid-option &&
340 test_must_fail git stash save --invalid-option &&
341 test bar5,bar6 = $(cat file),$(cat file2)
344 test_expect_success
'stash an added file' '
348 git stash save "added file" &&
351 test new = "$(cat file3)"
354 test_expect_success
'stash --intent-to-add file' '
357 git add --intent-to-add file4 &&
358 test_when_finished "git rm -f file4" &&
359 test_must_fail git stash
362 test_expect_success
'stash rm then recreate' '
366 git stash save "rm then recreate" &&
367 test bar = "$(cat file)" &&
369 test bar7 = "$(cat file)"
372 test_expect_success
'stash rm and ignore' '
375 echo file >.gitignore &&
376 git stash save "rm and ignore" &&
377 test bar = "$(cat file)" &&
378 test file = "$(cat .gitignore)" &&
381 test file = "$(cat .gitignore)"
384 test_expect_success
'stash rm and ignore (stage .gitignore)' '
387 echo file >.gitignore &&
388 git add .gitignore &&
389 git stash save "rm and ignore (stage .gitignore)" &&
390 test bar = "$(cat file)" &&
391 ! test -r .gitignore &&
394 test file = "$(cat .gitignore)"
397 test_expect_success SYMLINKS
'stash file to symlink' '
401 git stash save "file to symlink" &&
403 test bar = "$(cat file)" &&
405 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
408 test_expect_success SYMLINKS
'stash file to symlink (stage rm)' '
412 git stash save "file to symlink (stage rm)" &&
414 test bar = "$(cat file)" &&
416 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
419 test_expect_success SYMLINKS
'stash file to symlink (full stage)' '
424 git stash save "file to symlink (full stage)" &&
426 test bar = "$(cat file)" &&
428 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
431 # This test creates a commit with a symlink used for the following tests
433 test_expect_success
'stash symlink to file' '
435 test_ln_s_add file filelink &&
436 git commit -m "Add symlink" &&
439 git stash save "symlink to file"
442 test_expect_success SYMLINKS
'this must have re-created the symlink' '
444 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
447 test_expect_success
'unstash must re-create the file' '
449 ! test -h filelink &&
450 test bar = "$(cat file)"
453 test_expect_success
'stash symlink to file (stage rm)' '
457 git stash save "symlink to file (stage rm)"
460 test_expect_success SYMLINKS
'this must have re-created the symlink' '
462 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
465 test_expect_success
'unstash must re-create the file' '
467 ! test -h filelink &&
468 test bar = "$(cat file)"
471 test_expect_success
'stash symlink to file (full stage)' '
476 git stash save "symlink to file (full stage)"
479 test_expect_success SYMLINKS
'this must have re-created the symlink' '
481 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
484 test_expect_success
'unstash must re-create the file' '
486 ! test -h filelink &&
487 test bar = "$(cat file)"
490 test_expect_failure
'stash directory to file' '
493 echo foo >dir/file &&
495 git commit -m "Add file in dir" &&
498 git stash save "directory to file" &&
500 test foo = "$(cat dir/file)" &&
501 test_must_fail git stash apply &&
502 test bar = "$(cat dir)" &&
503 git reset --soft HEAD^
506 test_expect_failure
'stash file to directory' '
510 echo foo >file/file &&
511 git stash save "file to directory" &&
513 test bar = "$(cat file)" &&
516 test foo = "$(cat file/file)"
519 test_expect_success
'giving too many ref arguments does not modify files' '
521 test_when_finished "git reset --hard HEAD" &&
526 test-tool chmtime =123456789 file2 &&
527 for type in apply pop "branch stash-branch"
529 test_must_fail git stash $type stash@{0} stash@{1} 2>err &&
530 test_i18ngrep "Too many revisions" err &&
531 test 123456789 = $(test-tool chmtime -g file2) || return 1
535 test_expect_success
'drop: too many arguments errors out (does nothing)' '
536 git stash list >expect &&
537 test_must_fail git stash drop stash@{0} stash@{1} 2>err &&
538 test_i18ngrep "Too many revisions" err &&
539 git stash list >actual &&
540 test_cmp expect actual
543 test_expect_success
'show: too many arguments errors out (does nothing)' '
544 test_must_fail git stash show stash@{0} stash@{1} 2>err 1>out &&
545 test_i18ngrep "Too many revisions" err &&
546 test_must_be_empty out
549 test_expect_success
'stash create - no changes' '
551 test_when_finished "git reset --hard HEAD" &&
553 git stash create >actual &&
554 test_must_be_empty actual
557 test_expect_success
'stash branch - no stashes on stack, stash-like argument' '
559 test_when_finished "git reset --hard HEAD" &&
562 STASH_ID=$(git stash create) &&
564 git stash branch stash-branch ${STASH_ID} &&
565 test_when_finished "git reset --hard HEAD && git checkout main &&
566 git branch -D stash-branch" &&
567 test $(git ls-files --modified | wc -l) -eq 1
570 test_expect_success
'stash branch - stashes on stack, stash-like argument' '
572 test_when_finished "git reset --hard HEAD" &&
576 test_when_finished "git stash drop" &&
578 STASH_ID=$(git stash create) &&
580 git stash branch stash-branch ${STASH_ID} &&
581 test_when_finished "git reset --hard HEAD && git checkout main &&
582 git branch -D stash-branch" &&
583 test $(git ls-files --modified | wc -l) -eq 1
586 test_expect_success
'stash branch complains with no arguments' '
587 test_must_fail git stash branch 2>err &&
588 test_i18ngrep "No branch name specified" err
591 test_expect_success
'stash show format defaults to --stat' '
593 test_when_finished "git reset --hard HEAD" &&
597 test_when_finished "git stash drop" &&
599 STASH_ID=$(git stash create) &&
601 cat >expected <<-EOF &&
603 1 file changed, 1 insertion(+)
605 git stash show ${STASH_ID} >actual &&
606 test_cmp expected actual
609 test_expect_success
'stash show - stashes on stack, stash-like argument' '
611 test_when_finished "git reset --hard HEAD" &&
615 test_when_finished "git stash drop" &&
617 STASH_ID=$(git stash create) &&
619 echo "1 0 file" >expected &&
620 git stash show --numstat ${STASH_ID} >actual &&
621 test_cmp expected actual
624 test_expect_success
'stash show -p - stashes on stack, stash-like argument' '
626 test_when_finished "git reset --hard HEAD" &&
630 test_when_finished "git stash drop" &&
632 STASH_ID=$(git stash create) &&
634 cat >expected <<-EOF &&
635 diff --git a/file b/file
636 index 7601807..935fbd3 100644
643 git stash show -p ${STASH_ID} >actual &&
644 diff_cmp expected actual
647 test_expect_success
'stash show - no stashes on stack, stash-like argument' '
649 test_when_finished "git reset --hard HEAD" &&
652 STASH_ID=$(git stash create) &&
654 echo "1 0 file" >expected &&
655 git stash show --numstat ${STASH_ID} >actual &&
656 test_cmp expected actual
659 test_expect_success
'stash show -p - no stashes on stack, stash-like argument' '
661 test_when_finished "git reset --hard HEAD" &&
664 STASH_ID=$(git stash create) &&
666 cat >expected <<-EOF &&
667 diff --git a/file b/file
668 index 7601807..71b52c4 100644
675 git stash show -p ${STASH_ID} >actual &&
676 diff_cmp expected actual
679 test_expect_success
'stash show --patience shows diff' '
682 STASH_ID=$(git stash create) &&
684 cat >expected <<-EOF &&
685 diff --git a/file b/file
686 index 7601807..71b52c4 100644
693 git stash show --patience ${STASH_ID} >actual &&
694 diff_cmp expected actual
697 test_expect_success
'drop: fail early if specified stash is not a stash ref' '
699 test_when_finished "git reset --hard HEAD && git stash clear" &&
705 test_must_fail git stash drop $(git rev-parse stash@{0}) &&
707 test bar = "$(cat file)" &&
708 git reset --hard HEAD
711 test_expect_success
'pop: fail early if specified stash is not a stash ref' '
713 test_when_finished "git reset --hard HEAD && git stash clear" &&
719 test_must_fail git stash pop $(git rev-parse stash@{0}) &&
721 test bar = "$(cat file)" &&
722 git reset --hard HEAD
725 test_expect_success
'ref with non-existent reflog' '
731 test_must_fail git rev-parse --quiet --verify does-not-exist &&
732 test_must_fail git stash drop does-not-exist &&
733 test_must_fail git stash drop does-not-exist@{0} &&
734 test_must_fail git stash pop does-not-exist &&
735 test_must_fail git stash pop does-not-exist@{0} &&
736 test_must_fail git stash apply does-not-exist &&
737 test_must_fail git stash apply does-not-exist@{0} &&
738 test_must_fail git stash show does-not-exist &&
739 test_must_fail git stash show does-not-exist@{0} &&
740 test_must_fail git stash branch tmp does-not-exist &&
741 test_must_fail git stash branch tmp does-not-exist@{0} &&
745 test_expect_success
'invalid ref of the form stash@{n}, n >= N' '
747 test_must_fail git stash drop stash@{0} &&
752 test_must_fail git stash drop stash@{1} &&
753 test_must_fail git stash pop stash@{1} &&
754 test_must_fail git stash apply stash@{1} &&
755 test_must_fail git stash show stash@{1} &&
756 test_must_fail git stash branch tmp stash@{1} &&
760 test_expect_success
'invalid ref of the form "n", n >= N' '
762 test_must_fail git stash drop 0 &&
767 test_must_fail git stash drop 1 &&
768 test_must_fail git stash pop 1 &&
769 test_must_fail git stash apply 1 &&
770 test_must_fail git stash show 1 &&
771 test_must_fail git stash branch tmp 1 &&
775 test_expect_success
'valid ref of the form "n", n < N' '
782 git stash branch tmp 0 &&
790 test_must_fail git stash drop
793 test_expect_success
'branch: do not drop the stash if the branch exists' '
797 git commit -m initial &&
800 test_must_fail git stash branch main stash@{0} &&
801 git rev-parse stash@{0} --
804 test_expect_success
'branch: should not drop the stash if the apply fails' '
806 git reset HEAD~1 --hard &&
809 git commit -m initial &&
813 test_when_finished "git checkout main" &&
814 test_must_fail git stash branch new_branch stash@{0} &&
815 git rev-parse stash@{0} --
818 test_expect_success
'apply: show same status as git status (relative to ./)' '
820 echo 1 >subdir/subfile1 &&
821 echo 2 >subdir/subfile2 &&
822 git add subdir/subfile1 &&
823 git commit -m subdir &&
828 git status >../expect &&
830 sane_unset GIT_MERGE_VERBOSITY &&
833 sed -e 1d >actual && # drop "Saved..."
834 test_cmp expect actual
838 diff --git a/HEAD b/HEAD
840 index 0000000..fe0cbee
847 test_expect_success
'stash where working directory contains "HEAD" file' '
850 echo file-not-a-ref >HEAD &&
854 git diff-files --quiet &&
855 git diff-index --cached --quiet HEAD &&
856 test "$(git rev-parse stash^)" = "$(git rev-parse HEAD)" &&
857 git diff stash^..stash >output &&
858 diff_cmp expect output
861 test_expect_success
'store called with invalid commit' '
862 test_must_fail git stash store foo
865 test_expect_success
'store updates stash ref and reflog' '
870 STASH_ID=$(git stash create) &&
872 test_path_is_missing bazzy &&
873 git stash store -m quuxery $STASH_ID &&
874 test $(git rev-parse stash) = $STASH_ID &&
875 git reflog --format=%H stash| grep $STASH_ID &&
880 test_expect_success
'handle stash specification with spaces' '
884 stamp=$(git log -g --format="%cd" -1 refs/stash) &&
888 git stash apply "stash@{$stamp}" &&
892 test_expect_success
'setup stash with index and worktree changes' '
897 echo working >file &&
901 test_expect_success
'stash list -p shows simple diff' '
902 cat >expect <<-EOF &&
905 diff --git a/file b/file
906 index 257cc56..d26b33d 100644
913 git stash list --format=%gd -p >actual &&
914 diff_cmp expect actual
917 test_expect_success
'stash list --cc shows combined diff' '
918 cat >expect <<-\EOF &&
922 index 257cc56,9015a7a..d26b33d
925 @@@ -1,1 -1,1 +1,1 @@@
930 git stash list --format=%gd -p --cc >actual &&
931 diff_cmp expect actual
934 test_expect_success
'stash is not confused by partial renames' '
939 test_path_is_file renamed &&
940 test_path_is_missing file
943 test_expect_success
'push -m shows right message' '
946 git stash push -m "test message" &&
947 echo "stash@{0}: On main: test message" >expect &&
948 git stash list -1 >actual &&
949 test_cmp expect actual
952 test_expect_success
'push -m also works without space' '
955 git stash push -m"unspaced test message" &&
956 echo "stash@{0}: On main: unspaced test message" >expect &&
957 git stash list -1 >actual &&
958 test_cmp expect actual
961 test_expect_success
'store -m foo shows right message' '
966 STASH_ID=$(git stash create) &&
967 git stash store -m "store m" $STASH_ID &&
968 echo "stash@{0}: store m" >expect &&
969 git stash list -1 >actual &&
970 test_cmp expect actual
973 test_expect_success
'store -mfoo shows right message' '
978 STASH_ID=$(git stash create) &&
979 git stash store -m"store mfoo" $STASH_ID &&
980 echo "stash@{0}: store mfoo" >expect &&
981 git stash list -1 >actual &&
982 test_cmp expect actual
985 test_expect_success
'store --message=foo shows right message' '
990 STASH_ID=$(git stash create) &&
991 git stash store --message="store message=foo" $STASH_ID &&
992 echo "stash@{0}: store message=foo" >expect &&
993 git stash list -1 >actual &&
994 test_cmp expect actual
997 test_expect_success
'store --message foo shows right message' '
1002 STASH_ID=$(git stash create) &&
1003 git stash store --message "store message foo" $STASH_ID &&
1004 echo "stash@{0}: store message foo" >expect &&
1005 git stash list -1 >actual &&
1006 test_cmp expect actual
1009 test_expect_success
'push -mfoo uses right message' '
1012 git stash push -m"test mfoo" &&
1013 echo "stash@{0}: On main: test mfoo" >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 --message=foo is synonym for -mfoo' '
1030 git stash push --message="test message=foo" &&
1031 echo "stash@{0}: On main: test message=foo" >expect &&
1032 git stash list -1 >actual &&
1033 test_cmp expect actual
1036 test_expect_success
'push -m shows right message' '
1039 git stash push -m "test m foo" &&
1040 echo "stash@{0}: On main: test m foo" >expect &&
1041 git stash list -1 >actual &&
1042 test_cmp expect actual
1045 test_expect_success
'create stores correct message' '
1048 STASH_ID=$(git stash create "create test message") &&
1049 echo "On main: create test message" >expect &&
1050 git show --pretty=%s -s ${STASH_ID} >actual &&
1051 test_cmp expect actual
1054 test_expect_success
'create with multiple arguments for the message' '
1057 STASH_ID=$(git stash create test untracked) &&
1058 echo "On main: test untracked" >expect &&
1059 git show --pretty=%s -s ${STASH_ID} >actual &&
1060 test_cmp expect actual
1063 test_expect_success
'create in a detached state' '
1064 test_when_finished "git checkout main" &&
1065 git checkout HEAD~1 &&
1068 STASH_ID=$(git stash create) &&
1069 HEAD_ID=$(git rev-parse --short HEAD) &&
1070 echo "WIP on (no branch): ${HEAD_ID} initial" >expect &&
1071 git show --pretty=%s -s ${STASH_ID} >actual &&
1072 test_cmp expect actual
1075 test_expect_success
'stash -- <pathspec> stashes and restores the file' '
1079 git stash push -- foo &&
1080 test_path_is_file bar &&
1081 test_path_is_missing foo &&
1083 test_path_is_file foo &&
1084 test_path_is_file bar
1087 test_expect_success
'stash -- <pathspec> stashes in subdirectory' '
1094 git stash push -- ../foo
1096 test_path_is_file bar &&
1097 test_path_is_missing foo &&
1099 test_path_is_file foo &&
1100 test_path_is_file bar
1103 test_expect_success
'stash with multiple pathspec arguments' '
1107 git add foo bar extra &&
1108 git stash push -- foo bar &&
1109 test_path_is_missing bar &&
1110 test_path_is_missing foo &&
1111 test_path_is_file extra &&
1113 test_path_is_file foo &&
1114 test_path_is_file bar &&
1115 test_path_is_file extra
1118 test_expect_success
'stash with file including $IFS character' '
1123 git stash push -- "foo b*" &&
1124 test_path_is_missing "foo bar" &&
1125 test_path_is_file foo &&
1126 test_path_is_file bar &&
1128 test_path_is_file "foo bar" &&
1129 test_path_is_file foo &&
1130 test_path_is_file bar
1133 test_expect_success
'stash with pathspec matching multiple paths' '
1134 echo original >file &&
1135 echo original >other-file &&
1136 git commit -m "two" file other-file &&
1137 echo modified >file &&
1138 echo modified >other-file &&
1139 git stash push -- "*file" &&
1140 echo original >expect &&
1141 test_cmp expect file &&
1142 test_cmp expect other-file &&
1144 echo modified >expect &&
1145 test_cmp expect file &&
1146 test_cmp expect other-file
1149 test_expect_success
'stash push -p with pathspec shows no changes only once' '
1152 git commit -m "tmp" &&
1153 git stash push -p foo >actual &&
1154 echo "No local changes to save" >expect &&
1155 git reset --hard HEAD~ &&
1156 test_cmp expect actual
1159 test_expect_success
'push <pathspec>: show no changes when there are none' '
1162 git commit -m "tmp" &&
1163 git stash push foo >actual &&
1164 echo "No local changes to save" >expect &&
1165 git reset --hard HEAD~ &&
1166 test_cmp expect actual
1169 test_expect_success
'push: <pathspec> not in the repository errors out' '
1171 test_must_fail git stash push untracked &&
1172 test_path_is_file untracked
1175 test_expect_success
'push: -q is quiet with changes' '
1178 git stash push -q >output 2>&1 &&
1179 test_must_be_empty output
1182 test_expect_success
'push: -q is quiet with no changes' '
1183 git stash push -q >output 2>&1 &&
1184 test_must_be_empty output
1187 test_expect_success
'push: -q is quiet even if there is no initial commit' '
1189 test_when_finished rm -rf foo_dir &&
1193 test_must_fail git stash push -q >output 2>&1 &&
1194 test_must_be_empty output
1198 test_expect_success
'untracked files are left in place when -u is not given' '
1202 git stash push file &&
1203 test_path_is_file untracked
1206 test_expect_success
'stash without verb with pathspec' '
1211 git stash -- "foo b*" &&
1212 test_path_is_missing "foo bar" &&
1213 test_path_is_file foo &&
1214 test_path_is_file bar &&
1216 test_path_is_file "foo bar" &&
1217 test_path_is_file foo &&
1218 test_path_is_file bar
1221 test_expect_success
'stash -k -- <pathspec> leaves unstaged files intact' '
1226 git commit -m "test" &&
1229 git stash -k -- foo &&
1230 test "",bar = $(cat foo),$(cat bar) &&
1232 test foo,bar = $(cat foo),$(cat bar)
1235 test_expect_success
'stash -- <subdir> leaves untracked files in subdir intact' '
1237 >subdir/untracked &&
1240 git add subdir/tracked* &&
1241 git stash -- subdir/ &&
1242 test_path_is_missing subdir/tracked1 &&
1243 test_path_is_missing subdir/tracked2 &&
1244 test_path_is_file subdir/untracked &&
1246 test_path_is_file subdir/tracked1 &&
1247 test_path_is_file subdir/tracked2 &&
1248 test_path_is_file subdir/untracked
1251 test_expect_success
'stash -- <subdir> works with binary files' '
1253 >subdir/untracked &&
1255 cp "$TEST_DIRECTORY"/test-binary-1.png subdir/tracked-binary &&
1256 git add subdir/tracked* &&
1257 git stash -- subdir/ &&
1258 test_path_is_missing subdir/tracked &&
1259 test_path_is_missing subdir/tracked-binary &&
1260 test_path_is_file subdir/untracked &&
1262 test_path_is_file subdir/tracked &&
1263 test_path_is_file subdir/tracked-binary &&
1264 test_path_is_file subdir/untracked
1267 test_expect_success
'stash with user.name and user.email set works' '
1268 test_config user.name "A U Thor" &&
1269 test_config user.email "a.u@thor" &&
1273 test_expect_success
'stash works when user.name and user.email are not set' '
1277 echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" >expect &&
1279 git show -s --format="%an <%ae>" refs/stash >actual &&
1280 test_cmp expect actual &&
1283 test_config user.useconfigonly true &&
1284 test_config stash.usebuiltin true &&
1286 sane_unset GIT_AUTHOR_NAME &&
1287 sane_unset GIT_AUTHOR_EMAIL &&
1288 sane_unset GIT_COMMITTER_NAME &&
1289 sane_unset GIT_COMMITTER_EMAIL &&
1290 test_unconfig user.email &&
1291 test_unconfig user.name &&
1292 test_must_fail git commit -m "should fail" &&
1293 echo "git stash <git@stash>" >expect &&
1296 git show -s --format="%an <%ae>" refs/stash >actual &&
1297 test_cmp expect actual
1301 test_expect_success
'stash --keep-index with file deleted in index does not resurrect it on disk' '
1302 test_commit to-remove to-remove &&
1304 git stash --keep-index &&
1305 test_path_is_missing to-remove
1308 test_expect_success
'stash apply should succeed with unmodified file' '
1311 git commit -m base &&
1313 # now stash a modification
1314 echo modified >file &&
1317 # make the file stat dirty
1324 test_expect_success
'stash handles skip-worktree entries nicely' '
1326 echo changed >A.t &&
1328 git update-index --skip-worktree A.t &&
1332 git rev-parse --verify refs/stash:A.t
1335 test_expect_success
'stash -c stash.useBuiltin=false warning ' '
1336 expected="stash.useBuiltin support has been removed" &&
1338 git -c stash.useBuiltin=false stash 2>err &&
1339 test_i18ngrep "$expected" err &&
1340 env GIT_TEST_STASH_USE_BUILTIN=false git stash 2>err &&
1341 test_i18ngrep "$expected" err &&
1343 git -c stash.useBuiltin=true stash 2>err &&
1344 test_must_be_empty err &&
1345 env GIT_TEST_STASH_USE_BUILTIN=true git stash 2>err &&
1346 test_must_be_empty err
1349 test_expect_success
'git stash succeeds despite directory/file change' '
1350 test_create_repo directory_file_switch_v1 &&
1352 cd directory_file_switch_v1 &&
1355 test_write_lines this file has some words >filler &&
1357 git commit -m filler &&
1361 echo contents >filler/file &&
1366 test_expect_success
'git stash can pop file -> directory saved changes' '
1367 test_create_repo directory_file_switch_v2 &&
1369 cd directory_file_switch_v2 &&
1372 test_write_lines this file has some words >filler &&
1374 git commit -m filler &&
1378 echo contents >filler/file &&
1379 cp filler/file expect &&
1380 git stash push --include-untracked &&
1381 git stash apply --index &&
1382 test_cmp expect filler/file
1386 test_expect_success
'git stash can pop directory -> file saved changes' '
1387 test_create_repo directory_file_switch_v3 &&
1389 cd directory_file_switch_v3 &&
1393 test_write_lines some words >filler/file1 &&
1394 test_write_lines and stuff >filler/file2 &&
1396 git commit -m filler &&
1398 git rm -rf filler &&
1399 echo contents >filler &&
1401 git stash push --include-untracked &&
1402 git stash apply --index &&
1403 test_cmp expect filler
1407 test_expect_success
'restore untracked files even when we hit conflicts' '
1408 git init restore_untracked_after_conflict &&
1410 cd restore_untracked_after_conflict &&
1415 git commit -m first &&
1417 echo something >c &&
1419 git stash push --include-untracked &&
1423 git commit -m second &&
1425 test_must_fail git stash pop &&