3 # Copyright (c) 2007 Johannes E Schindelin
6 test_description
='Test git stash'
13 sed -e 's/^index 0000000\.\.[0-9a-f]*/index 0000000..1234567/' \
14 -e 's/^index [0-9a-f]*\.\.[0-9a-f]*/index 1234567..89abcde/' \
15 -e 's/^index [0-9a-f]*,[0-9a-f]*\.\.[0-9a-f]*/index 1234567,7654321..89abcde/' \
16 "$i" >"$i.compare" ||
return 1
18 test_cmp
"$1.compare" "$2.compare" &&
19 rm -f "$1.compare" "$2.compare"
22 test_expect_success
'stash some dirty working directory' '
25 echo unrelated >other-file &&
28 git commit -m initial &&
34 git diff-files --quiet &&
35 git diff-index --cached --quiet HEAD
39 diff --git a/file b/file
40 index 0cfbf08..00750ed 100644
48 test_expect_success
'parents of stash' '
49 test $(git rev-parse stash^) = $(git rev-parse HEAD) &&
50 git diff stash^2..stash >output &&
51 diff_cmp expect output
54 test_expect_success
'applying bogus stash does nothing' '
55 test_must_fail git stash apply stash@{1} &&
60 test_expect_success
'apply does not need clean working directory' '
67 test_expect_success
'apply does not clobber working directory changes' '
70 test_must_fail git stash apply &&
75 test_expect_success
'apply stashed changes' '
80 git commit -m other-file &&
82 test 3 = $(cat file) &&
83 test 1 = $(git show :file) &&
84 test 1 = $(git show HEAD:file)
87 test_expect_success
'apply stashed changes (including index)' '
88 git reset --hard HEAD^ &&
92 git commit -m other-file &&
93 git stash apply --index &&
94 test 3 = $(cat file) &&
95 test 2 = $(git show :file) &&
96 test 1 = $(git show HEAD:file)
99 test_expect_success
'unstashing in a subdirectory' '
100 git reset --hard HEAD &&
108 test_expect_success
'stash drop complains of extra options' '
109 test_must_fail git stash drop --foo
112 test_expect_success
'drop top stash' '
114 git stash list >expected &&
118 git stash list >actual &&
119 test_cmp expected actual &&
121 test 3 = $(cat file) &&
122 test 1 = $(git show :file) &&
123 test 1 = $(git show HEAD:file)
126 test_expect_success
'drop middle stash' '
132 git stash drop stash@{1} &&
133 test 2 = $(git stash list | wc -l) &&
135 test 9 = $(cat file) &&
136 test 1 = $(git show :file) &&
137 test 1 = $(git show HEAD:file) &&
141 test 3 = $(cat file) &&
142 test 1 = $(git show :file) &&
143 test 1 = $(git show HEAD:file)
146 test_expect_success
'drop middle stash by index' '
153 test 2 = $(git stash list | wc -l) &&
155 test 9 = $(cat file) &&
156 test 1 = $(git show :file) &&
157 test 1 = $(git show HEAD:file) &&
161 test 3 = $(cat file) &&
162 test 1 = $(git show :file) &&
163 test 1 = $(git show HEAD:file)
166 test_expect_success
'stash pop' '
169 test 3 = $(cat file) &&
170 test 1 = $(git show :file) &&
171 test 1 = $(git show HEAD:file) &&
172 test 0 = $(git stash list | wc -l)
176 diff --git a/file2 b/file2
178 index 0000000..1fe912c
186 diff --git a/file b/file
187 index 257cc56..5716ca5 100644
196 diff --git a/file b/file
197 index 7601807..5716ca5 100644
203 diff --git a/file2 b/file2
205 index 0000000..1fe912c
212 test_expect_success
'stash branch' '
214 git commit file -m first &&
220 git commit file -m second &&
221 git stash branch stashbranch &&
222 test refs/heads/stashbranch = $(git symbolic-ref HEAD) &&
223 test $(git rev-parse HEAD) = $(git rev-parse master^) &&
224 git diff --cached >output &&
225 diff_cmp expect output &&
227 diff_cmp expect1 output &&
229 git commit -m alternate\ second &&
230 git diff master..stashbranch >output &&
231 diff_cmp output expect2 &&
232 test 0 = $(git stash list | wc -l)
235 test_expect_success
'apply -q is quiet' '
238 git stash apply -q >output.out 2>&1 &&
239 test_must_be_empty output.out
242 test_expect_success
'save -q is quiet' '
243 git stash save --quiet >output.out 2>&1 &&
244 test_must_be_empty output.out
247 test_expect_success
'pop -q works and is quiet' '
248 git stash pop -q >output.out 2>&1 &&
250 git show :file >actual &&
251 test_cmp expect actual &&
252 test_must_be_empty output.out
255 test_expect_success
'pop -q --index works and is quiet' '
258 git stash save --quiet &&
259 git stash pop -q --index >output.out 2>&1 &&
260 git diff-files file2 >file2.diff &&
261 test_must_be_empty file2.diff &&
262 test foo = "$(git show :file)" &&
263 test_must_be_empty output.out
266 test_expect_success
'drop -q is quiet' '
268 git stash drop -q >output.out 2>&1 &&
269 test_must_be_empty output.out
272 test_expect_success
'stash -k' '
277 test bar,bar4 = $(cat file),$(cat file2)
280 test_expect_success
'stash --no-keep-index' '
284 git stash --no-keep-index &&
285 test bar,bar2 = $(cat file),$(cat file2)
288 test_expect_success
'stash --invalid-option' '
292 test_must_fail git stash --invalid-option &&
293 test_must_fail git stash save --invalid-option &&
294 test bar5,bar6 = $(cat file),$(cat file2)
297 test_expect_success
'stash an added file' '
301 git stash save "added file" &&
304 test new = "$(cat file3)"
307 test_expect_success
'stash --intent-to-add file' '
310 git add --intent-to-add file4 &&
311 test_when_finished "git rm -f file4" &&
312 test_must_fail git stash
315 test_expect_success
'stash rm then recreate' '
319 git stash save "rm then recreate" &&
320 test bar = "$(cat file)" &&
322 test bar7 = "$(cat file)"
325 test_expect_success
'stash rm and ignore' '
328 echo file >.gitignore &&
329 git stash save "rm and ignore" &&
330 test bar = "$(cat file)" &&
331 test file = "$(cat .gitignore)" &&
334 test file = "$(cat .gitignore)"
337 test_expect_success
'stash rm and ignore (stage .gitignore)' '
340 echo file >.gitignore &&
341 git add .gitignore &&
342 git stash save "rm and ignore (stage .gitignore)" &&
343 test bar = "$(cat file)" &&
344 ! test -r .gitignore &&
347 test file = "$(cat .gitignore)"
350 test_expect_success SYMLINKS
'stash file to symlink' '
354 git stash save "file to symlink" &&
356 test bar = "$(cat file)" &&
358 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
361 test_expect_success SYMLINKS
'stash file to symlink (stage rm)' '
365 git stash save "file to symlink (stage rm)" &&
367 test bar = "$(cat file)" &&
369 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
372 test_expect_success SYMLINKS
'stash file to symlink (full stage)' '
377 git stash save "file to symlink (full stage)" &&
379 test bar = "$(cat file)" &&
381 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
384 # This test creates a commit with a symlink used for the following tests
386 test_expect_success
'stash symlink to file' '
388 test_ln_s_add file filelink &&
389 git commit -m "Add symlink" &&
392 git stash save "symlink to file"
395 test_expect_success SYMLINKS
'this must have re-created the symlink' '
397 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
400 test_expect_success
'unstash must re-create the file' '
402 ! test -h filelink &&
403 test bar = "$(cat file)"
406 test_expect_success
'stash symlink to file (stage rm)' '
410 git stash save "symlink to file (stage rm)"
413 test_expect_success SYMLINKS
'this must have re-created the symlink' '
415 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
418 test_expect_success
'unstash must re-create the file' '
420 ! test -h filelink &&
421 test bar = "$(cat file)"
424 test_expect_success
'stash symlink to file (full stage)' '
429 git stash save "symlink to file (full stage)"
432 test_expect_success SYMLINKS
'this must have re-created the symlink' '
434 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
437 test_expect_success
'unstash must re-create the file' '
439 ! test -h filelink &&
440 test bar = "$(cat file)"
443 test_expect_failure
'stash directory to file' '
446 echo foo >dir/file &&
448 git commit -m "Add file in dir" &&
451 git stash save "directory to file" &&
453 test foo = "$(cat dir/file)" &&
454 test_must_fail git stash apply &&
455 test bar = "$(cat dir)" &&
456 git reset --soft HEAD^
459 test_expect_failure
'stash file to directory' '
463 echo foo >file/file &&
464 git stash save "file to directory" &&
466 test bar = "$(cat file)" &&
469 test foo = "$(cat file/file)"
472 test_expect_success
'giving too many ref arguments does not modify files' '
474 test_when_finished "git reset --hard HEAD" &&
479 test-tool chmtime =123456789 file2 &&
480 for type in apply pop "branch stash-branch"
482 test_must_fail git stash $type stash@{0} stash@{1} 2>err &&
483 test_i18ngrep "Too many revisions" err &&
484 test 123456789 = $(test-tool chmtime -g file2) || return 1
488 test_expect_success
'drop: too many arguments errors out (does nothing)' '
489 git stash list >expect &&
490 test_must_fail git stash drop stash@{0} stash@{1} 2>err &&
491 test_i18ngrep "Too many revisions" err &&
492 git stash list >actual &&
493 test_cmp expect actual
496 test_expect_success
'show: too many arguments errors out (does nothing)' '
497 test_must_fail git stash show stash@{0} stash@{1} 2>err 1>out &&
498 test_i18ngrep "Too many revisions" err &&
499 test_must_be_empty out
502 test_expect_success
'stash create - no changes' '
504 test_when_finished "git reset --hard HEAD" &&
506 git stash create >actual &&
507 test_must_be_empty actual
510 test_expect_success
'stash branch - no stashes on stack, stash-like argument' '
512 test_when_finished "git reset --hard HEAD" &&
515 STASH_ID=$(git stash create) &&
517 git stash branch stash-branch ${STASH_ID} &&
518 test_when_finished "git reset --hard HEAD && git checkout master &&
519 git branch -D stash-branch" &&
520 test $(git ls-files --modified | wc -l) -eq 1
523 test_expect_success
'stash branch - stashes on stack, stash-like argument' '
525 test_when_finished "git reset --hard HEAD" &&
529 test_when_finished "git stash drop" &&
531 STASH_ID=$(git stash create) &&
533 git stash branch stash-branch ${STASH_ID} &&
534 test_when_finished "git reset --hard HEAD && git checkout master &&
535 git branch -D stash-branch" &&
536 test $(git ls-files --modified | wc -l) -eq 1
539 test_expect_success
'stash branch complains with no arguments' '
540 test_must_fail git stash branch 2>err &&
541 test_i18ngrep "No branch name specified" err
544 test_expect_success
'stash show format defaults to --stat' '
546 test_when_finished "git reset --hard HEAD" &&
550 test_when_finished "git stash drop" &&
552 STASH_ID=$(git stash create) &&
554 cat >expected <<-EOF &&
556 1 file changed, 1 insertion(+)
558 git stash show ${STASH_ID} >actual &&
559 test_i18ncmp expected actual
562 test_expect_success
'stash show - stashes on stack, stash-like argument' '
564 test_when_finished "git reset --hard HEAD" &&
568 test_when_finished "git stash drop" &&
570 STASH_ID=$(git stash create) &&
572 echo "1 0 file" >expected &&
573 git stash show --numstat ${STASH_ID} >actual &&
574 test_cmp expected actual
577 test_expect_success
'stash show -p - stashes on stack, stash-like argument' '
579 test_when_finished "git reset --hard HEAD" &&
583 test_when_finished "git stash drop" &&
585 STASH_ID=$(git stash create) &&
587 cat >expected <<-EOF &&
588 diff --git a/file b/file
589 index 7601807..935fbd3 100644
596 git stash show -p ${STASH_ID} >actual &&
597 diff_cmp expected actual
600 test_expect_success
'stash show - no stashes on stack, stash-like argument' '
602 test_when_finished "git reset --hard HEAD" &&
605 STASH_ID=$(git stash create) &&
607 echo "1 0 file" >expected &&
608 git stash show --numstat ${STASH_ID} >actual &&
609 test_cmp expected actual
612 test_expect_success
'stash show -p - no stashes on stack, stash-like argument' '
614 test_when_finished "git reset --hard HEAD" &&
617 STASH_ID=$(git stash create) &&
619 cat >expected <<-EOF &&
620 diff --git a/file b/file
621 index 7601807..71b52c4 100644
628 git stash show -p ${STASH_ID} >actual &&
629 diff_cmp expected actual
632 test_expect_success
'stash show --patience shows diff' '
635 STASH_ID=$(git stash create) &&
637 cat >expected <<-EOF &&
638 diff --git a/file b/file
639 index 7601807..71b52c4 100644
646 git stash show --patience ${STASH_ID} >actual &&
647 diff_cmp expected actual
650 test_expect_success
'drop: fail early if specified stash is not a stash ref' '
652 test_when_finished "git reset --hard HEAD && git stash clear" &&
658 test_must_fail git stash drop $(git rev-parse stash@{0}) &&
660 test bar = "$(cat file)" &&
661 git reset --hard HEAD
664 test_expect_success
'pop: fail early if specified stash is not a stash ref' '
666 test_when_finished "git reset --hard HEAD && git stash clear" &&
672 test_must_fail git stash pop $(git rev-parse stash@{0}) &&
674 test bar = "$(cat file)" &&
675 git reset --hard HEAD
678 test_expect_success
'ref with non-existent reflog' '
684 test_must_fail git rev-parse --quiet --verify does-not-exist &&
685 test_must_fail git stash drop does-not-exist &&
686 test_must_fail git stash drop does-not-exist@{0} &&
687 test_must_fail git stash pop does-not-exist &&
688 test_must_fail git stash pop does-not-exist@{0} &&
689 test_must_fail git stash apply does-not-exist &&
690 test_must_fail git stash apply does-not-exist@{0} &&
691 test_must_fail git stash show does-not-exist &&
692 test_must_fail git stash show does-not-exist@{0} &&
693 test_must_fail git stash branch tmp does-not-exist &&
694 test_must_fail git stash branch tmp does-not-exist@{0} &&
698 test_expect_success
'invalid ref of the form stash@{n}, n >= N' '
700 test_must_fail git stash drop stash@{0} &&
705 test_must_fail git stash drop stash@{1} &&
706 test_must_fail git stash pop stash@{1} &&
707 test_must_fail git stash apply stash@{1} &&
708 test_must_fail git stash show stash@{1} &&
709 test_must_fail git stash branch tmp stash@{1} &&
713 test_expect_success
'invalid ref of the form "n", n >= N' '
715 test_must_fail git stash drop 0 &&
720 test_must_fail git stash drop 1 &&
721 test_must_fail git stash pop 1 &&
722 test_must_fail git stash apply 1 &&
723 test_must_fail git stash show 1 &&
724 test_must_fail git stash branch tmp 1 &&
728 test_expect_success
'valid ref of the form "n", n < N' '
735 git stash branch tmp 0 &&
736 git checkout master &&
743 test_must_fail git stash drop
746 test_expect_success
'branch: do not drop the stash if the branch exists' '
750 git commit -m initial &&
753 test_must_fail git stash branch master stash@{0} &&
754 git rev-parse stash@{0} --
757 test_expect_success
'branch: should not drop the stash if the apply fails' '
759 git reset HEAD~1 --hard &&
762 git commit -m initial &&
766 test_when_finished "git checkout master" &&
767 test_must_fail git stash branch new_branch stash@{0} &&
768 git rev-parse stash@{0} --
771 test_expect_success
'apply: show same status as git status (relative to ./)' '
773 echo 1 >subdir/subfile1 &&
774 echo 2 >subdir/subfile2 &&
775 git add subdir/subfile1 &&
776 git commit -m subdir &&
781 git status >../expect &&
783 sane_unset GIT_MERGE_VERBOSITY &&
786 sed -e 1d >actual && # drop "Saved..."
787 test_i18ncmp expect actual
791 diff --git a/HEAD b/HEAD
793 index 0000000..fe0cbee
800 test_expect_success
'stash where working directory contains "HEAD" file' '
803 echo file-not-a-ref >HEAD &&
807 git diff-files --quiet &&
808 git diff-index --cached --quiet HEAD &&
809 test "$(git rev-parse stash^)" = "$(git rev-parse HEAD)" &&
810 git diff stash^..stash >output &&
811 diff_cmp expect output
814 test_expect_success
'store called with invalid commit' '
815 test_must_fail git stash store foo
818 test_expect_success
'store updates stash ref and reflog' '
823 STASH_ID=$(git stash create) &&
825 test_path_is_missing bazzy &&
826 git stash store -m quuxery $STASH_ID &&
827 test $(git rev-parse stash) = $STASH_ID &&
828 git reflog --format=%H stash| grep $STASH_ID &&
833 test_expect_success
'handle stash specification with spaces' '
837 stamp=$(git log -g --format="%cd" -1 refs/stash) &&
841 git stash apply "stash@{$stamp}" &&
845 test_expect_success
'setup stash with index and worktree changes' '
850 echo working >file &&
854 test_expect_success
'stash list implies --first-parent -m' '
855 cat >expect <<-EOF &&
858 diff --git a/file b/file
859 index 257cc56..d26b33d 100644
866 git stash list --format=%gd -p >actual &&
867 diff_cmp expect actual
870 test_expect_success
'stash list --cc shows combined diff' '
871 cat >expect <<-\EOF &&
875 index 257cc56,9015a7a..d26b33d
878 @@@ -1,1 -1,1 +1,1 @@@
883 git stash list --format=%gd -p --cc >actual &&
884 diff_cmp expect actual
887 test_expect_success
'stash is not confused by partial renames' '
892 test_path_is_file renamed &&
893 test_path_is_missing file
896 test_expect_success
'push -m shows right message' '
899 git stash push -m "test message" &&
900 echo "stash@{0}: On master: test message" >expect &&
901 git stash list -1 >actual &&
902 test_cmp expect actual
905 test_expect_success
'push -m also works without space' '
908 git stash push -m"unspaced test message" &&
909 echo "stash@{0}: On master: unspaced test message" >expect &&
910 git stash list -1 >actual &&
911 test_cmp expect actual
914 test_expect_success
'store -m foo shows right message' '
919 STASH_ID=$(git stash create) &&
920 git stash store -m "store m" $STASH_ID &&
921 echo "stash@{0}: store m" >expect &&
922 git stash list -1 >actual &&
923 test_cmp expect actual
926 test_expect_success
'store -mfoo shows right message' '
931 STASH_ID=$(git stash create) &&
932 git stash store -m"store mfoo" $STASH_ID &&
933 echo "stash@{0}: store mfoo" >expect &&
934 git stash list -1 >actual &&
935 test_cmp expect actual
938 test_expect_success
'store --message=foo shows right message' '
943 STASH_ID=$(git stash create) &&
944 git stash store --message="store message=foo" $STASH_ID &&
945 echo "stash@{0}: store message=foo" >expect &&
946 git stash list -1 >actual &&
947 test_cmp expect actual
950 test_expect_success
'store --message foo shows right message' '
955 STASH_ID=$(git stash create) &&
956 git stash store --message "store message foo" $STASH_ID &&
957 echo "stash@{0}: store message foo" >expect &&
958 git stash list -1 >actual &&
959 test_cmp expect actual
962 test_expect_success
'push -mfoo uses right message' '
965 git stash push -m"test mfoo" &&
966 echo "stash@{0}: On master: test mfoo" >expect &&
967 git stash list -1 >actual &&
968 test_cmp expect actual
971 test_expect_success
'push --message foo is synonym for -mfoo' '
974 git stash push --message "test message foo" &&
975 echo "stash@{0}: On master: test message foo" >expect &&
976 git stash list -1 >actual &&
977 test_cmp expect actual
980 test_expect_success
'push --message=foo is synonym for -mfoo' '
983 git stash push --message="test message=foo" &&
984 echo "stash@{0}: On master: test message=foo" >expect &&
985 git stash list -1 >actual &&
986 test_cmp expect actual
989 test_expect_success
'push -m shows right message' '
992 git stash push -m "test m foo" &&
993 echo "stash@{0}: On master: test m foo" >expect &&
994 git stash list -1 >actual &&
995 test_cmp expect actual
998 test_expect_success
'create stores correct message' '
1001 STASH_ID=$(git stash create "create test message") &&
1002 echo "On master: create test message" >expect &&
1003 git show --pretty=%s -s ${STASH_ID} >actual &&
1004 test_cmp expect actual
1007 test_expect_success
'create with multiple arguments for the message' '
1010 STASH_ID=$(git stash create test untracked) &&
1011 echo "On master: test untracked" >expect &&
1012 git show --pretty=%s -s ${STASH_ID} >actual &&
1013 test_cmp expect actual
1016 test_expect_success
'create in a detached state' '
1017 test_when_finished "git checkout master" &&
1018 git checkout HEAD~1 &&
1021 STASH_ID=$(git stash create) &&
1022 HEAD_ID=$(git rev-parse --short HEAD) &&
1023 echo "WIP on (no branch): ${HEAD_ID} initial" >expect &&
1024 git show --pretty=%s -s ${STASH_ID} >actual &&
1025 test_cmp expect actual
1028 test_expect_success
'stash -- <pathspec> stashes and restores the file' '
1032 git stash push -- foo &&
1033 test_path_is_file bar &&
1034 test_path_is_missing foo &&
1036 test_path_is_file foo &&
1037 test_path_is_file bar
1040 test_expect_success
'stash -- <pathspec> stashes in subdirectory' '
1047 git stash push -- ../foo
1049 test_path_is_file bar &&
1050 test_path_is_missing foo &&
1052 test_path_is_file foo &&
1053 test_path_is_file bar
1056 test_expect_success
'stash with multiple pathspec arguments' '
1060 git add foo bar extra &&
1061 git stash push -- foo bar &&
1062 test_path_is_missing bar &&
1063 test_path_is_missing foo &&
1064 test_path_is_file extra &&
1066 test_path_is_file foo &&
1067 test_path_is_file bar &&
1068 test_path_is_file extra
1071 test_expect_success
'stash with file including $IFS character' '
1076 git stash push -- "foo b*" &&
1077 test_path_is_missing "foo bar" &&
1078 test_path_is_file foo &&
1079 test_path_is_file bar &&
1081 test_path_is_file "foo bar" &&
1082 test_path_is_file foo &&
1083 test_path_is_file bar
1086 test_expect_success
'stash with pathspec matching multiple paths' '
1087 echo original >file &&
1088 echo original >other-file &&
1089 git commit -m "two" file other-file &&
1090 echo modified >file &&
1091 echo modified >other-file &&
1092 git stash push -- "*file" &&
1093 echo original >expect &&
1094 test_cmp expect file &&
1095 test_cmp expect other-file &&
1097 echo modified >expect &&
1098 test_cmp expect file &&
1099 test_cmp expect other-file
1102 test_expect_success
'stash push -p with pathspec shows no changes only once' '
1105 git commit -m "tmp" &&
1106 git stash push -p foo >actual &&
1107 echo "No local changes to save" >expect &&
1108 git reset --hard HEAD~ &&
1109 test_i18ncmp expect actual
1112 test_expect_success
'push <pathspec>: show no changes when there are none' '
1115 git commit -m "tmp" &&
1116 git stash push foo >actual &&
1117 echo "No local changes to save" >expect &&
1118 git reset --hard HEAD~ &&
1119 test_i18ncmp expect actual
1122 test_expect_success
'push: <pathspec> not in the repository errors out' '
1124 test_must_fail git stash push untracked &&
1125 test_path_is_file untracked
1128 test_expect_success
'push: -q is quiet with changes' '
1131 git stash push -q >output 2>&1 &&
1132 test_must_be_empty output
1135 test_expect_success
'push: -q is quiet with no changes' '
1136 git stash push -q >output 2>&1 &&
1137 test_must_be_empty output
1140 test_expect_success
'push: -q is quiet even if there is no initial commit' '
1142 test_when_finished rm -rf foo_dir &&
1146 test_must_fail git stash push -q >output 2>&1 &&
1147 test_must_be_empty output
1151 test_expect_success
'untracked files are left in place when -u is not given' '
1155 git stash push file &&
1156 test_path_is_file untracked
1159 test_expect_success
'stash without verb with pathspec' '
1164 git stash -- "foo b*" &&
1165 test_path_is_missing "foo bar" &&
1166 test_path_is_file foo &&
1167 test_path_is_file bar &&
1169 test_path_is_file "foo bar" &&
1170 test_path_is_file foo &&
1171 test_path_is_file bar
1174 test_expect_success
'stash -k -- <pathspec> leaves unstaged files intact' '
1179 git commit -m "test" &&
1182 git stash -k -- foo &&
1183 test "",bar = $(cat foo),$(cat bar) &&
1185 test foo,bar = $(cat foo),$(cat bar)
1188 test_expect_success
'stash -- <subdir> leaves untracked files in subdir intact' '
1190 >subdir/untracked &&
1193 git add subdir/tracked* &&
1194 git stash -- subdir/ &&
1195 test_path_is_missing subdir/tracked1 &&
1196 test_path_is_missing subdir/tracked2 &&
1197 test_path_is_file subdir/untracked &&
1199 test_path_is_file subdir/tracked1 &&
1200 test_path_is_file subdir/tracked2 &&
1201 test_path_is_file subdir/untracked
1204 test_expect_success
'stash -- <subdir> works with binary files' '
1206 >subdir/untracked &&
1208 cp "$TEST_DIRECTORY"/test-binary-1.png subdir/tracked-binary &&
1209 git add subdir/tracked* &&
1210 git stash -- subdir/ &&
1211 test_path_is_missing subdir/tracked &&
1212 test_path_is_missing subdir/tracked-binary &&
1213 test_path_is_file subdir/untracked &&
1215 test_path_is_file subdir/tracked &&
1216 test_path_is_file subdir/tracked-binary &&
1217 test_path_is_file subdir/untracked
1220 test_expect_success
'stash with user.name and user.email set works' '
1221 test_config user.name "A U Thor" &&
1222 test_config user.email "a.u@thor" &&
1226 test_expect_success
'stash works when user.name and user.email are not set' '
1230 echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" >expect &&
1232 git show -s --format="%an <%ae>" refs/stash >actual &&
1233 test_cmp expect actual &&
1236 test_config user.useconfigonly true &&
1237 test_config stash.usebuiltin true &&
1239 sane_unset GIT_AUTHOR_NAME &&
1240 sane_unset GIT_AUTHOR_EMAIL &&
1241 sane_unset GIT_COMMITTER_NAME &&
1242 sane_unset GIT_COMMITTER_EMAIL &&
1243 test_unconfig user.email &&
1244 test_unconfig user.name &&
1245 test_must_fail git commit -m "should fail" &&
1246 echo "git stash <git@stash>" >expect &&
1249 git show -s --format="%an <%ae>" refs/stash >actual &&
1250 test_cmp expect actual
1254 test_expect_success
'stash --keep-index with file deleted in index does not resurrect it on disk' '
1255 test_commit to-remove to-remove &&
1257 git stash --keep-index &&
1258 test_path_is_missing to-remove
1261 test_expect_success
'stash apply should succeed with unmodified file' '
1264 git commit -m base &&
1266 # now stash a modification
1267 echo modified >file &&
1270 # make the file stat dirty
1277 test_expect_success
'stash handles skip-worktree entries nicely' '
1279 echo changed >A.t &&
1281 git update-index --skip-worktree A.t &&
1285 git rev-parse --verify refs/stash:A.t