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
'dont assume push with non-option args' '
289 test_must_fail git stash -q drop 2>err &&
290 test_i18ngrep -e "subcommand wasn'\''t specified; '\''push'\'' can'\''t be assumed due to unexpected token '\''drop'\''" err
293 test_expect_success
'stash --invalid-option' '
297 test_must_fail git stash --invalid-option &&
298 test_must_fail git stash save --invalid-option &&
299 test bar5,bar6 = $(cat file),$(cat file2)
302 test_expect_success
'stash an added file' '
306 git stash save "added file" &&
309 test new = "$(cat file3)"
312 test_expect_success
'stash --intent-to-add file' '
315 git add --intent-to-add file4 &&
316 test_when_finished "git rm -f file4" &&
317 test_must_fail git stash
320 test_expect_success
'stash rm then recreate' '
324 git stash save "rm then recreate" &&
325 test bar = "$(cat file)" &&
327 test bar7 = "$(cat file)"
330 test_expect_success
'stash rm and ignore' '
333 echo file >.gitignore &&
334 git stash save "rm and ignore" &&
335 test bar = "$(cat file)" &&
336 test file = "$(cat .gitignore)" &&
339 test file = "$(cat .gitignore)"
342 test_expect_success
'stash rm and ignore (stage .gitignore)' '
345 echo file >.gitignore &&
346 git add .gitignore &&
347 git stash save "rm and ignore (stage .gitignore)" &&
348 test bar = "$(cat file)" &&
349 ! test -r .gitignore &&
352 test file = "$(cat .gitignore)"
355 test_expect_success SYMLINKS
'stash file to symlink' '
359 git stash save "file to symlink" &&
361 test bar = "$(cat file)" &&
363 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
366 test_expect_success SYMLINKS
'stash file to symlink (stage rm)' '
370 git stash save "file to symlink (stage rm)" &&
372 test bar = "$(cat file)" &&
374 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
377 test_expect_success SYMLINKS
'stash file to symlink (full stage)' '
382 git stash save "file to symlink (full stage)" &&
384 test bar = "$(cat file)" &&
386 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
389 # This test creates a commit with a symlink used for the following tests
391 test_expect_success
'stash symlink to file' '
393 test_ln_s_add file filelink &&
394 git commit -m "Add symlink" &&
397 git stash save "symlink to file"
400 test_expect_success SYMLINKS
'this must have re-created the symlink' '
402 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
405 test_expect_success
'unstash must re-create the file' '
407 ! test -h filelink &&
408 test bar = "$(cat file)"
411 test_expect_success
'stash symlink to file (stage rm)' '
415 git stash save "symlink to file (stage rm)"
418 test_expect_success SYMLINKS
'this must have re-created the symlink' '
420 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
423 test_expect_success
'unstash must re-create the file' '
425 ! test -h filelink &&
426 test bar = "$(cat file)"
429 test_expect_success
'stash symlink to file (full stage)' '
434 git stash save "symlink to file (full stage)"
437 test_expect_success SYMLINKS
'this must have re-created the symlink' '
439 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
442 test_expect_success
'unstash must re-create the file' '
444 ! test -h filelink &&
445 test bar = "$(cat file)"
448 test_expect_failure
'stash directory to file' '
451 echo foo >dir/file &&
453 git commit -m "Add file in dir" &&
456 git stash save "directory to file" &&
458 test foo = "$(cat dir/file)" &&
459 test_must_fail git stash apply &&
460 test bar = "$(cat dir)" &&
461 git reset --soft HEAD^
464 test_expect_failure
'stash file to directory' '
468 echo foo >file/file &&
469 git stash save "file to directory" &&
471 test bar = "$(cat file)" &&
474 test foo = "$(cat file/file)"
477 test_expect_success
'giving too many ref arguments does not modify files' '
479 test_when_finished "git reset --hard HEAD" &&
484 test-tool chmtime =123456789 file2 &&
485 for type in apply pop "branch stash-branch"
487 test_must_fail git stash $type stash@{0} stash@{1} 2>err &&
488 test_i18ngrep "Too many revisions" err &&
489 test 123456789 = $(test-tool chmtime -g file2) || return 1
493 test_expect_success
'drop: too many arguments errors out (does nothing)' '
494 git stash list >expect &&
495 test_must_fail git stash drop stash@{0} stash@{1} 2>err &&
496 test_i18ngrep "Too many revisions" err &&
497 git stash list >actual &&
498 test_cmp expect actual
501 test_expect_success
'show: too many arguments errors out (does nothing)' '
502 test_must_fail git stash show stash@{0} stash@{1} 2>err 1>out &&
503 test_i18ngrep "Too many revisions" err &&
504 test_must_be_empty out
507 test_expect_success
'stash create - no changes' '
509 test_when_finished "git reset --hard HEAD" &&
511 git stash create >actual &&
512 test_must_be_empty actual
515 test_expect_success
'stash branch - no stashes on stack, stash-like argument' '
517 test_when_finished "git reset --hard HEAD" &&
520 STASH_ID=$(git stash create) &&
522 git stash branch stash-branch ${STASH_ID} &&
523 test_when_finished "git reset --hard HEAD && git checkout master &&
524 git branch -D stash-branch" &&
525 test $(git ls-files --modified | wc -l) -eq 1
528 test_expect_success
'stash branch - stashes on stack, stash-like argument' '
530 test_when_finished "git reset --hard HEAD" &&
534 test_when_finished "git stash drop" &&
536 STASH_ID=$(git stash create) &&
538 git stash branch stash-branch ${STASH_ID} &&
539 test_when_finished "git reset --hard HEAD && git checkout master &&
540 git branch -D stash-branch" &&
541 test $(git ls-files --modified | wc -l) -eq 1
544 test_expect_success
'stash branch complains with no arguments' '
545 test_must_fail git stash branch 2>err &&
546 test_i18ngrep "No branch name specified" err
549 test_expect_success
'stash show format defaults to --stat' '
551 test_when_finished "git reset --hard HEAD" &&
555 test_when_finished "git stash drop" &&
557 STASH_ID=$(git stash create) &&
559 cat >expected <<-EOF &&
561 1 file changed, 1 insertion(+)
563 git stash show ${STASH_ID} >actual &&
564 test_i18ncmp expected actual
567 test_expect_success
'stash show - stashes on stack, stash-like argument' '
569 test_when_finished "git reset --hard HEAD" &&
573 test_when_finished "git stash drop" &&
575 STASH_ID=$(git stash create) &&
577 echo "1 0 file" >expected &&
578 git stash show --numstat ${STASH_ID} >actual &&
579 test_cmp expected actual
582 test_expect_success
'stash show -p - stashes on stack, stash-like argument' '
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 &&
593 diff --git a/file b/file
594 index 7601807..935fbd3 100644
601 git stash show -p ${STASH_ID} >actual &&
602 diff_cmp expected actual
605 test_expect_success
'stash show - no stashes on stack, stash-like argument' '
607 test_when_finished "git reset --hard HEAD" &&
610 STASH_ID=$(git stash create) &&
612 echo "1 0 file" >expected &&
613 git stash show --numstat ${STASH_ID} >actual &&
614 test_cmp expected actual
617 test_expect_success
'stash show -p - no stashes on stack, stash-like argument' '
619 test_when_finished "git reset --hard HEAD" &&
622 STASH_ID=$(git stash create) &&
624 cat >expected <<-EOF &&
625 diff --git a/file b/file
626 index 7601807..71b52c4 100644
633 git stash show -p ${STASH_ID} >actual &&
634 diff_cmp expected actual
637 test_expect_success
'stash show --patience shows diff' '
640 STASH_ID=$(git stash create) &&
642 cat >expected <<-EOF &&
643 diff --git a/file b/file
644 index 7601807..71b52c4 100644
651 git stash show --patience ${STASH_ID} >actual &&
652 diff_cmp expected actual
655 test_expect_success
'drop: fail early if specified stash is not a stash ref' '
657 test_when_finished "git reset --hard HEAD && git stash clear" &&
663 test_must_fail git stash drop $(git rev-parse stash@{0}) &&
665 test bar = "$(cat file)" &&
666 git reset --hard HEAD
669 test_expect_success
'pop: fail early if specified stash is not a stash ref' '
671 test_when_finished "git reset --hard HEAD && git stash clear" &&
677 test_must_fail git stash pop $(git rev-parse stash@{0}) &&
679 test bar = "$(cat file)" &&
680 git reset --hard HEAD
683 test_expect_success
'ref with non-existent reflog' '
689 test_must_fail git rev-parse --quiet --verify does-not-exist &&
690 test_must_fail git stash drop does-not-exist &&
691 test_must_fail git stash drop does-not-exist@{0} &&
692 test_must_fail git stash pop does-not-exist &&
693 test_must_fail git stash pop does-not-exist@{0} &&
694 test_must_fail git stash apply does-not-exist &&
695 test_must_fail git stash apply does-not-exist@{0} &&
696 test_must_fail git stash show does-not-exist &&
697 test_must_fail git stash show does-not-exist@{0} &&
698 test_must_fail git stash branch tmp does-not-exist &&
699 test_must_fail git stash branch tmp does-not-exist@{0} &&
703 test_expect_success
'invalid ref of the form stash@{n}, n >= N' '
705 test_must_fail git stash drop stash@{0} &&
710 test_must_fail git stash drop stash@{1} &&
711 test_must_fail git stash pop stash@{1} &&
712 test_must_fail git stash apply stash@{1} &&
713 test_must_fail git stash show stash@{1} &&
714 test_must_fail git stash branch tmp stash@{1} &&
718 test_expect_success
'invalid ref of the form "n", n >= N' '
720 test_must_fail git stash drop 0 &&
725 test_must_fail git stash drop 1 &&
726 test_must_fail git stash pop 1 &&
727 test_must_fail git stash apply 1 &&
728 test_must_fail git stash show 1 &&
729 test_must_fail git stash branch tmp 1 &&
733 test_expect_success
'valid ref of the form "n", n < N' '
740 git stash branch tmp 0 &&
741 git checkout master &&
748 test_must_fail git stash drop
751 test_expect_success
'branch: do not drop the stash if the branch exists' '
755 git commit -m initial &&
758 test_must_fail git stash branch master stash@{0} &&
759 git rev-parse stash@{0} --
762 test_expect_success
'branch: should not drop the stash if the apply fails' '
764 git reset HEAD~1 --hard &&
767 git commit -m initial &&
771 test_when_finished "git checkout master" &&
772 test_must_fail git stash branch new_branch stash@{0} &&
773 git rev-parse stash@{0} --
776 test_expect_success
'apply: show same status as git status (relative to ./)' '
778 echo 1 >subdir/subfile1 &&
779 echo 2 >subdir/subfile2 &&
780 git add subdir/subfile1 &&
781 git commit -m subdir &&
786 git status >../expect &&
788 sane_unset GIT_MERGE_VERBOSITY &&
791 sed -e 1d >actual && # drop "Saved..."
792 test_i18ncmp expect actual
796 diff --git a/HEAD b/HEAD
798 index 0000000..fe0cbee
805 test_expect_success
'stash where working directory contains "HEAD" file' '
808 echo file-not-a-ref >HEAD &&
812 git diff-files --quiet &&
813 git diff-index --cached --quiet HEAD &&
814 test "$(git rev-parse stash^)" = "$(git rev-parse HEAD)" &&
815 git diff stash^..stash >output &&
816 diff_cmp expect output
819 test_expect_success
'store called with invalid commit' '
820 test_must_fail git stash store foo
823 test_expect_success
'store updates stash ref and reflog' '
828 STASH_ID=$(git stash create) &&
830 test_path_is_missing bazzy &&
831 git stash store -m quuxery $STASH_ID &&
832 test $(git rev-parse stash) = $STASH_ID &&
833 git reflog --format=%H stash| grep $STASH_ID &&
838 test_expect_success
'handle stash specification with spaces' '
842 stamp=$(git log -g --format="%cd" -1 refs/stash) &&
846 git stash apply "stash@{$stamp}" &&
850 test_expect_success
'setup stash with index and worktree changes' '
855 echo working >file &&
859 test_expect_success
'stash list implies --first-parent -m' '
860 cat >expect <<-EOF &&
863 diff --git a/file b/file
864 index 257cc56..d26b33d 100644
871 git stash list --format=%gd -p >actual &&
872 diff_cmp expect actual
875 test_expect_success
'stash list --cc shows combined diff' '
876 cat >expect <<-\EOF &&
880 index 257cc56,9015a7a..d26b33d
883 @@@ -1,1 -1,1 +1,1 @@@
888 git stash list --format=%gd -p --cc >actual &&
889 diff_cmp expect actual
892 test_expect_success
'stash is not confused by partial renames' '
897 test_path_is_file renamed &&
898 test_path_is_missing file
901 test_expect_success
'push -m shows right message' '
904 git stash push -m "test message" &&
905 echo "stash@{0}: On master: test message" >expect &&
906 git stash list -1 >actual &&
907 test_cmp expect actual
910 test_expect_success
'push -m also works without space' '
913 git stash push -m"unspaced test message" &&
914 echo "stash@{0}: On master: unspaced test message" >expect &&
915 git stash list -1 >actual &&
916 test_cmp expect actual
919 test_expect_success
'store -m foo shows right message' '
924 STASH_ID=$(git stash create) &&
925 git stash store -m "store m" $STASH_ID &&
926 echo "stash@{0}: store m" >expect &&
927 git stash list -1 >actual &&
928 test_cmp expect actual
931 test_expect_success
'store -mfoo shows right message' '
936 STASH_ID=$(git stash create) &&
937 git stash store -m"store mfoo" $STASH_ID &&
938 echo "stash@{0}: store mfoo" >expect &&
939 git stash list -1 >actual &&
940 test_cmp expect actual
943 test_expect_success
'store --message=foo shows right message' '
948 STASH_ID=$(git stash create) &&
949 git stash store --message="store message=foo" $STASH_ID &&
950 echo "stash@{0}: store message=foo" >expect &&
951 git stash list -1 >actual &&
952 test_cmp expect actual
955 test_expect_success
'store --message foo shows right message' '
960 STASH_ID=$(git stash create) &&
961 git stash store --message "store message foo" $STASH_ID &&
962 echo "stash@{0}: store message foo" >expect &&
963 git stash list -1 >actual &&
964 test_cmp expect actual
967 test_expect_success
'push -mfoo uses right message' '
970 git stash push -m"test mfoo" &&
971 echo "stash@{0}: On master: test mfoo" >expect &&
972 git stash list -1 >actual &&
973 test_cmp expect actual
976 test_expect_success
'push --message foo is synonym for -mfoo' '
979 git stash push --message "test message foo" &&
980 echo "stash@{0}: On master: test message foo" >expect &&
981 git stash list -1 >actual &&
982 test_cmp expect actual
985 test_expect_success
'push --message=foo is synonym for -mfoo' '
988 git stash push --message="test message=foo" &&
989 echo "stash@{0}: On master: test message=foo" >expect &&
990 git stash list -1 >actual &&
991 test_cmp expect actual
994 test_expect_success
'push -m shows right message' '
997 git stash push -m "test m foo" &&
998 echo "stash@{0}: On master: test m foo" >expect &&
999 git stash list -1 >actual &&
1000 test_cmp expect actual
1003 test_expect_success
'create stores correct message' '
1006 STASH_ID=$(git stash create "create test message") &&
1007 echo "On master: create test message" >expect &&
1008 git show --pretty=%s -s ${STASH_ID} >actual &&
1009 test_cmp expect actual
1012 test_expect_success
'create with multiple arguments for the message' '
1015 STASH_ID=$(git stash create test untracked) &&
1016 echo "On master: test untracked" >expect &&
1017 git show --pretty=%s -s ${STASH_ID} >actual &&
1018 test_cmp expect actual
1021 test_expect_success
'create in a detached state' '
1022 test_when_finished "git checkout master" &&
1023 git checkout HEAD~1 &&
1026 STASH_ID=$(git stash create) &&
1027 HEAD_ID=$(git rev-parse --short HEAD) &&
1028 echo "WIP on (no branch): ${HEAD_ID} initial" >expect &&
1029 git show --pretty=%s -s ${STASH_ID} >actual &&
1030 test_cmp expect actual
1033 test_expect_success
'stash -- <pathspec> stashes and restores the file' '
1037 git stash push -- foo &&
1038 test_path_is_file bar &&
1039 test_path_is_missing foo &&
1041 test_path_is_file foo &&
1042 test_path_is_file bar
1045 test_expect_success
'stash -- <pathspec> stashes in subdirectory' '
1052 git stash push -- ../foo
1054 test_path_is_file bar &&
1055 test_path_is_missing foo &&
1057 test_path_is_file foo &&
1058 test_path_is_file bar
1061 test_expect_success
'stash with multiple pathspec arguments' '
1065 git add foo bar extra &&
1066 git stash push -- foo bar &&
1067 test_path_is_missing bar &&
1068 test_path_is_missing foo &&
1069 test_path_is_file extra &&
1071 test_path_is_file foo &&
1072 test_path_is_file bar &&
1073 test_path_is_file extra
1076 test_expect_success
'stash with file including $IFS character' '
1081 git stash push -- "foo b*" &&
1082 test_path_is_missing "foo bar" &&
1083 test_path_is_file foo &&
1084 test_path_is_file bar &&
1086 test_path_is_file "foo bar" &&
1087 test_path_is_file foo &&
1088 test_path_is_file bar
1091 test_expect_success
'stash with pathspec matching multiple paths' '
1092 echo original >file &&
1093 echo original >other-file &&
1094 git commit -m "two" file other-file &&
1095 echo modified >file &&
1096 echo modified >other-file &&
1097 git stash push -- "*file" &&
1098 echo original >expect &&
1099 test_cmp expect file &&
1100 test_cmp expect other-file &&
1102 echo modified >expect &&
1103 test_cmp expect file &&
1104 test_cmp expect other-file
1107 test_expect_success
'stash push -p with pathspec shows no changes only once' '
1110 git commit -m "tmp" &&
1111 git stash push -p foo >actual &&
1112 echo "No local changes to save" >expect &&
1113 git reset --hard HEAD~ &&
1114 test_i18ncmp expect actual
1117 test_expect_success
'push <pathspec>: show no changes when there are none' '
1120 git commit -m "tmp" &&
1121 git stash push foo >actual &&
1122 echo "No local changes to save" >expect &&
1123 git reset --hard HEAD~ &&
1124 test_i18ncmp expect actual
1127 test_expect_success
'push: <pathspec> not in the repository errors out' '
1129 test_must_fail git stash push untracked &&
1130 test_path_is_file untracked
1133 test_expect_success
'push: -q is quiet with changes' '
1136 git stash push -q >output 2>&1 &&
1137 test_must_be_empty output
1140 test_expect_success
'push: -q is quiet with no changes' '
1141 git stash push -q >output 2>&1 &&
1142 test_must_be_empty output
1145 test_expect_success
'push: -q is quiet even if there is no initial commit' '
1147 test_when_finished rm -rf foo_dir &&
1151 test_must_fail git stash push -q >output 2>&1 &&
1152 test_must_be_empty output
1156 test_expect_success
'untracked files are left in place when -u is not given' '
1160 git stash push file &&
1161 test_path_is_file untracked
1164 test_expect_success
'stash without verb with pathspec' '
1169 git stash -- "foo b*" &&
1170 test_path_is_missing "foo bar" &&
1171 test_path_is_file foo &&
1172 test_path_is_file bar &&
1174 test_path_is_file "foo bar" &&
1175 test_path_is_file foo &&
1176 test_path_is_file bar
1179 test_expect_success
'stash -k -- <pathspec> leaves unstaged files intact' '
1184 git commit -m "test" &&
1187 git stash -k -- foo &&
1188 test "",bar = $(cat foo),$(cat bar) &&
1190 test foo,bar = $(cat foo),$(cat bar)
1193 test_expect_success
'stash -- <subdir> leaves untracked files in subdir intact' '
1195 >subdir/untracked &&
1198 git add subdir/tracked* &&
1199 git stash -- subdir/ &&
1200 test_path_is_missing subdir/tracked1 &&
1201 test_path_is_missing subdir/tracked2 &&
1202 test_path_is_file subdir/untracked &&
1204 test_path_is_file subdir/tracked1 &&
1205 test_path_is_file subdir/tracked2 &&
1206 test_path_is_file subdir/untracked
1209 test_expect_success
'stash -- <subdir> works with binary files' '
1211 >subdir/untracked &&
1213 cp "$TEST_DIRECTORY"/test-binary-1.png subdir/tracked-binary &&
1214 git add subdir/tracked* &&
1215 git stash -- subdir/ &&
1216 test_path_is_missing subdir/tracked &&
1217 test_path_is_missing subdir/tracked-binary &&
1218 test_path_is_file subdir/untracked &&
1220 test_path_is_file subdir/tracked &&
1221 test_path_is_file subdir/tracked-binary &&
1222 test_path_is_file subdir/untracked
1225 test_expect_success
'stash with user.name and user.email set works' '
1226 test_config user.name "A U Thor" &&
1227 test_config user.email "a.u@thor" &&
1231 test_expect_success
'stash works when user.name and user.email are not set' '
1235 echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" >expect &&
1237 git show -s --format="%an <%ae>" refs/stash >actual &&
1238 test_cmp expect actual &&
1241 test_config user.useconfigonly true &&
1242 test_config stash.usebuiltin true &&
1244 sane_unset GIT_AUTHOR_NAME &&
1245 sane_unset GIT_AUTHOR_EMAIL &&
1246 sane_unset GIT_COMMITTER_NAME &&
1247 sane_unset GIT_COMMITTER_EMAIL &&
1248 test_unconfig user.email &&
1249 test_unconfig user.name &&
1250 test_must_fail git commit -m "should fail" &&
1251 echo "git stash <git@stash>" >expect &&
1254 git show -s --format="%an <%ae>" refs/stash >actual &&
1255 test_cmp expect actual
1259 test_expect_success
'stash --keep-index with file deleted in index does not resurrect it on disk' '
1260 test_commit to-remove to-remove &&
1262 git stash --keep-index &&
1263 test_path_is_missing to-remove
1266 test_expect_success
'stash apply should succeed with unmodified file' '
1269 git commit -m base &&
1271 # now stash a modification
1272 echo modified >file &&
1275 # make the file stat dirty
1282 test_expect_success
'stash handles skip-worktree entries nicely' '
1284 echo changed >A.t &&
1286 git update-index --skip-worktree A.t &&
1290 git rev-parse --verify refs/stash:A.t