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 is quiet' '
248 git stash pop -q >output.out 2>&1 &&
249 test_must_be_empty output.out
252 test_expect_success 'pop -q --index works and is quiet' '
255 git stash save --quiet &&
256 git stash pop -q --index >output.out 2>&1 &&
257 test foo = "$(git show :file)" &&
258 test_must_be_empty output.out
261 test_expect_success 'drop -q is quiet' '
263 git stash drop -q >output.out 2>&1 &&
264 test_must_be_empty output.out
267 test_expect_success 'stash -k' '
272 test bar,bar4 = $(cat file),$(cat file2)
275 test_expect_success 'stash --no-keep-index' '
279 git stash --no-keep-index &&
280 test bar,bar2 = $(cat file),$(cat file2)
283 test_expect_success 'stash --invalid-option' '
287 test_must_fail git stash --invalid-option &&
288 test_must_fail git stash save --invalid-option &&
289 test bar5,bar6 = $(cat file),$(cat file2)
292 test_expect_success 'stash an added file' '
296 git stash save "added file" &&
299 test new = "$(cat file3)"
302 test_expect_success 'stash --intent-to-add file' '
305 git add --intent-to-add file4 &&
306 test_when_finished "git rm -f file4" &&
307 test_must_fail git stash
310 test_expect_success 'stash rm then recreate' '
314 git stash save "rm then recreate" &&
315 test bar = "$(cat file)" &&
317 test bar7 = "$(cat file)"
320 test_expect_success 'stash rm and ignore' '
323 echo file >.gitignore &&
324 git stash save "rm and ignore" &&
325 test bar = "$(cat file)" &&
326 test file = "$(cat .gitignore)" &&
329 test file = "$(cat .gitignore)"
332 test_expect_success 'stash rm and ignore (stage .gitignore)' '
335 echo file >.gitignore &&
336 git add .gitignore &&
337 git stash save "rm and ignore (stage .gitignore)" &&
338 test bar = "$(cat file)" &&
339 ! test -r .gitignore &&
342 test file = "$(cat .gitignore)"
345 test_expect_success SYMLINKS 'stash file to symlink' '
349 git stash save "file to symlink" &&
351 test bar = "$(cat file)" &&
353 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
356 test_expect_success SYMLINKS 'stash file to symlink (stage rm)' '
360 git stash save "file to symlink (stage rm)" &&
362 test bar = "$(cat file)" &&
364 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
367 test_expect_success SYMLINKS 'stash file to symlink (full stage)' '
372 git stash save "file to symlink (full stage)" &&
374 test bar = "$(cat file)" &&
376 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
379 # This test creates a commit with a symlink used for the following tests
381 test_expect_success 'stash symlink to file' '
383 test_ln_s_add file filelink &&
384 git commit -m "Add symlink" &&
387 git stash save "symlink to file"
390 test_expect_success SYMLINKS 'this must have re-created the symlink' '
392 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
395 test_expect_success 'unstash must re-create the file' '
397 ! test -h filelink &&
398 test bar = "$(cat file)"
401 test_expect_success 'stash symlink to file (stage rm)' '
405 git stash save "symlink to file (stage rm)"
408 test_expect_success SYMLINKS 'this must have re-created the symlink' '
410 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
413 test_expect_success 'unstash must re-create the file' '
415 ! test -h filelink &&
416 test bar = "$(cat file)"
419 test_expect_success 'stash symlink to file (full stage)' '
424 git stash save "symlink to file (full stage)"
427 test_expect_success SYMLINKS 'this must have re-created the symlink' '
429 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
432 test_expect_success 'unstash must re-create the file' '
434 ! test -h filelink &&
435 test bar = "$(cat file)"
438 test_expect_failure 'stash directory to file' '
441 echo foo >dir/file &&
443 git commit -m "Add file in dir" &&
446 git stash save "directory to file" &&
448 test foo = "$(cat dir/file)" &&
449 test_must_fail git stash apply &&
450 test bar = "$(cat dir)" &&
451 git reset --soft HEAD^
454 test_expect_failure 'stash file to directory' '
458 echo foo >file/file &&
459 git stash save "file to directory" &&
461 test bar = "$(cat file)" &&
464 test foo = "$(cat file/file)"
467 test_expect_success 'giving too many ref arguments does not modify files' '
469 test_when_finished "git reset --hard HEAD" &&
474 test-tool chmtime =123456789 file2 &&
475 for type in apply pop "branch stash-branch"
477 test_must_fail git stash $type stash@{0} stash@{1} 2>err &&
478 test_i18ngrep "Too many revisions" err &&
479 test 123456789 = $(test-tool chmtime -g file2) || return 1
483 test_expect_success 'drop: too many arguments errors out (does nothing)' '
484 git stash list >expect &&
485 test_must_fail git stash drop stash@{0} stash@{1} 2>err &&
486 test_i18ngrep "Too many revisions" err &&
487 git stash list >actual &&
488 test_cmp expect actual
491 test_expect_success 'show: too many arguments errors out (does nothing)' '
492 test_must_fail git stash show stash@{0} stash@{1} 2>err 1>out &&
493 test_i18ngrep "Too many revisions" err &&
494 test_must_be_empty out
497 test_expect_success 'stash create - no changes' '
499 test_when_finished "git reset --hard HEAD" &&
501 git stash create >actual &&
502 test_must_be_empty actual
505 test_expect_success 'stash branch - no stashes on stack, stash-like argument' '
507 test_when_finished "git reset --hard HEAD" &&
510 STASH_ID=$(git stash create) &&
512 git stash branch stash-branch ${STASH_ID} &&
513 test_when_finished "git reset --hard HEAD && git checkout master &&
514 git branch -D stash-branch" &&
515 test $(git ls-files --modified | wc -l) -eq 1
518 test_expect_success 'stash branch - stashes on stack, stash-like argument' '
520 test_when_finished "git reset --hard HEAD" &&
524 test_when_finished "git stash drop" &&
526 STASH_ID=$(git stash create) &&
528 git stash branch stash-branch ${STASH_ID} &&
529 test_when_finished "git reset --hard HEAD && git checkout master &&
530 git branch -D stash-branch" &&
531 test $(git ls-files --modified | wc -l) -eq 1
534 test_expect_success 'stash branch complains with no arguments' '
535 test_must_fail git stash branch 2>err &&
536 test_i18ngrep "No branch name specified" err
539 test_expect_success 'stash show format defaults to --stat' '
541 test_when_finished "git reset --hard HEAD" &&
545 test_when_finished "git stash drop" &&
547 STASH_ID=$(git stash create) &&
549 cat >expected <<-EOF &&
551 1 file changed, 1 insertion(+)
553 git stash show ${STASH_ID} >actual &&
554 test_i18ncmp expected actual
557 test_expect_success 'stash show - stashes on stack, stash-like argument' '
559 test_when_finished "git reset --hard HEAD" &&
563 test_when_finished "git stash drop" &&
565 STASH_ID=$(git stash create) &&
567 echo "1 0 file" >expected &&
568 git stash show --numstat ${STASH_ID} >actual &&
569 test_cmp expected actual
572 test_expect_success 'stash show -p - stashes on stack, stash-like argument' '
574 test_when_finished "git reset --hard HEAD" &&
578 test_when_finished "git stash drop" &&
580 STASH_ID=$(git stash create) &&
582 cat >expected <<-EOF &&
583 diff --git a/file b/file
584 index 7601807..935fbd3 100644
591 git stash show -p ${STASH_ID} >actual &&
592 diff_cmp expected actual
595 test_expect_success 'stash show - no stashes on stack, stash-like argument' '
597 test_when_finished "git reset --hard HEAD" &&
600 STASH_ID=$(git stash create) &&
602 echo "1 0 file" >expected &&
603 git stash show --numstat ${STASH_ID} >actual &&
604 test_cmp expected actual
607 test_expect_success 'stash show -p - no stashes on stack, stash-like argument' '
609 test_when_finished "git reset --hard HEAD" &&
612 STASH_ID=$(git stash create) &&
614 cat >expected <<-EOF &&
615 diff --git a/file b/file
616 index 7601807..71b52c4 100644
623 git stash show -p ${STASH_ID} >actual &&
624 diff_cmp expected actual
627 test_expect_success 'stash show --patience shows diff' '
630 STASH_ID=$(git stash create) &&
632 cat >expected <<-EOF &&
633 diff --git a/file b/file
634 index 7601807..71b52c4 100644
641 git stash show --patience ${STASH_ID} >actual &&
642 diff_cmp expected actual
645 test_expect_success 'drop: fail early if specified stash is not a stash ref' '
647 test_when_finished "git reset --hard HEAD && git stash clear" &&
653 test_must_fail git stash drop $(git rev-parse stash@{0}) &&
655 test bar = "$(cat file)" &&
656 git reset --hard HEAD
659 test_expect_success 'pop: fail early if specified stash is not a stash ref' '
661 test_when_finished "git reset --hard HEAD && git stash clear" &&
667 test_must_fail git stash pop $(git rev-parse stash@{0}) &&
669 test bar = "$(cat file)" &&
670 git reset --hard HEAD
673 test_expect_success 'ref with non-existent reflog' '
679 test_must_fail git rev-parse --quiet --verify does-not-exist &&
680 test_must_fail git stash drop does-not-exist &&
681 test_must_fail git stash drop does-not-exist@{0} &&
682 test_must_fail git stash pop does-not-exist &&
683 test_must_fail git stash pop does-not-exist@{0} &&
684 test_must_fail git stash apply does-not-exist &&
685 test_must_fail git stash apply does-not-exist@{0} &&
686 test_must_fail git stash show does-not-exist &&
687 test_must_fail git stash show does-not-exist@{0} &&
688 test_must_fail git stash branch tmp does-not-exist &&
689 test_must_fail git stash branch tmp does-not-exist@{0} &&
693 test_expect_success 'invalid ref of the form stash@{n}, n >= N' '
695 test_must_fail git stash drop stash@{0} &&
700 test_must_fail git stash drop stash@{1} &&
701 test_must_fail git stash pop stash@{1} &&
702 test_must_fail git stash apply stash@{1} &&
703 test_must_fail git stash show stash@{1} &&
704 test_must_fail git stash branch tmp stash@{1} &&
708 test_expect_success 'invalid ref of the form "n", n >= N' '
710 test_must_fail git stash drop 0 &&
715 test_must_fail git stash drop 1 &&
716 test_must_fail git stash pop 1 &&
717 test_must_fail git stash apply 1 &&
718 test_must_fail git stash show 1 &&
719 test_must_fail git stash branch tmp 1 &&
723 test_expect_success 'valid ref of the form "n", n < N' '
730 git stash branch tmp 0 &&
731 git checkout master &&
738 test_must_fail git stash drop
741 test_expect_success 'branch: do not drop the stash if the branch exists' '
745 git commit -m initial &&
748 test_must_fail git stash branch master stash@{0} &&
749 git rev-parse stash@{0} --
752 test_expect_success 'branch: should not drop the stash if the apply fails' '
754 git reset HEAD~1 --hard &&
757 git commit -m initial &&
761 test_when_finished "git checkout master" &&
762 test_must_fail git stash branch new_branch stash@{0} &&
763 git rev-parse stash@{0} --
766 test_expect_success 'apply: show same status as git status (relative to ./)' '
768 echo 1 >subdir/subfile1 &&
769 echo 2 >subdir/subfile2 &&
770 git add subdir/subfile1 &&
771 git commit -m subdir &&
776 git status >../expect &&
778 sane_unset GIT_MERGE_VERBOSITY &&
781 sed -e 1d >actual && # drop "Saved..."
782 test_i18ncmp expect actual
786 diff --git a/HEAD b/HEAD
788 index 0000000..fe0cbee
795 test_expect_success 'stash where working directory contains "HEAD" file' '
798 echo file-not-a-ref >HEAD &&
802 git diff-files --quiet &&
803 git diff-index --cached --quiet HEAD &&
804 test "$(git rev-parse stash^)" = "$(git rev-parse HEAD)" &&
805 git diff stash^..stash >output &&
806 diff_cmp expect output
809 test_expect_success 'store called with invalid commit' '
810 test_must_fail git stash store foo
813 test_expect_success 'store updates stash ref and reflog' '
818 STASH_ID=$(git stash create) &&
820 test_path_is_missing bazzy &&
821 git stash store -m quuxery $STASH_ID &&
822 test $(git rev-parse stash) = $STASH_ID &&
823 git reflog --format=%H stash| grep $STASH_ID &&
828 test_expect_success 'handle stash specification with spaces' '
832 stamp=$(git log -g --format="%cd" -1 refs/stash) &&
836 git stash apply "stash@{$stamp}" &&
840 test_expect_success 'setup stash with index and worktree changes' '
845 echo working >file &&
849 test_expect_success 'stash list implies --first-parent -m' '
850 cat >expect <<-EOF &&
853 diff --git a/file b/file
854 index 257cc56..d26b33d 100644
861 git stash list --format=%gd -p >actual &&
862 diff_cmp expect actual
865 test_expect_success 'stash list --cc shows combined diff' '
866 cat >expect <<-\EOF &&
870 index 257cc56,9015a7a..d26b33d
873 @@@ -1,1 -1,1 +1,1 @@@
878 git stash list --format=%gd -p --cc >actual &&
879 diff_cmp expect actual
882 test_expect_success 'stash is not confused by partial renames' '
887 test_path_is_file renamed &&
888 test_path_is_missing file
891 test_expect_success 'push -m shows right message' '
894 git stash push -m "test message" &&
895 echo "stash@{0}: On master: test message" >expect &&
896 git stash list -1 >actual &&
897 test_cmp expect actual
900 test_expect_success 'push -m also works without space' '
903 git stash push -m"unspaced test message" &&
904 echo "stash@{0}: On master: unspaced test message" >expect &&
905 git stash list -1 >actual &&
906 test_cmp expect actual
909 test_expect_success 'store -m foo shows right message' '
914 STASH_ID=$(git stash create) &&
915 git stash store -m "store m" $STASH_ID &&
916 echo "stash@{0}: store m" >expect &&
917 git stash list -1 >actual &&
918 test_cmp expect actual
921 test_expect_success 'store -mfoo shows right message' '
926 STASH_ID=$(git stash create) &&
927 git stash store -m"store mfoo" $STASH_ID &&
928 echo "stash@{0}: store mfoo" >expect &&
929 git stash list -1 >actual &&
930 test_cmp expect actual
933 test_expect_success 'store --message=foo shows right message' '
938 STASH_ID=$(git stash create) &&
939 git stash store --message="store message=foo" $STASH_ID &&
940 echo "stash@{0}: store message=foo" >expect &&
941 git stash list -1 >actual &&
942 test_cmp expect actual
945 test_expect_success 'store --message foo shows right message' '
950 STASH_ID=$(git stash create) &&
951 git stash store --message "store message foo" $STASH_ID &&
952 echo "stash@{0}: store message foo" >expect &&
953 git stash list -1 >actual &&
954 test_cmp expect actual
957 test_expect_success 'push -mfoo uses right message' '
960 git stash push -m"test mfoo" &&
961 echo "stash@{0}: On master: test mfoo" >expect &&
962 git stash list -1 >actual &&
963 test_cmp expect actual
966 test_expect_success 'push --message foo is synonym for -mfoo' '
969 git stash push --message "test message foo" &&
970 echo "stash@{0}: On master: test message foo" >expect &&
971 git stash list -1 >actual &&
972 test_cmp expect actual
975 test_expect_success 'push --message=foo is synonym for -mfoo' '
978 git stash push --message="test message=foo" &&
979 echo "stash@{0}: On master: test message=foo" >expect &&
980 git stash list -1 >actual &&
981 test_cmp expect actual
984 test_expect_success 'push -m shows right message' '
987 git stash push -m "test m foo" &&
988 echo "stash@{0}: On master: test m foo" >expect &&
989 git stash list -1 >actual &&
990 test_cmp expect actual
993 test_expect_success 'create stores correct message' '
996 STASH_ID=$(git stash create "create test message") &&
997 echo "On master: create test message" >expect &&
998 git show --pretty=%s -s ${STASH_ID} >actual &&
999 test_cmp expect actual
1002 test_expect_success 'create with multiple arguments for the message' '
1005 STASH_ID=$(git stash create test untracked) &&
1006 echo "On master: test untracked" >expect &&
1007 git show --pretty=%s -s ${STASH_ID} >actual &&
1008 test_cmp expect actual
1011 test_expect_success 'create in a detached state' '
1012 test_when_finished "git checkout master" &&
1013 git checkout HEAD~1 &&
1016 STASH_ID=$(git stash create) &&
1017 HEAD_ID=$(git rev-parse --short HEAD) &&
1018 echo "WIP on (no branch): ${HEAD_ID} initial" >expect &&
1019 git show --pretty=%s -s ${STASH_ID} >actual &&
1020 test_cmp expect actual
1023 test_expect_success 'stash -- <pathspec> stashes and restores the file' '
1027 git stash push -- foo &&
1028 test_path_is_file bar &&
1029 test_path_is_missing foo &&
1031 test_path_is_file foo &&
1032 test_path_is_file bar
1035 test_expect_success 'stash -- <pathspec> stashes in subdirectory' '
1042 git stash push -- ../foo
1044 test_path_is_file bar &&
1045 test_path_is_missing foo &&
1047 test_path_is_file foo &&
1048 test_path_is_file bar
1051 test_expect_success 'stash with multiple pathspec arguments' '
1055 git add foo bar extra &&
1056 git stash push -- foo bar &&
1057 test_path_is_missing bar &&
1058 test_path_is_missing foo &&
1059 test_path_is_file extra &&
1061 test_path_is_file foo &&
1062 test_path_is_file bar &&
1063 test_path_is_file extra
1066 test_expect_success 'stash with file including $IFS character' '
1071 git stash push -- "foo b*" &&
1072 test_path_is_missing "foo bar" &&
1073 test_path_is_file foo &&
1074 test_path_is_file bar &&
1076 test_path_is_file "foo bar" &&
1077 test_path_is_file foo &&
1078 test_path_is_file bar
1081 test_expect_success 'stash with pathspec matching multiple paths' '
1082 echo original >file &&
1083 echo original >other-file &&
1084 git commit -m "two" file other-file &&
1085 echo modified >file &&
1086 echo modified >other-file &&
1087 git stash push -- "*file" &&
1088 echo original >expect &&
1089 test_cmp expect file &&
1090 test_cmp expect other-file &&
1092 echo modified >expect &&
1093 test_cmp expect file &&
1094 test_cmp expect other-file
1097 test_expect_success 'stash push -p with pathspec shows no changes only once' '
1100 git commit -m "tmp" &&
1101 git stash push -p foo >actual &&
1102 echo "No local changes to save" >expect &&
1103 git reset --hard HEAD~ &&
1104 test_i18ncmp expect actual
1107 test_expect_success 'push <pathspec>: show no changes when there are none' '
1110 git commit -m "tmp" &&
1111 git stash push 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> not in the repository errors out' '
1119 test_must_fail git stash push untracked &&
1120 test_path_is_file untracked
1123 test_expect_success 'push: -q is quiet with changes' '
1126 git stash push -q >output 2>&1 &&
1127 test_must_be_empty output
1130 test_expect_success 'push: -q is quiet with no changes' '
1131 git stash push -q >output 2>&1 &&
1132 test_must_be_empty output
1135 test_expect_success 'push: -q is quiet even if there is no initial commit' '
1137 test_when_finished rm -rf foo_dir &&
1141 test_must_fail git stash push -q >output 2>&1 &&
1142 test_must_be_empty output
1146 test_expect_success 'untracked files are left in place when -u is not given' '
1150 git stash push file &&
1151 test_path_is_file untracked
1154 test_expect_success 'stash without verb with pathspec' '
1159 git stash -- "foo b*" &&
1160 test_path_is_missing "foo bar" &&
1161 test_path_is_file foo &&
1162 test_path_is_file bar &&
1164 test_path_is_file "foo bar" &&
1165 test_path_is_file foo &&
1166 test_path_is_file bar
1169 test_expect_success 'stash -k -- <pathspec> leaves unstaged files intact' '
1174 git commit -m "test" &&
1177 git stash -k -- foo &&
1178 test "",bar = $(cat foo),$(cat bar) &&
1180 test foo,bar = $(cat foo),$(cat bar)
1183 test_expect_success 'stash -- <subdir> leaves untracked files in subdir intact' '
1185 >subdir/untracked &&
1188 git add subdir/tracked* &&
1189 git stash -- subdir/ &&
1190 test_path_is_missing subdir/tracked1 &&
1191 test_path_is_missing subdir/tracked2 &&
1192 test_path_is_file subdir/untracked &&
1194 test_path_is_file subdir/tracked1 &&
1195 test_path_is_file subdir/tracked2 &&
1196 test_path_is_file subdir/untracked
1199 test_expect_success 'stash -- <subdir> works with binary files' '
1201 >subdir/untracked &&
1203 cp "$TEST_DIRECTORY"/test-binary-1.png subdir/tracked-binary &&
1204 git add subdir/tracked* &&
1205 git stash -- subdir/ &&
1206 test_path_is_missing subdir/tracked &&
1207 test_path_is_missing subdir/tracked-binary &&
1208 test_path_is_file subdir/untracked &&
1210 test_path_is_file subdir/tracked &&
1211 test_path_is_file subdir/tracked-binary &&
1212 test_path_is_file subdir/untracked
1215 test_expect_success 'stash with user.name and user.email set works' '
1216 test_config user.name "A U Thor" &&
1217 test_config user.email "a.u@thor" &&
1221 test_expect_success 'stash works when user.name and user.email are not set' '
1225 echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" >expect &&
1227 git show -s --format="%an <%ae>" refs/stash >actual &&
1228 test_cmp expect actual &&
1231 test_config user.useconfigonly true &&
1232 test_config stash.usebuiltin true &&
1234 sane_unset GIT_AUTHOR_NAME &&
1235 sane_unset GIT_AUTHOR_EMAIL &&
1236 sane_unset GIT_COMMITTER_NAME &&
1237 sane_unset GIT_COMMITTER_EMAIL &&
1238 test_unconfig user.email &&
1239 test_unconfig user.name &&
1240 test_must_fail git commit -m "should fail" &&
1241 echo "git stash <git@stash>" >expect &&
1244 git show -s --format="%an <%ae>" refs/stash >actual &&
1245 test_cmp expect actual
1249 test_expect_success 'stash --keep-index with file deleted in index does not resurrect it on disk' '
1250 test_commit to-remove to-remove &&
1252 git stash --keep-index &&
1253 test_path_is_missing to-remove
1256 test_expect_success 'stash apply should succeed with unmodified file' '
1259 git commit -m base &&
1261 # now stash a modification
1262 echo modified >file &&
1265 # make the file stat dirty
1272 test_expect_success 'stash handles skip-worktree entries nicely' '
1274 echo changed >A.t &&
1276 git update-index --skip-worktree A.t &&
1280 git rev-parse --verify refs/stash:A.t