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
16 sed -e 's/^index 0000000\.\.[0-9a-f]*/index 0000000..1234567/' \
17 -e 's/^index [0-9a-f]*\.\.[0-9a-f]*/index 1234567..89abcde/' \
18 -e 's/^index [0-9a-f]*,[0-9a-f]*\.\.[0-9a-f]*/index 1234567,7654321..89abcde/' \
19 "$i" >"$i.compare" ||
return 1
21 test_cmp
"$1.compare" "$2.compare" &&
22 rm -f "$1.compare" "$2.compare"
25 test_expect_success
'stash some dirty working directory' '
28 echo unrelated >other-file &&
31 git commit -m initial &&
37 git diff-files --quiet &&
38 git diff-index --cached --quiet HEAD
42 diff --git a/file b/file
43 index 0cfbf08..00750ed 100644
51 test_expect_success
'parents of stash' '
52 test $(git rev-parse stash^) = $(git rev-parse HEAD) &&
53 git diff stash^2..stash >output &&
54 diff_cmp expect output
57 test_expect_success
'applying bogus stash does nothing' '
58 test_must_fail git stash apply stash@{1} &&
63 test_expect_success
'apply does not need clean working directory' '
70 test_expect_success
'apply does not clobber working directory changes' '
73 test_must_fail git stash apply &&
78 test_expect_success
'apply stashed changes' '
83 git commit -m other-file &&
85 test 3 = $(cat file) &&
86 test 1 = $(git show :file) &&
87 test 1 = $(git show HEAD:file)
90 test_expect_success
'apply stashed changes (including index)' '
91 git reset --hard HEAD^ &&
95 git commit -m other-file &&
96 git stash apply --index &&
97 test 3 = $(cat file) &&
98 test 2 = $(git show :file) &&
99 test 1 = $(git show HEAD:file)
102 test_expect_success
'unstashing in a subdirectory' '
103 git reset --hard HEAD &&
111 test_expect_success
'stash drop complains of extra options' '
112 test_must_fail git stash drop --foo
115 test_expect_success
'drop top stash' '
117 git stash list >expected &&
121 git stash list >actual &&
122 test_cmp expected actual &&
124 test 3 = $(cat file) &&
125 test 1 = $(git show :file) &&
126 test 1 = $(git show HEAD:file)
129 test_expect_success
'drop middle stash' '
135 git stash drop stash@{1} &&
136 test 2 = $(git stash list | wc -l) &&
138 test 9 = $(cat file) &&
139 test 1 = $(git show :file) &&
140 test 1 = $(git show HEAD:file) &&
144 test 3 = $(cat file) &&
145 test 1 = $(git show :file) &&
146 test 1 = $(git show HEAD:file)
149 test_expect_success
'drop middle stash by index' '
156 test 2 = $(git stash list | wc -l) &&
158 test 9 = $(cat file) &&
159 test 1 = $(git show :file) &&
160 test 1 = $(git show HEAD:file) &&
164 test 3 = $(cat file) &&
165 test 1 = $(git show :file) &&
166 test 1 = $(git show HEAD:file)
169 test_expect_success
'stash pop' '
172 test 3 = $(cat file) &&
173 test 1 = $(git show :file) &&
174 test 1 = $(git show HEAD:file) &&
175 test 0 = $(git stash list | wc -l)
179 diff --git a/file2 b/file2
181 index 0000000..1fe912c
189 diff --git a/file b/file
190 index 257cc56..5716ca5 100644
199 diff --git a/file b/file
200 index 7601807..5716ca5 100644
206 diff --git a/file2 b/file2
208 index 0000000..1fe912c
215 test_expect_success
'stash branch' '
217 git commit file -m first &&
223 git commit file -m second &&
224 git stash branch stashbranch &&
225 test refs/heads/stashbranch = $(git symbolic-ref HEAD) &&
226 test $(git rev-parse HEAD) = $(git rev-parse main^) &&
227 git diff --cached >output &&
228 diff_cmp expect output &&
230 diff_cmp expect1 output &&
232 git commit -m alternate\ second &&
233 git diff main..stashbranch >output &&
234 diff_cmp output expect2 &&
235 test 0 = $(git stash list | wc -l)
238 test_expect_success
'apply -q is quiet' '
241 git stash apply -q >output.out 2>&1 &&
242 test_must_be_empty output.out
245 test_expect_success
'save -q is quiet' '
246 git stash save --quiet >output.out 2>&1 &&
247 test_must_be_empty output.out
250 test_expect_success
'pop -q works and is quiet' '
251 git stash pop -q >output.out 2>&1 &&
253 git show :file >actual &&
254 test_cmp expect actual &&
255 test_must_be_empty output.out
258 test_expect_success
'pop -q --index works and is quiet' '
261 git stash save --quiet &&
262 git stash pop -q --index >output.out 2>&1 &&
263 git diff-files file2 >file2.diff &&
264 test_must_be_empty file2.diff &&
265 test foo = "$(git show :file)" &&
266 test_must_be_empty output.out
269 test_expect_success
'drop -q is quiet' '
271 git stash drop -q >output.out 2>&1 &&
272 test_must_be_empty output.out
275 test_expect_success
'stash -k' '
280 test bar,bar4 = $(cat file),$(cat file2)
283 test_expect_success
'stash --no-keep-index' '
287 git stash --no-keep-index &&
288 test bar,bar2 = $(cat file),$(cat file2)
291 test_expect_success
'stash --staged' '
295 git stash --staged &&
296 test bar3,bar2 = $(cat file),$(cat file2) &&
299 test bar,bar4 = $(cat file),$(cat file2)
302 test_expect_success
'dont assume push with non-option args' '
303 test_must_fail git stash -q drop 2>err &&
304 test_i18ngrep -e "subcommand wasn'\''t specified; '\''push'\'' can'\''t be assumed due to unexpected token '\''drop'\''" err
307 test_expect_success
'stash --invalid-option' '
311 test_must_fail git stash --invalid-option &&
312 test_must_fail git stash save --invalid-option &&
313 test bar5,bar6 = $(cat file),$(cat file2)
316 test_expect_success
'stash an added file' '
320 git stash save "added file" &&
323 test new = "$(cat file3)"
326 test_expect_success
'stash --intent-to-add file' '
329 git add --intent-to-add file4 &&
330 test_when_finished "git rm -f file4" &&
331 test_must_fail git stash
334 test_expect_success
'stash rm then recreate' '
338 git stash save "rm then recreate" &&
339 test bar = "$(cat file)" &&
341 test bar7 = "$(cat file)"
344 test_expect_success
'stash rm and ignore' '
347 echo file >.gitignore &&
348 git stash save "rm and ignore" &&
349 test bar = "$(cat file)" &&
350 test file = "$(cat .gitignore)" &&
353 test file = "$(cat .gitignore)"
356 test_expect_success
'stash rm and ignore (stage .gitignore)' '
359 echo file >.gitignore &&
360 git add .gitignore &&
361 git stash save "rm and ignore (stage .gitignore)" &&
362 test bar = "$(cat file)" &&
363 ! test -r .gitignore &&
366 test file = "$(cat .gitignore)"
369 test_expect_success SYMLINKS
'stash file to symlink' '
373 git stash save "file to symlink" &&
375 test bar = "$(cat file)" &&
377 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
380 test_expect_success SYMLINKS
'stash file to symlink (stage rm)' '
384 git stash save "file to symlink (stage rm)" &&
386 test bar = "$(cat file)" &&
388 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
391 test_expect_success SYMLINKS
'stash file to symlink (full stage)' '
396 git stash save "file to symlink (full stage)" &&
398 test bar = "$(cat file)" &&
400 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
403 # This test creates a commit with a symlink used for the following tests
405 test_expect_success
'stash symlink to file' '
407 test_ln_s_add file filelink &&
408 git commit -m "Add symlink" &&
411 git stash save "symlink to file"
414 test_expect_success SYMLINKS
'this must have re-created the symlink' '
416 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
419 test_expect_success
'unstash must re-create the file' '
421 ! test -h filelink &&
422 test bar = "$(cat file)"
425 test_expect_success
'stash symlink to file (stage rm)' '
429 git stash save "symlink to file (stage rm)"
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_success
'stash symlink to file (full stage)' '
448 git stash save "symlink to file (full stage)"
451 test_expect_success SYMLINKS
'this must have re-created the symlink' '
453 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
456 test_expect_success
'unstash must re-create the file' '
458 ! test -h filelink &&
459 test bar = "$(cat file)"
462 test_expect_failure
'stash directory to file' '
465 echo foo >dir/file &&
467 git commit -m "Add file in dir" &&
470 git stash save "directory to file" &&
472 test foo = "$(cat dir/file)" &&
473 test_must_fail git stash apply &&
474 test bar = "$(cat dir)" &&
475 git reset --soft HEAD^
478 test_expect_failure
'stash file to directory' '
482 echo foo >file/file &&
483 git stash save "file to directory" &&
485 test bar = "$(cat file)" &&
488 test foo = "$(cat file/file)"
491 test_expect_success
'giving too many ref arguments does not modify files' '
493 test_when_finished "git reset --hard HEAD" &&
498 test-tool chmtime =123456789 file2 &&
499 for type in apply pop "branch stash-branch"
501 test_must_fail git stash $type stash@{0} stash@{1} 2>err &&
502 test_i18ngrep "Too many revisions" err &&
503 test 123456789 = $(test-tool chmtime -g file2) || return 1
507 test_expect_success
'drop: too many arguments errors out (does nothing)' '
508 git stash list >expect &&
509 test_must_fail git stash drop stash@{0} stash@{1} 2>err &&
510 test_i18ngrep "Too many revisions" err &&
511 git stash list >actual &&
512 test_cmp expect actual
515 test_expect_success
'show: too many arguments errors out (does nothing)' '
516 test_must_fail git stash show stash@{0} stash@{1} 2>err 1>out &&
517 test_i18ngrep "Too many revisions" err &&
518 test_must_be_empty out
521 test_expect_success
'stash create - no changes' '
523 test_when_finished "git reset --hard HEAD" &&
525 git stash create >actual &&
526 test_must_be_empty actual
529 test_expect_success
'stash branch - no stashes on stack, stash-like argument' '
531 test_when_finished "git reset --hard HEAD" &&
534 STASH_ID=$(git stash create) &&
536 git stash branch stash-branch ${STASH_ID} &&
537 test_when_finished "git reset --hard HEAD && git checkout main &&
538 git branch -D stash-branch" &&
539 test $(git ls-files --modified | wc -l) -eq 1
542 test_expect_success
'stash branch - stashes on stack, stash-like argument' '
544 test_when_finished "git reset --hard HEAD" &&
548 test_when_finished "git stash drop" &&
550 STASH_ID=$(git stash create) &&
552 git stash branch stash-branch ${STASH_ID} &&
553 test_when_finished "git reset --hard HEAD && git checkout main &&
554 git branch -D stash-branch" &&
555 test $(git ls-files --modified | wc -l) -eq 1
558 test_expect_success
'stash branch complains with no arguments' '
559 test_must_fail git stash branch 2>err &&
560 test_i18ngrep "No branch name specified" err
563 test_expect_success
'stash show format defaults to --stat' '
565 test_when_finished "git reset --hard HEAD" &&
569 test_when_finished "git stash drop" &&
571 STASH_ID=$(git stash create) &&
573 cat >expected <<-EOF &&
575 1 file changed, 1 insertion(+)
577 git stash show ${STASH_ID} >actual &&
578 test_cmp expected actual
581 test_expect_success
'stash show - stashes on stack, stash-like argument' '
583 test_when_finished "git reset --hard HEAD" &&
587 test_when_finished "git stash drop" &&
589 STASH_ID=$(git stash create) &&
591 echo "1 0 file" >expected &&
592 git stash show --numstat ${STASH_ID} >actual &&
593 test_cmp expected actual
596 test_expect_success
'stash show -p - stashes on stack, stash-like argument' '
598 test_when_finished "git reset --hard HEAD" &&
602 test_when_finished "git stash drop" &&
604 STASH_ID=$(git stash create) &&
606 cat >expected <<-EOF &&
607 diff --git a/file b/file
608 index 7601807..935fbd3 100644
615 git stash show -p ${STASH_ID} >actual &&
616 diff_cmp expected actual
619 test_expect_success
'stash show - no stashes on stack, stash-like argument' '
621 test_when_finished "git reset --hard HEAD" &&
624 STASH_ID=$(git stash create) &&
626 echo "1 0 file" >expected &&
627 git stash show --numstat ${STASH_ID} >actual &&
628 test_cmp expected actual
631 test_expect_success
'stash show -p - no stashes on stack, stash-like argument' '
633 test_when_finished "git reset --hard HEAD" &&
636 STASH_ID=$(git stash create) &&
638 cat >expected <<-EOF &&
639 diff --git a/file b/file
640 index 7601807..71b52c4 100644
647 git stash show -p ${STASH_ID} >actual &&
648 diff_cmp expected actual
651 test_expect_success
'stash show --patience shows diff' '
654 STASH_ID=$(git stash create) &&
656 cat >expected <<-EOF &&
657 diff --git a/file b/file
658 index 7601807..71b52c4 100644
665 git stash show --patience ${STASH_ID} >actual &&
666 diff_cmp expected actual
669 test_expect_success
'drop: 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 drop $(git rev-parse stash@{0}) &&
679 test bar = "$(cat file)" &&
680 git reset --hard HEAD
683 test_expect_success
'pop: fail early if specified stash is not a stash ref' '
685 test_when_finished "git reset --hard HEAD && git stash clear" &&
691 test_must_fail git stash pop $(git rev-parse stash@{0}) &&
693 test bar = "$(cat file)" &&
694 git reset --hard HEAD
697 test_expect_success
'ref with non-existent reflog' '
703 test_must_fail git rev-parse --quiet --verify does-not-exist &&
704 test_must_fail git stash drop does-not-exist &&
705 test_must_fail git stash drop does-not-exist@{0} &&
706 test_must_fail git stash pop does-not-exist &&
707 test_must_fail git stash pop does-not-exist@{0} &&
708 test_must_fail git stash apply does-not-exist &&
709 test_must_fail git stash apply does-not-exist@{0} &&
710 test_must_fail git stash show does-not-exist &&
711 test_must_fail git stash show does-not-exist@{0} &&
712 test_must_fail git stash branch tmp does-not-exist &&
713 test_must_fail git stash branch tmp does-not-exist@{0} &&
717 test_expect_success
'invalid ref of the form stash@{n}, n >= N' '
719 test_must_fail git stash drop stash@{0} &&
724 test_must_fail git stash drop stash@{1} &&
725 test_must_fail git stash pop stash@{1} &&
726 test_must_fail git stash apply stash@{1} &&
727 test_must_fail git stash show stash@{1} &&
728 test_must_fail git stash branch tmp stash@{1} &&
732 test_expect_success
'invalid ref of the form "n", n >= N' '
734 test_must_fail git stash drop 0 &&
739 test_must_fail git stash drop 1 &&
740 test_must_fail git stash pop 1 &&
741 test_must_fail git stash apply 1 &&
742 test_must_fail git stash show 1 &&
743 test_must_fail git stash branch tmp 1 &&
747 test_expect_success
'valid ref of the form "n", n < N' '
754 git stash branch tmp 0 &&
762 test_must_fail git stash drop
765 test_expect_success
'branch: do not drop the stash if the branch exists' '
769 git commit -m initial &&
772 test_must_fail git stash branch main stash@{0} &&
773 git rev-parse stash@{0} --
776 test_expect_success
'branch: should not drop the stash if the apply fails' '
778 git reset HEAD~1 --hard &&
781 git commit -m initial &&
785 test_when_finished "git checkout main" &&
786 test_must_fail git stash branch new_branch stash@{0} &&
787 git rev-parse stash@{0} --
790 test_expect_success
'apply: show same status as git status (relative to ./)' '
792 echo 1 >subdir/subfile1 &&
793 echo 2 >subdir/subfile2 &&
794 git add subdir/subfile1 &&
795 git commit -m subdir &&
800 git status >../expect &&
802 sane_unset GIT_MERGE_VERBOSITY &&
805 sed -e 1d >actual && # drop "Saved..."
806 test_cmp expect actual
810 diff --git a/HEAD b/HEAD
812 index 0000000..fe0cbee
819 test_expect_success
'stash where working directory contains "HEAD" file' '
822 echo file-not-a-ref >HEAD &&
826 git diff-files --quiet &&
827 git diff-index --cached --quiet HEAD &&
828 test "$(git rev-parse stash^)" = "$(git rev-parse HEAD)" &&
829 git diff stash^..stash >output &&
830 diff_cmp expect output
833 test_expect_success
'store called with invalid commit' '
834 test_must_fail git stash store foo
837 test_expect_success
'store updates stash ref and reflog' '
842 STASH_ID=$(git stash create) &&
844 test_path_is_missing bazzy &&
845 git stash store -m quuxery $STASH_ID &&
846 test $(git rev-parse stash) = $STASH_ID &&
847 git reflog --format=%H stash| grep $STASH_ID &&
852 test_expect_success
'handle stash specification with spaces' '
856 stamp=$(git log -g --format="%cd" -1 refs/stash) &&
860 git stash apply "stash@{$stamp}" &&
864 test_expect_success
'setup stash with index and worktree changes' '
869 echo working >file &&
873 test_expect_success
'stash list -p shows simple diff' '
874 cat >expect <<-EOF &&
877 diff --git a/file b/file
878 index 257cc56..d26b33d 100644
885 git stash list --format=%gd -p >actual &&
886 diff_cmp expect actual
889 test_expect_success
'stash list --cc shows combined diff' '
890 cat >expect <<-\EOF &&
894 index 257cc56,9015a7a..d26b33d
897 @@@ -1,1 -1,1 +1,1 @@@
902 git stash list --format=%gd -p --cc >actual &&
903 diff_cmp expect actual
906 test_expect_success
'stash is not confused by partial renames' '
911 test_path_is_file renamed &&
912 test_path_is_missing file
915 test_expect_success
'push -m shows right message' '
918 git stash push -m "test message" &&
919 echo "stash@{0}: On main: test message" >expect &&
920 git stash list -1 >actual &&
921 test_cmp expect actual
924 test_expect_success
'push -m also works without space' '
927 git stash push -m"unspaced test message" &&
928 echo "stash@{0}: On main: unspaced test message" >expect &&
929 git stash list -1 >actual &&
930 test_cmp expect actual
933 test_expect_success
'store -m foo shows right message' '
938 STASH_ID=$(git stash create) &&
939 git stash store -m "store m" $STASH_ID &&
940 echo "stash@{0}: store m" >expect &&
941 git stash list -1 >actual &&
942 test_cmp expect actual
945 test_expect_success
'store -mfoo shows right message' '
950 STASH_ID=$(git stash create) &&
951 git stash store -m"store mfoo" $STASH_ID &&
952 echo "stash@{0}: store mfoo" >expect &&
953 git stash list -1 >actual &&
954 test_cmp expect actual
957 test_expect_success
'store --message=foo shows right message' '
962 STASH_ID=$(git stash create) &&
963 git stash store --message="store message=foo" $STASH_ID &&
964 echo "stash@{0}: store message=foo" >expect &&
965 git stash list -1 >actual &&
966 test_cmp expect actual
969 test_expect_success
'store --message foo shows right message' '
974 STASH_ID=$(git stash create) &&
975 git stash store --message "store message foo" $STASH_ID &&
976 echo "stash@{0}: store message foo" >expect &&
977 git stash list -1 >actual &&
978 test_cmp expect actual
981 test_expect_success
'push -mfoo uses right message' '
984 git stash push -m"test mfoo" &&
985 echo "stash@{0}: On main: test mfoo" >expect &&
986 git stash list -1 >actual &&
987 test_cmp expect actual
990 test_expect_success
'push --message foo is synonym for -mfoo' '
993 git stash push --message "test message foo" &&
994 echo "stash@{0}: On main: test message foo" >expect &&
995 git stash list -1 >actual &&
996 test_cmp expect actual
999 test_expect_success
'push --message=foo is synonym for -mfoo' '
1002 git stash push --message="test message=foo" &&
1003 echo "stash@{0}: On main: test message=foo" >expect &&
1004 git stash list -1 >actual &&
1005 test_cmp expect actual
1008 test_expect_success
'push -m shows right message' '
1011 git stash push -m "test m foo" &&
1012 echo "stash@{0}: On main: test m foo" >expect &&
1013 git stash list -1 >actual &&
1014 test_cmp expect actual
1017 test_expect_success
'create stores correct message' '
1020 STASH_ID=$(git stash create "create test message") &&
1021 echo "On main: create test message" >expect &&
1022 git show --pretty=%s -s ${STASH_ID} >actual &&
1023 test_cmp expect actual
1026 test_expect_success
'create with multiple arguments for the message' '
1029 STASH_ID=$(git stash create test untracked) &&
1030 echo "On main: test untracked" >expect &&
1031 git show --pretty=%s -s ${STASH_ID} >actual &&
1032 test_cmp expect actual
1035 test_expect_success
'create in a detached state' '
1036 test_when_finished "git checkout main" &&
1037 git checkout HEAD~1 &&
1040 STASH_ID=$(git stash create) &&
1041 HEAD_ID=$(git rev-parse --short HEAD) &&
1042 echo "WIP on (no branch): ${HEAD_ID} initial" >expect &&
1043 git show --pretty=%s -s ${STASH_ID} >actual &&
1044 test_cmp expect actual
1047 test_expect_success
'stash -- <pathspec> stashes and restores the file' '
1051 git stash push -- foo &&
1052 test_path_is_file bar &&
1053 test_path_is_missing foo &&
1055 test_path_is_file foo &&
1056 test_path_is_file bar
1059 test_expect_success
'stash -- <pathspec> stashes in subdirectory' '
1066 git stash push -- ../foo
1068 test_path_is_file bar &&
1069 test_path_is_missing foo &&
1071 test_path_is_file foo &&
1072 test_path_is_file bar
1075 test_expect_success
'stash with multiple pathspec arguments' '
1079 git add foo bar extra &&
1080 git stash push -- foo bar &&
1081 test_path_is_missing bar &&
1082 test_path_is_missing foo &&
1083 test_path_is_file extra &&
1085 test_path_is_file foo &&
1086 test_path_is_file bar &&
1087 test_path_is_file extra
1090 test_expect_success
'stash with file including $IFS character' '
1095 git stash push -- "foo b*" &&
1096 test_path_is_missing "foo bar" &&
1097 test_path_is_file foo &&
1098 test_path_is_file bar &&
1100 test_path_is_file "foo bar" &&
1101 test_path_is_file foo &&
1102 test_path_is_file bar
1105 test_expect_success
'stash with pathspec matching multiple paths' '
1106 echo original >file &&
1107 echo original >other-file &&
1108 git commit -m "two" file other-file &&
1109 echo modified >file &&
1110 echo modified >other-file &&
1111 git stash push -- "*file" &&
1112 echo original >expect &&
1113 test_cmp expect file &&
1114 test_cmp expect other-file &&
1116 echo modified >expect &&
1117 test_cmp expect file &&
1118 test_cmp expect other-file
1121 test_expect_success
'stash push -p with pathspec shows no changes only once' '
1124 git commit -m "tmp" &&
1125 git stash push -p foo >actual &&
1126 echo "No local changes to save" >expect &&
1127 git reset --hard HEAD~ &&
1128 test_cmp expect actual
1131 test_expect_success
'push <pathspec>: show no changes when there are none' '
1134 git commit -m "tmp" &&
1135 git stash push foo >actual &&
1136 echo "No local changes to save" >expect &&
1137 git reset --hard HEAD~ &&
1138 test_cmp expect actual
1141 test_expect_success
'push: <pathspec> not in the repository errors out' '
1143 test_must_fail git stash push untracked &&
1144 test_path_is_file untracked
1147 test_expect_success
'push: -q is quiet with changes' '
1150 git stash push -q >output 2>&1 &&
1151 test_must_be_empty output
1154 test_expect_success
'push: -q is quiet with no changes' '
1155 git stash push -q >output 2>&1 &&
1156 test_must_be_empty output
1159 test_expect_success
'push: -q is quiet even if there is no initial commit' '
1161 test_when_finished rm -rf foo_dir &&
1165 test_must_fail git stash push -q >output 2>&1 &&
1166 test_must_be_empty output
1170 test_expect_success
'untracked files are left in place when -u is not given' '
1174 git stash push file &&
1175 test_path_is_file untracked
1178 test_expect_success
'stash without verb with pathspec' '
1183 git stash -- "foo b*" &&
1184 test_path_is_missing "foo bar" &&
1185 test_path_is_file foo &&
1186 test_path_is_file bar &&
1188 test_path_is_file "foo bar" &&
1189 test_path_is_file foo &&
1190 test_path_is_file bar
1193 test_expect_success
'stash -k -- <pathspec> leaves unstaged files intact' '
1198 git commit -m "test" &&
1201 git stash -k -- foo &&
1202 test "",bar = $(cat foo),$(cat bar) &&
1204 test foo,bar = $(cat foo),$(cat bar)
1207 test_expect_success
'stash -- <subdir> leaves untracked files in subdir intact' '
1209 >subdir/untracked &&
1212 git add subdir/tracked* &&
1213 git stash -- subdir/ &&
1214 test_path_is_missing subdir/tracked1 &&
1215 test_path_is_missing subdir/tracked2 &&
1216 test_path_is_file subdir/untracked &&
1218 test_path_is_file subdir/tracked1 &&
1219 test_path_is_file subdir/tracked2 &&
1220 test_path_is_file subdir/untracked
1223 test_expect_success
'stash -- <subdir> works with binary files' '
1225 >subdir/untracked &&
1227 cp "$TEST_DIRECTORY"/test-binary-1.png subdir/tracked-binary &&
1228 git add subdir/tracked* &&
1229 git stash -- subdir/ &&
1230 test_path_is_missing subdir/tracked &&
1231 test_path_is_missing subdir/tracked-binary &&
1232 test_path_is_file subdir/untracked &&
1234 test_path_is_file subdir/tracked &&
1235 test_path_is_file subdir/tracked-binary &&
1236 test_path_is_file subdir/untracked
1239 test_expect_success
'stash with user.name and user.email set works' '
1240 test_config user.name "A U Thor" &&
1241 test_config user.email "a.u@thor" &&
1245 test_expect_success
'stash works when user.name and user.email are not set' '
1249 echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" >expect &&
1251 git show -s --format="%an <%ae>" refs/stash >actual &&
1252 test_cmp expect actual &&
1255 test_config user.useconfigonly true &&
1256 test_config stash.usebuiltin true &&
1258 sane_unset GIT_AUTHOR_NAME &&
1259 sane_unset GIT_AUTHOR_EMAIL &&
1260 sane_unset GIT_COMMITTER_NAME &&
1261 sane_unset GIT_COMMITTER_EMAIL &&
1262 test_unconfig user.email &&
1263 test_unconfig user.name &&
1264 test_must_fail git commit -m "should fail" &&
1265 echo "git stash <git@stash>" >expect &&
1268 git show -s --format="%an <%ae>" refs/stash >actual &&
1269 test_cmp expect actual
1273 test_expect_success
'stash --keep-index with file deleted in index does not resurrect it on disk' '
1274 test_commit to-remove to-remove &&
1276 git stash --keep-index &&
1277 test_path_is_missing to-remove
1280 test_expect_success
'stash apply should succeed with unmodified file' '
1283 git commit -m base &&
1285 # now stash a modification
1286 echo modified >file &&
1289 # make the file stat dirty
1296 test_expect_success
'stash handles skip-worktree entries nicely' '
1298 echo changed >A.t &&
1300 git update-index --skip-worktree A.t &&
1304 git rev-parse --verify refs/stash:A.t
1307 test_expect_success
'stash -c stash.useBuiltin=false warning ' '
1308 expected="stash.useBuiltin support has been removed" &&
1310 git -c stash.useBuiltin=false stash 2>err &&
1311 test_i18ngrep "$expected" err &&
1312 env GIT_TEST_STASH_USE_BUILTIN=false git stash 2>err &&
1313 test_i18ngrep "$expected" err &&
1315 git -c stash.useBuiltin=true stash 2>err &&
1316 test_must_be_empty err &&
1317 env GIT_TEST_STASH_USE_BUILTIN=true git stash 2>err &&
1318 test_must_be_empty err
1321 test_expect_success
'git stash succeeds despite directory/file change' '
1322 test_create_repo directory_file_switch_v1 &&
1324 cd directory_file_switch_v1 &&
1327 test_write_lines this file has some words >filler &&
1329 git commit -m filler &&
1333 echo contents >filler/file &&
1338 test_expect_success
'git stash can pop file -> directory saved changes' '
1339 test_create_repo directory_file_switch_v2 &&
1341 cd directory_file_switch_v2 &&
1344 test_write_lines this file has some words >filler &&
1346 git commit -m filler &&
1350 echo contents >filler/file &&
1351 cp filler/file expect &&
1352 git stash push --include-untracked &&
1353 git stash apply --index &&
1354 test_cmp expect filler/file
1358 test_expect_success
'git stash can pop directory -> file saved changes' '
1359 test_create_repo directory_file_switch_v3 &&
1361 cd directory_file_switch_v3 &&
1365 test_write_lines some words >filler/file1 &&
1366 test_write_lines and stuff >filler/file2 &&
1368 git commit -m filler &&
1370 git rm -rf filler &&
1371 echo contents >filler &&
1373 git stash push --include-untracked &&
1374 git stash apply --index &&
1375 test_cmp expect filler