]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3903-stash.sh
stash: strip "refs/heads/" with skip_prefix
[thirdparty/git.git] / t / t3903-stash.sh
CommitLineData
150937c4
JS
1#!/bin/sh
2#
3# Copyright (c) 2007 Johannes E Schindelin
4#
5
0cb0e143 6test_description='Test git stash'
150937c4 7
cbc75a12 8GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
9export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
150937c4
JS
11. ./test-lib.sh
12
ca7990ce
ÆAB
13test_expect_success 'usage on cmd and subcommand invalid option' '
14 test_expect_code 129 git stash --invalid-option 2>usage &&
15 grep "or: git stash" usage &&
16
17 test_expect_code 129 git stash push --invalid-option 2>usage &&
18 ! grep "or: git stash" usage
19'
20
21test_expect_success 'usage on main command -h emits a summary of subcommands' '
22 test_expect_code 129 git stash -h >usage &&
23 grep -F "usage: git stash list" usage &&
24 grep -F "or: git stash show" usage
25'
26
27test_expect_failure 'usage for subcommands should emit subcommand usage' '
28 test_expect_code 129 git stash push -h >usage &&
29 grep -F "usage: git stash [push" usage
30'
31
c7848150 32diff_cmp () {
33 for i in "$1" "$2"
34 do
35 sed -e 's/^index 0000000\.\.[0-9a-f]*/index 0000000..1234567/' \
36 -e 's/^index [0-9a-f]*\.\.[0-9a-f]*/index 1234567..89abcde/' \
37 -e 's/^index [0-9a-f]*,[0-9a-f]*\.\.[0-9a-f]*/index 1234567,7654321..89abcde/' \
38 "$i" >"$i.compare" || return 1
39 done &&
40 test_cmp "$1.compare" "$2.compare" &&
41 rm -f "$1.compare" "$2.compare"
42}
43
150937c4 44test_expect_success 'stash some dirty working directory' '
6a0b88b2 45 echo 1 >file &&
150937c4 46 git add file &&
88bab59c
JK
47 echo unrelated >other-file &&
48 git add other-file &&
150937c4
JS
49 test_tick &&
50 git commit -m initial &&
6a0b88b2 51 echo 2 >file &&
150937c4 52 git add file &&
6a0b88b2 53 echo 3 >file &&
150937c4
JS
54 test_tick &&
55 git stash &&
56 git diff-files --quiet &&
57 git diff-index --cached --quiet HEAD
58'
59
6a0b88b2 60cat >expect <<EOF
150937c4
JS
61diff --git a/file b/file
62index 0cfbf08..00750ed 100644
63--- a/file
64+++ b/file
65@@ -1 +1 @@
66-2
67+3
68EOF
69
70test_expect_success 'parents of stash' '
71 test $(git rev-parse stash^) = $(git rev-parse HEAD) &&
6a0b88b2 72 git diff stash^2..stash >output &&
c7848150 73 diff_cmp expect output
150937c4
JS
74'
75
59d418fe
JK
76test_expect_success 'applying bogus stash does nothing' '
77 test_must_fail git stash apply stash@{1} &&
78 echo 1 >expect &&
79 test_cmp expect file
80'
81
e0e2a9cb
JK
82test_expect_success 'apply does not need clean working directory' '
83 echo 4 >other-file &&
e0e2a9cb
JK
84 git stash apply &&
85 echo 3 >expect &&
86 test_cmp expect file
87'
88
89test_expect_success 'apply does not clobber working directory changes' '
90 git reset --hard &&
91 echo 4 >file &&
92 test_must_fail git stash apply &&
93 echo 4 >expect &&
94 test_cmp expect file
150937c4
JS
95'
96
97test_expect_success 'apply stashed changes' '
e0e2a9cb
JK
98 git reset --hard &&
99 echo 5 >other-file &&
150937c4
JS
100 git add other-file &&
101 test_tick &&
102 git commit -m other-file &&
103 git stash apply &&
104 test 3 = $(cat file) &&
105 test 1 = $(git show :file) &&
106 test 1 = $(git show HEAD:file)
107'
108
109test_expect_success 'apply stashed changes (including index)' '
110 git reset --hard HEAD^ &&
6a0b88b2 111 echo 6 >other-file &&
150937c4
JS
112 git add other-file &&
113 test_tick &&
114 git commit -m other-file &&
115 git stash apply --index &&
116 test 3 = $(cat file) &&
117 test 2 = $(git show :file) &&
118 test 1 = $(git show HEAD:file)
119'
120
ceff079b
JH
121test_expect_success 'unstashing in a subdirectory' '
122 git reset --hard HEAD &&
123 mkdir subdir &&
18a82692
JN
124 (
125 cd subdir &&
126 git stash apply
fd4ec4f2 127 )
b683c080
BC
128'
129
d6cc2df5
JK
130test_expect_success 'stash drop complains of extra options' '
131 test_must_fail git stash drop --foo
132'
133
b683c080
BC
134test_expect_success 'drop top stash' '
135 git reset --hard &&
6a0b88b2
PSU
136 git stash list >expected &&
137 echo 7 >file &&
b683c080
BC
138 git stash &&
139 git stash drop &&
6a0b88b2
PSU
140 git stash list >actual &&
141 test_cmp expected actual &&
b683c080
BC
142 git stash apply &&
143 test 3 = $(cat file) &&
144 test 1 = $(git show :file) &&
145 test 1 = $(git show HEAD:file)
146'
147
148test_expect_success 'drop middle stash' '
149 git reset --hard &&
6a0b88b2 150 echo 8 >file &&
b683c080 151 git stash &&
6a0b88b2 152 echo 9 >file &&
b683c080
BC
153 git stash &&
154 git stash drop stash@{1} &&
155 test 2 = $(git stash list | wc -l) &&
156 git stash apply &&
157 test 9 = $(cat file) &&
158 test 1 = $(git show :file) &&
159 test 1 = $(git show HEAD:file) &&
160 git reset --hard &&
161 git stash drop &&
162 git stash apply &&
163 test 3 = $(cat file) &&
164 test 1 = $(git show :file) &&
165 test 1 = $(git show HEAD:file)
166'
167
a56c8f5a
AW
168test_expect_success 'drop middle stash by index' '
169 git reset --hard &&
170 echo 8 >file &&
171 git stash &&
172 echo 9 >file &&
173 git stash &&
174 git stash drop 1 &&
175 test 2 = $(git stash list | wc -l) &&
176 git stash apply &&
177 test 9 = $(cat file) &&
178 test 1 = $(git show :file) &&
179 test 1 = $(git show HEAD:file) &&
180 git reset --hard &&
181 git stash drop &&
182 git stash apply &&
183 test 3 = $(cat file) &&
184 test 1 = $(git show :file) &&
185 test 1 = $(git show HEAD:file)
186'
187
b683c080
BC
188test_expect_success 'stash pop' '
189 git reset --hard &&
190 git stash pop &&
191 test 3 = $(cat file) &&
192 test 1 = $(git show :file) &&
193 test 1 = $(git show HEAD:file) &&
194 test 0 = $(git stash list | wc -l)
ceff079b
JH
195'
196
6a0b88b2 197cat >expect <<EOF
4a588075
AMS
198diff --git a/file2 b/file2
199new file mode 100644
200index 0000000..1fe912c
201--- /dev/null
202+++ b/file2
203@@ -0,0 +1 @@
204+bar2
205EOF
206
6a0b88b2 207cat >expect1 <<EOF
4a588075
AMS
208diff --git a/file b/file
209index 257cc56..5716ca5 100644
210--- a/file
211+++ b/file
212@@ -1 +1 @@
213-foo
214+bar
215EOF
216
6a0b88b2 217cat >expect2 <<EOF
4a588075
AMS
218diff --git a/file b/file
219index 7601807..5716ca5 100644
220--- a/file
221+++ b/file
222@@ -1 +1 @@
223-baz
224+bar
225diff --git a/file2 b/file2
226new file mode 100644
227index 0000000..1fe912c
228--- /dev/null
229+++ b/file2
230@@ -0,0 +1 @@
231+bar2
232EOF
233
234test_expect_success 'stash branch' '
6a0b88b2 235 echo foo >file &&
a48fcd83 236 git commit file -m first &&
6a0b88b2
PSU
237 echo bar >file &&
238 echo bar2 >file2 &&
4a588075
AMS
239 git add file2 &&
240 git stash &&
6a0b88b2 241 echo baz >file &&
4a588075
AMS
242 git commit file -m second &&
243 git stash branch stashbranch &&
244 test refs/heads/stashbranch = $(git symbolic-ref HEAD) &&
cbc75a12 245 test $(git rev-parse HEAD) = $(git rev-parse main^) &&
6a0b88b2 246 git diff --cached >output &&
c7848150 247 diff_cmp expect output &&
6a0b88b2 248 git diff >output &&
c7848150 249 diff_cmp expect1 output &&
4a588075
AMS
250 git add file &&
251 git commit -m alternate\ second &&
cbc75a12 252 git diff main..stashbranch >output &&
c7848150 253 diff_cmp output expect2 &&
4a588075
AMS
254 test 0 = $(git stash list | wc -l)
255'
256
fcdd0e92 257test_expect_success 'apply -q is quiet' '
6a0b88b2 258 echo foo >file &&
fcdd0e92 259 git stash &&
6a0b88b2 260 git stash apply -q >output.out 2>&1 &&
ca8d148d 261 test_must_be_empty output.out
fcdd0e92
SB
262'
263
264test_expect_success 'save -q is quiet' '
6a0b88b2 265 git stash save --quiet >output.out 2>&1 &&
ca8d148d 266 test_must_be_empty output.out
fcdd0e92
SB
267'
268
df53c808 269test_expect_success 'pop -q works and is quiet' '
6a0b88b2 270 git stash pop -q >output.out 2>&1 &&
df53c808
TG
271 echo bar >expect &&
272 git show :file >actual &&
273 test_cmp expect actual &&
ca8d148d 274 test_must_be_empty output.out
fcdd0e92
SB
275'
276
460ccd0e 277test_expect_success 'pop -q --index works and is quiet' '
6a0b88b2 278 echo foo >file &&
460ccd0e
TR
279 git add file &&
280 git stash save --quiet &&
6a0b88b2 281 git stash pop -q --index >output.out 2>&1 &&
df53c808
TG
282 git diff-files file2 >file2.diff &&
283 test_must_be_empty file2.diff &&
460ccd0e 284 test foo = "$(git show :file)" &&
ca8d148d 285 test_must_be_empty output.out
460ccd0e
TR
286'
287
fcdd0e92
SB
288test_expect_success 'drop -q is quiet' '
289 git stash &&
6a0b88b2 290 git stash drop -q >output.out 2>&1 &&
ca8d148d 291 test_must_be_empty output.out
fcdd0e92
SB
292'
293
ea41cfc4 294test_expect_success 'stash -k' '
6a0b88b2
PSU
295 echo bar3 >file &&
296 echo bar4 >file2 &&
ea41cfc4
JS
297 git add file2 &&
298 git stash -k &&
299 test bar,bar4 = $(cat file),$(cat file2)
300'
301
21ec98a7 302test_expect_success 'stash --no-keep-index' '
6a0b88b2
PSU
303 echo bar33 >file &&
304 echo bar44 >file2 &&
21ec98a7
DM
305 git add file2 &&
306 git stash --no-keep-index &&
307 test bar,bar2 = $(cat file),$(cat file2)
308'
309
41a28eb6
SO
310test_expect_success 'stash --staged' '
311 echo bar3 >file &&
312 echo bar4 >file2 &&
313 git add file2 &&
314 git stash --staged &&
315 test bar3,bar2 = $(cat file),$(cat file2) &&
316 git reset --hard &&
317 git stash pop &&
318 test bar,bar4 = $(cat file),$(cat file2)
319'
320
8c3713ce
AM
321test_expect_success 'dont assume push with non-option args' '
322 test_must_fail git stash -q drop 2>err &&
323 test_i18ngrep -e "subcommand wasn'\''t specified; '\''push'\'' can'\''t be assumed due to unexpected token '\''drop'\''" err
324'
325
3c2eb80f 326test_expect_success 'stash --invalid-option' '
6a0b88b2
PSU
327 echo bar5 >file &&
328 echo bar6 >file2 &&
3c2eb80f
MM
329 git add file2 &&
330 test_must_fail git stash --invalid-option &&
331 test_must_fail git stash save --invalid-option &&
1ada5020 332 test bar5,bar6 = $(cat file),$(cat file2)
3c2eb80f
MM
333'
334
2ba2fe29
CB
335test_expect_success 'stash an added file' '
336 git reset --hard &&
337 echo new >file3 &&
338 git add file3 &&
339 git stash save "added file" &&
340 ! test -r file3 &&
341 git stash apply &&
342 test new = "$(cat file3)"
343'
344
b6e531e6
MK
345test_expect_success 'stash --intent-to-add file' '
346 git reset --hard &&
347 echo new >file4 &&
348 git add --intent-to-add file4 &&
349 test_when_finished "git rm -f file4" &&
350 test_must_fail git stash
351'
352
2ba2fe29
CB
353test_expect_success 'stash rm then recreate' '
354 git reset --hard &&
355 git rm file &&
356 echo bar7 >file &&
357 git stash save "rm then recreate" &&
358 test bar = "$(cat file)" &&
359 git stash apply &&
360 test bar7 = "$(cat file)"
361'
362
363test_expect_success 'stash rm and ignore' '
364 git reset --hard &&
365 git rm file &&
366 echo file >.gitignore &&
367 git stash save "rm and ignore" &&
368 test bar = "$(cat file)" &&
a48fcd83 369 test file = "$(cat .gitignore)" &&
2ba2fe29
CB
370 git stash apply &&
371 ! test -r file &&
372 test file = "$(cat .gitignore)"
373'
374
375test_expect_success 'stash rm and ignore (stage .gitignore)' '
376 git reset --hard &&
377 git rm file &&
378 echo file >.gitignore &&
379 git add .gitignore &&
380 git stash save "rm and ignore (stage .gitignore)" &&
381 test bar = "$(cat file)" &&
a48fcd83 382 ! test -r .gitignore &&
2ba2fe29
CB
383 git stash apply &&
384 ! test -r file &&
385 test file = "$(cat .gitignore)"
386'
387
388test_expect_success SYMLINKS 'stash file to symlink' '
389 git reset --hard &&
390 rm file &&
391 ln -s file2 file &&
392 git stash save "file to symlink" &&
393 test -f file &&
394 test bar = "$(cat file)" &&
395 git stash apply &&
396 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
397'
398
399test_expect_success SYMLINKS 'stash file to symlink (stage rm)' '
400 git reset --hard &&
401 git rm file &&
402 ln -s file2 file &&
403 git stash save "file to symlink (stage rm)" &&
404 test -f file &&
405 test bar = "$(cat file)" &&
406 git stash apply &&
407 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
408'
409
410test_expect_success SYMLINKS 'stash file to symlink (full stage)' '
411 git reset --hard &&
412 rm file &&
413 ln -s file2 file &&
414 git add file &&
415 git stash save "file to symlink (full stage)" &&
416 test -f file &&
417 test bar = "$(cat file)" &&
418 git stash apply &&
419 case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
420'
421
422# This test creates a commit with a symlink used for the following tests
423
889c6f0e 424test_expect_success 'stash symlink to file' '
2ba2fe29 425 git reset --hard &&
889c6f0e 426 test_ln_s_add file filelink &&
2ba2fe29
CB
427 git commit -m "Add symlink" &&
428 rm filelink &&
429 cp file filelink &&
889c6f0e
JS
430 git stash save "symlink to file"
431'
432
433test_expect_success SYMLINKS 'this must have re-created the symlink' '
2ba2fe29 434 test -h filelink &&
889c6f0e
JS
435 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
436'
437
438test_expect_success 'unstash must re-create the file' '
2ba2fe29
CB
439 git stash apply &&
440 ! test -h filelink &&
441 test bar = "$(cat file)"
442'
443
889c6f0e 444test_expect_success 'stash symlink to file (stage rm)' '
2ba2fe29
CB
445 git reset --hard &&
446 git rm filelink &&
447 cp file filelink &&
889c6f0e
JS
448 git stash save "symlink to file (stage rm)"
449'
450
451test_expect_success SYMLINKS 'this must have re-created the symlink' '
2ba2fe29 452 test -h filelink &&
889c6f0e
JS
453 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
454'
455
456test_expect_success 'unstash must re-create the file' '
2ba2fe29
CB
457 git stash apply &&
458 ! test -h filelink &&
459 test bar = "$(cat file)"
460'
461
889c6f0e 462test_expect_success 'stash symlink to file (full stage)' '
2ba2fe29
CB
463 git reset --hard &&
464 rm filelink &&
465 cp file filelink &&
466 git add filelink &&
889c6f0e
JS
467 git stash save "symlink to file (full stage)"
468'
469
470test_expect_success SYMLINKS 'this must have re-created the symlink' '
2ba2fe29 471 test -h filelink &&
889c6f0e
JS
472 case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
473'
474
475test_expect_success 'unstash must re-create the file' '
2ba2fe29
CB
476 git stash apply &&
477 ! test -h filelink &&
478 test bar = "$(cat file)"
479'
480
481test_expect_failure 'stash directory to file' '
482 git reset --hard &&
483 mkdir dir &&
484 echo foo >dir/file &&
485 git add dir/file &&
486 git commit -m "Add file in dir" &&
487 rm -fr dir &&
488 echo bar >dir &&
489 git stash save "directory to file" &&
490 test -d dir &&
491 test foo = "$(cat dir/file)" &&
492 test_must_fail git stash apply &&
493 test bar = "$(cat dir)" &&
494 git reset --soft HEAD^
495'
496
497test_expect_failure 'stash file to directory' '
498 git reset --hard &&
499 rm file &&
500 mkdir file &&
501 echo foo >file/file &&
502 git stash save "file to directory" &&
503 test -f file &&
504 test bar = "$(cat file)" &&
505 git stash apply &&
506 test -f file/file &&
507 test foo = "$(cat file/file)"
508'
509
93415f58
JT
510test_expect_success 'giving too many ref arguments does not modify files' '
511 git stash clear &&
512 test_when_finished "git reset --hard HEAD" &&
513 echo foo >file2 &&
514 git stash &&
515 echo bar >file2 &&
516 git stash &&
517 test-tool chmtime =123456789 file2 &&
518 for type in apply pop "branch stash-branch"
519 do
520 test_must_fail git stash $type stash@{0} stash@{1} 2>err &&
521 test_i18ngrep "Too many revisions" err &&
522 test 123456789 = $(test-tool chmtime -g file2) || return 1
523 done
524'
525
526test_expect_success 'drop: too many arguments errors out (does nothing)' '
527 git stash list >expect &&
528 test_must_fail git stash drop stash@{0} stash@{1} 2>err &&
529 test_i18ngrep "Too many revisions" err &&
530 git stash list >actual &&
531 test_cmp expect actual
532'
533
534test_expect_success 'show: too many arguments errors out (does nothing)' '
535 test_must_fail git stash show stash@{0} stash@{1} 2>err 1>out &&
536 test_i18ngrep "Too many revisions" err &&
537 test_must_be_empty out
538'
539
c95bc226
JT
540test_expect_success 'stash create - no changes' '
541 git stash clear &&
542 test_when_finished "git reset --hard HEAD" &&
543 git reset --hard &&
544 git stash create >actual &&
545 test_must_be_empty actual
546'
547
daf7a0c0
JS
548test_expect_success 'stash branch - no stashes on stack, stash-like argument' '
549 git stash clear &&
550 test_when_finished "git reset --hard HEAD" &&
551 git reset --hard &&
6a0b88b2 552 echo foo >>file &&
daf7a0c0
JS
553 STASH_ID=$(git stash create) &&
554 git reset --hard &&
555 git stash branch stash-branch ${STASH_ID} &&
cbc75a12 556 test_when_finished "git reset --hard HEAD && git checkout main &&
6a0b88b2 557 git branch -D stash-branch" &&
daf7a0c0
JS
558 test $(git ls-files --modified | wc -l) -eq 1
559'
560
561test_expect_success 'stash branch - stashes on stack, stash-like argument' '
562 git stash clear &&
563 test_when_finished "git reset --hard HEAD" &&
564 git reset --hard &&
6a0b88b2 565 echo foo >>file &&
daf7a0c0
JS
566 git stash &&
567 test_when_finished "git stash drop" &&
6a0b88b2 568 echo bar >>file &&
daf7a0c0
JS
569 STASH_ID=$(git stash create) &&
570 git reset --hard &&
571 git stash branch stash-branch ${STASH_ID} &&
cbc75a12 572 test_when_finished "git reset --hard HEAD && git checkout main &&
6a0b88b2 573 git branch -D stash-branch" &&
daf7a0c0
JS
574 test $(git ls-files --modified | wc -l) -eq 1
575'
576
93415f58
JT
577test_expect_success 'stash branch complains with no arguments' '
578 test_must_fail git stash branch 2>err &&
579 test_i18ngrep "No branch name specified" err
580'
581
11452114 582test_expect_success 'stash show format defaults to --stat' '
daf7a0c0
JS
583 git stash clear &&
584 test_when_finished "git reset --hard HEAD" &&
585 git reset --hard &&
6a0b88b2 586 echo foo >>file &&
daf7a0c0
JS
587 git stash &&
588 test_when_finished "git stash drop" &&
6a0b88b2 589 echo bar >>file &&
daf7a0c0
JS
590 STASH_ID=$(git stash create) &&
591 git reset --hard &&
3fcb8878 592 cat >expected <<-EOF &&
dc801e71 593 file | 1 +
7f814632 594 1 file changed, 1 insertion(+)
3fcb8878
BC
595 EOF
596 git stash show ${STASH_ID} >actual &&
1108cea7 597 test_cmp expected actual
daf7a0c0 598'
3fcb8878 599
11452114
JN
600test_expect_success 'stash show - stashes on stack, stash-like argument' '
601 git stash clear &&
602 test_when_finished "git reset --hard HEAD" &&
603 git reset --hard &&
6a0b88b2 604 echo foo >>file &&
11452114
JN
605 git stash &&
606 test_when_finished "git stash drop" &&
6a0b88b2 607 echo bar >>file &&
11452114
JN
608 STASH_ID=$(git stash create) &&
609 git reset --hard &&
610 echo "1 0 file" >expected &&
611 git stash show --numstat ${STASH_ID} >actual &&
612 test_cmp expected actual
613'
614
9027fa9e 615test_expect_success 'stash show -p - stashes on stack, stash-like argument' '
3fcb8878
BC
616 git stash clear &&
617 test_when_finished "git reset --hard HEAD" &&
618 git reset --hard &&
6a0b88b2 619 echo foo >>file &&
3fcb8878
BC
620 git stash &&
621 test_when_finished "git stash drop" &&
6a0b88b2 622 echo bar >>file &&
3fcb8878
BC
623 STASH_ID=$(git stash create) &&
624 git reset --hard &&
625 cat >expected <<-EOF &&
626 diff --git a/file b/file
627 index 7601807..935fbd3 100644
628 --- a/file
629 +++ b/file
630 @@ -1 +1,2 @@
631 baz
632 +bar
633 EOF
634 git stash show -p ${STASH_ID} >actual &&
c7848150 635 diff_cmp expected actual
3fcb8878
BC
636'
637
9027fa9e 638test_expect_success 'stash show - no stashes on stack, stash-like argument' '
3fcb8878
BC
639 git stash clear &&
640 test_when_finished "git reset --hard HEAD" &&
641 git reset --hard &&
6a0b88b2 642 echo foo >>file &&
3fcb8878
BC
643 STASH_ID=$(git stash create) &&
644 git reset --hard &&
11452114
JN
645 echo "1 0 file" >expected &&
646 git stash show --numstat ${STASH_ID} >actual &&
647 test_cmp expected actual
3fcb8878
BC
648'
649
9027fa9e 650test_expect_success 'stash show -p - no stashes on stack, stash-like argument' '
daf7a0c0
JS
651 git stash clear &&
652 test_when_finished "git reset --hard HEAD" &&
653 git reset --hard &&
6a0b88b2 654 echo foo >>file &&
daf7a0c0
JS
655 STASH_ID=$(git stash create) &&
656 git reset --hard &&
3fcb8878
BC
657 cat >expected <<-EOF &&
658 diff --git a/file b/file
659 index 7601807..71b52c4 100644
660 --- a/file
661 +++ b/file
662 @@ -1 +1,2 @@
663 baz
664 +foo
665 EOF
666 git stash show -p ${STASH_ID} >actual &&
c7848150 667 diff_cmp expected actual
daf7a0c0
JS
668'
669
8e407bc8
TG
670test_expect_success 'stash show --patience shows diff' '
671 git reset --hard &&
672 echo foo >>file &&
673 STASH_ID=$(git stash create) &&
674 git reset --hard &&
675 cat >expected <<-EOF &&
676 diff --git a/file b/file
677 index 7601807..71b52c4 100644
678 --- a/file
679 +++ b/file
680 @@ -1 +1,2 @@
681 baz
682 +foo
683 EOF
684 git stash show --patience ${STASH_ID} >actual &&
c7848150 685 diff_cmp expected actual
8e407bc8
TG
686'
687
ab8ad46e 688test_expect_success 'drop: fail early if specified stash is not a stash ref' '
daf7a0c0
JS
689 git stash clear &&
690 test_when_finished "git reset --hard HEAD && git stash clear" &&
691 git reset --hard &&
6a0b88b2 692 echo foo >file &&
daf7a0c0 693 git stash &&
6a0b88b2 694 echo bar >file &&
daf7a0c0 695 git stash &&
8d66bb05 696 test_must_fail git stash drop $(git rev-parse stash@{0}) &&
daf7a0c0
JS
697 git stash pop &&
698 test bar = "$(cat file)" &&
699 git reset --hard HEAD
700'
701
ab8ad46e 702test_expect_success 'pop: fail early if specified stash is not a stash ref' '
daf7a0c0
JS
703 git stash clear &&
704 test_when_finished "git reset --hard HEAD && git stash clear" &&
705 git reset --hard &&
6a0b88b2 706 echo foo >file &&
daf7a0c0 707 git stash &&
6a0b88b2 708 echo bar >file &&
daf7a0c0 709 git stash &&
8d66bb05 710 test_must_fail git stash pop $(git rev-parse stash@{0}) &&
daf7a0c0
JS
711 git stash pop &&
712 test bar = "$(cat file)" &&
713 git reset --hard HEAD
714'
715
7be8b3ba 716test_expect_success 'ref with non-existent reflog' '
daf7a0c0 717 git stash clear &&
6a0b88b2
PSU
718 echo bar5 >file &&
719 echo bar6 >file2 &&
daf7a0c0
JS
720 git add file2 &&
721 git stash &&
1ae96444 722 test_must_fail git rev-parse --quiet --verify does-not-exist &&
8d66bb05
JS
723 test_must_fail git stash drop does-not-exist &&
724 test_must_fail git stash drop does-not-exist@{0} &&
725 test_must_fail git stash pop does-not-exist &&
726 test_must_fail git stash pop does-not-exist@{0} &&
727 test_must_fail git stash apply does-not-exist &&
728 test_must_fail git stash apply does-not-exist@{0} &&
729 test_must_fail git stash show does-not-exist &&
730 test_must_fail git stash show does-not-exist@{0} &&
731 test_must_fail git stash branch tmp does-not-exist &&
732 test_must_fail git stash branch tmp does-not-exist@{0} &&
daf7a0c0
JS
733 git stash drop
734'
735
736test_expect_success 'invalid ref of the form stash@{n}, n >= N' '
737 git stash clear &&
8d66bb05 738 test_must_fail git stash drop stash@{0} &&
6a0b88b2
PSU
739 echo bar5 >file &&
740 echo bar6 >file2 &&
daf7a0c0
JS
741 git add file2 &&
742 git stash &&
9355fc9c
JS
743 test_must_fail git stash drop stash@{1} &&
744 test_must_fail git stash pop stash@{1} &&
745 test_must_fail git stash apply stash@{1} &&
746 test_must_fail git stash show stash@{1} &&
747 test_must_fail git stash branch tmp stash@{1} &&
daf7a0c0
JS
748 git stash drop
749'
750
a56c8f5a
AW
751test_expect_success 'invalid ref of the form "n", n >= N' '
752 git stash clear &&
753 test_must_fail git stash drop 0 &&
754 echo bar5 >file &&
755 echo bar6 >file2 &&
756 git add file2 &&
757 git stash &&
758 test_must_fail git stash drop 1 &&
759 test_must_fail git stash pop 1 &&
760 test_must_fail git stash apply 1 &&
761 test_must_fail git stash show 1 &&
762 test_must_fail git stash branch tmp 1 &&
763 git stash drop
764'
765
63b50c8f
TG
766test_expect_success 'valid ref of the form "n", n < N' '
767 git stash clear &&
768 echo bar5 >file &&
769 echo bar6 >file2 &&
770 git add file2 &&
771 git stash &&
772 git stash show 0 &&
773 git stash branch tmp 0 &&
cbc75a12 774 git checkout main &&
63b50c8f
TG
775 git stash &&
776 git stash apply 0 &&
777 git reset --hard &&
778 git stash pop 0 &&
779 git stash &&
780 git stash drop 0 &&
781 test_must_fail git stash drop
782'
783
ab8ad46e 784test_expect_success 'branch: do not drop the stash if the branch exists' '
835d6a1f
TC
785 git stash clear &&
786 echo foo >file &&
787 git add file &&
788 git commit -m initial &&
789 echo bar >file &&
790 git stash &&
cbc75a12 791 test_must_fail git stash branch main stash@{0} &&
835d6a1f
TC
792 git rev-parse stash@{0} --
793'
794
ab8ad46e 795test_expect_success 'branch: should not drop the stash if the apply fails' '
b04e6915
JT
796 git stash clear &&
797 git reset HEAD~1 --hard &&
798 echo foo >file &&
799 git add file &&
800 git commit -m initial &&
801 echo bar >file &&
802 git stash &&
803 echo baz >file &&
cbc75a12 804 test_when_finished "git checkout main" &&
b04e6915
JT
805 test_must_fail git stash branch new_branch stash@{0} &&
806 git rev-parse stash@{0} --
807'
808
ab8ad46e 809test_expect_success 'apply: show same status as git status (relative to ./)' '
6eaf92f3
PK
810 git stash clear &&
811 echo 1 >subdir/subfile1 &&
812 echo 2 >subdir/subfile2 &&
813 git add subdir/subfile1 &&
814 git commit -m subdir &&
815 (
816 cd subdir &&
817 echo x >subfile1 &&
818 echo x >../file &&
819 git status >../expect &&
820 git stash &&
821 sane_unset GIT_MERGE_VERBOSITY &&
822 git stash apply
823 ) |
1790f4fe 824 sed -e 1d >actual && # drop "Saved..."
1108cea7 825 test_cmp expect actual
6eaf92f3
PK
826'
827
6a0b88b2 828cat >expect <<EOF
44df2e29
JM
829diff --git a/HEAD b/HEAD
830new file mode 100644
831index 0000000..fe0cbee
832--- /dev/null
833+++ b/HEAD
834@@ -0,0 +1 @@
835+file-not-a-ref
836EOF
837
838test_expect_success 'stash where working directory contains "HEAD" file' '
839 git stash clear &&
840 git reset --hard &&
6a0b88b2 841 echo file-not-a-ref >HEAD &&
44df2e29
JM
842 git add HEAD &&
843 test_tick &&
844 git stash &&
845 git diff-files --quiet &&
846 git diff-index --cached --quiet HEAD &&
847 test "$(git rev-parse stash^)" = "$(git rev-parse HEAD)" &&
6a0b88b2 848 git diff stash^..stash >output &&
c7848150 849 diff_cmp expect output
44df2e29
JM
850'
851
bd514cad
RR
852test_expect_success 'store called with invalid commit' '
853 test_must_fail git stash store foo
854'
855
856test_expect_success 'store updates stash ref and reflog' '
857 git stash clear &&
858 git reset --hard &&
859 echo quux >bazzy &&
860 git add bazzy &&
861 STASH_ID=$(git stash create) &&
862 git reset --hard &&
79b04f9b 863 test_path_is_missing bazzy &&
bd514cad 864 git stash store -m quuxery $STASH_ID &&
cbc5cf7c 865 test $(git rev-parse stash) = $STASH_ID &&
d0ab0584 866 git reflog --format=%H stash| grep $STASH_ID &&
bd514cad
RR
867 git stash pop &&
868 grep quux bazzy
869'
870
2a07e437
ØW
871test_expect_success 'handle stash specification with spaces' '
872 git stash clear &&
873 echo pig >file &&
874 git stash &&
875 stamp=$(git log -g --format="%cd" -1 refs/stash) &&
876 test_tick &&
877 echo cow >file &&
878 git stash &&
879 git stash apply "stash@{$stamp}" &&
880 grep pig file
881'
882
288c67ca
JK
883test_expect_success 'setup stash with index and worktree changes' '
884 git stash clear &&
885 git reset --hard &&
886 echo index >file &&
887 git add file &&
888 echo working >file &&
889 git stash
890'
891
1e20a407 892test_expect_success 'stash list -p shows simple diff' '
f2f3fc95
JK
893 cat >expect <<-EOF &&
894 stash@{0}
288c67ca
JK
895
896 diff --git a/file b/file
897 index 257cc56..d26b33d 100644
898 --- a/file
899 +++ b/file
900 @@ -1 +1 @@
901 -foo
902 +working
903 EOF
f2f3fc95 904 git stash list --format=%gd -p >actual &&
c7848150 905 diff_cmp expect actual
288c67ca
JK
906'
907
908test_expect_success 'stash list --cc shows combined diff' '
909 cat >expect <<-\EOF &&
f2f3fc95 910 stash@{0}
288c67ca
JK
911
912 diff --cc file
913 index 257cc56,9015a7a..d26b33d
914 --- a/file
915 +++ b/file
916 @@@ -1,1 -1,1 +1,1 @@@
917 - foo
918 -index
919 ++working
920 EOF
f2f3fc95 921 git stash list --format=%gd -p --cc >actual &&
c7848150 922 diff_cmp expect actual
288c67ca
JK
923'
924
9d4e28ea
JK
925test_expect_success 'stash is not confused by partial renames' '
926 mv file renamed &&
927 git add renamed &&
928 git stash &&
929 git stash apply &&
930 test_path_is_file renamed &&
931 test_path_is_missing file
932'
933
f5727e26
TG
934test_expect_success 'push -m shows right message' '
935 >foo &&
936 git add foo &&
937 git stash push -m "test message" &&
cbc75a12 938 echo "stash@{0}: On main: test message" >expect &&
f5727e26
TG
939 git stash list -1 >actual &&
940 test_cmp expect actual
941'
942
5675473f
PH
943test_expect_success 'push -m also works without space' '
944 >foo &&
945 git add foo &&
946 git stash push -m"unspaced test message" &&
cbc75a12 947 echo "stash@{0}: On main: unspaced test message" >expect &&
5675473f
PH
948 git stash list -1 >actual &&
949 test_cmp expect actual
950'
951
952test_expect_success 'store -m foo shows right message' '
953 git stash clear &&
954 git reset --hard &&
955 echo quux >bazzy &&
956 git add bazzy &&
957 STASH_ID=$(git stash create) &&
958 git stash store -m "store m" $STASH_ID &&
959 echo "stash@{0}: store m" >expect &&
960 git stash list -1 >actual &&
961 test_cmp expect actual
962'
963
964test_expect_success 'store -mfoo shows right message' '
965 git stash clear &&
966 git reset --hard &&
967 echo quux >bazzy &&
968 git add bazzy &&
969 STASH_ID=$(git stash create) &&
970 git stash store -m"store mfoo" $STASH_ID &&
971 echo "stash@{0}: store mfoo" >expect &&
972 git stash list -1 >actual &&
973 test_cmp expect actual
974'
975
976test_expect_success 'store --message=foo shows right message' '
977 git stash clear &&
978 git reset --hard &&
979 echo quux >bazzy &&
980 git add bazzy &&
981 STASH_ID=$(git stash create) &&
982 git stash store --message="store message=foo" $STASH_ID &&
983 echo "stash@{0}: store message=foo" >expect &&
984 git stash list -1 >actual &&
985 test_cmp expect actual
986'
987
988test_expect_success 'store --message foo shows right message' '
989 git stash clear &&
990 git reset --hard &&
991 echo quux >bazzy &&
992 git add bazzy &&
993 STASH_ID=$(git stash create) &&
994 git stash store --message "store message foo" $STASH_ID &&
995 echo "stash@{0}: store message foo" >expect &&
996 git stash list -1 >actual &&
997 test_cmp expect actual
998'
999
1000test_expect_success 'push -mfoo uses right message' '
1001 >foo &&
1002 git add foo &&
1003 git stash push -m"test mfoo" &&
cbc75a12 1004 echo "stash@{0}: On main: test mfoo" >expect &&
5675473f
PH
1005 git stash list -1 >actual &&
1006 test_cmp expect actual
1007'
1008
1009test_expect_success 'push --message foo is synonym for -mfoo' '
1010 >foo &&
1011 git add foo &&
1012 git stash push --message "test message foo" &&
cbc75a12 1013 echo "stash@{0}: On main: test message foo" >expect &&
5675473f
PH
1014 git stash list -1 >actual &&
1015 test_cmp expect actual
1016'
1017
1018test_expect_success 'push --message=foo is synonym for -mfoo' '
1019 >foo &&
1020 git add foo &&
1021 git stash push --message="test message=foo" &&
cbc75a12 1022 echo "stash@{0}: On main: test message=foo" >expect &&
5675473f
PH
1023 git stash list -1 >actual &&
1024 test_cmp expect actual
1025'
1026
1027test_expect_success 'push -m shows right message' '
1028 >foo &&
1029 git add foo &&
1030 git stash push -m "test m foo" &&
cbc75a12 1031 echo "stash@{0}: On main: test m foo" >expect &&
5675473f
PH
1032 git stash list -1 >actual &&
1033 test_cmp expect actual
1034'
1035
6f5ccd4d
TG
1036test_expect_success 'create stores correct message' '
1037 >foo &&
1038 git add foo &&
1039 STASH_ID=$(git stash create "create test message") &&
cbc75a12 1040 echo "On main: create test message" >expect &&
6f5ccd4d
TG
1041 git show --pretty=%s -s ${STASH_ID} >actual &&
1042 test_cmp expect actual
1043'
1044
ceaf037f
GC
1045test_expect_success 'create when branch name has /' '
1046 test_when_finished "git checkout main" &&
1047 git checkout -b some/topic &&
1048 >foo &&
1049 git add foo &&
1050 STASH_ID=$(git stash create "create test message") &&
1051 echo "On some/topic: create test message" >expect &&
1052 git show --pretty=%s -s ${STASH_ID} >actual &&
1053 test_cmp expect actual
1054'
1055
6f5ccd4d
TG
1056test_expect_success 'create with multiple arguments for the message' '
1057 >foo &&
1058 git add foo &&
1059 STASH_ID=$(git stash create test untracked) &&
cbc75a12 1060 echo "On main: test untracked" >expect &&
6f5ccd4d
TG
1061 git show --pretty=%s -s ${STASH_ID} >actual &&
1062 test_cmp expect actual
1063'
1064
4e9bf3dd 1065test_expect_success 'create in a detached state' '
cbc75a12 1066 test_when_finished "git checkout main" &&
4e9bf3dd
JT
1067 git checkout HEAD~1 &&
1068 >foo &&
1069 git add foo &&
1070 STASH_ID=$(git stash create) &&
1071 HEAD_ID=$(git rev-parse --short HEAD) &&
1072 echo "WIP on (no branch): ${HEAD_ID} initial" >expect &&
1073 git show --pretty=%s -s ${STASH_ID} >actual &&
1074 test_cmp expect actual
1075'
1076
df6bba09
TG
1077test_expect_success 'stash -- <pathspec> stashes and restores the file' '
1078 >foo &&
1079 >bar &&
1080 git add foo bar &&
1081 git stash push -- foo &&
1082 test_path_is_file bar &&
1083 test_path_is_missing foo &&
1084 git stash pop &&
1085 test_path_is_file foo &&
1086 test_path_is_file bar
1087'
1088
22fc703e
PS
1089test_expect_success 'stash -- <pathspec> stashes in subdirectory' '
1090 mkdir sub &&
1091 >foo &&
1092 >bar &&
1093 git add foo bar &&
1094 (
1095 cd sub &&
1096 git stash push -- ../foo
1097 ) &&
1098 test_path_is_file bar &&
1099 test_path_is_missing foo &&
1100 git stash pop &&
1101 test_path_is_file foo &&
1102 test_path_is_file bar
1103'
1104
df6bba09
TG
1105test_expect_success 'stash with multiple pathspec arguments' '
1106 >foo &&
1107 >bar &&
1108 >extra &&
1109 git add foo bar extra &&
1110 git stash push -- foo bar &&
1111 test_path_is_missing bar &&
1112 test_path_is_missing foo &&
1113 test_path_is_file extra &&
1114 git stash pop &&
1115 test_path_is_file foo &&
1116 test_path_is_file bar &&
1117 test_path_is_file extra
1118'
1119
1120test_expect_success 'stash with file including $IFS character' '
1121 >"foo bar" &&
1122 >foo &&
1123 >bar &&
1124 git add foo* &&
1125 git stash push -- "foo b*" &&
1126 test_path_is_missing "foo bar" &&
1127 test_path_is_file foo &&
1128 test_path_is_file bar &&
1129 git stash pop &&
1130 test_path_is_file "foo bar" &&
1131 test_path_is_file foo &&
1132 test_path_is_file bar
1133'
1134
1135test_expect_success 'stash with pathspec matching multiple paths' '
1136 echo original >file &&
1137 echo original >other-file &&
1138 git commit -m "two" file other-file &&
1139 echo modified >file &&
1140 echo modified >other-file &&
1141 git stash push -- "*file" &&
1142 echo original >expect &&
1143 test_cmp expect file &&
1144 test_cmp expect other-file &&
1145 git stash pop &&
1146 echo modified >expect &&
1147 test_cmp expect file &&
1148 test_cmp expect other-file
1149'
1150
1151test_expect_success 'stash push -p with pathspec shows no changes only once' '
1152 >foo &&
1153 git add foo &&
1154 git commit -m "tmp" &&
1155 git stash push -p foo >actual &&
1156 echo "No local changes to save" >expect &&
1157 git reset --hard HEAD~ &&
1108cea7 1158 test_cmp expect actual
df6bba09
TG
1159'
1160
ab8ad46e 1161test_expect_success 'push <pathspec>: show no changes when there are none' '
df6bba09
TG
1162 >foo &&
1163 git add foo &&
1164 git commit -m "tmp" &&
1165 git stash push foo >actual &&
1166 echo "No local changes to save" >expect &&
1167 git reset --hard HEAD~ &&
1108cea7 1168 test_cmp expect actual
df6bba09
TG
1169'
1170
ab8ad46e 1171test_expect_success 'push: <pathspec> not in the repository errors out' '
df6bba09
TG
1172 >untracked &&
1173 test_must_fail git stash push untracked &&
1174 test_path_is_file untracked
1175'
1176
1ac528c0
PSU
1177test_expect_success 'push: -q is quiet with changes' '
1178 >foo &&
1179 git add foo &&
1180 git stash push -q >output 2>&1 &&
1181 test_must_be_empty output
1182'
1183
1184test_expect_success 'push: -q is quiet with no changes' '
1185 git stash push -q >output 2>&1 &&
1186 test_must_be_empty output
1187'
1188
1189test_expect_success 'push: -q is quiet even if there is no initial commit' '
1190 git init foo_dir &&
1191 test_when_finished rm -rf foo_dir &&
1192 (
1193 cd foo_dir &&
1194 >bar &&
1195 test_must_fail git stash push -q >output 2>&1 &&
1196 test_must_be_empty output
1197 )
1198'
1199
df6bba09
TG
1200test_expect_success 'untracked files are left in place when -u is not given' '
1201 >file &&
1202 git add file &&
1203 >untracked &&
1204 git stash push file &&
1205 test_path_is_file untracked
1206'
1207
9e140909
TG
1208test_expect_success 'stash without verb with pathspec' '
1209 >"foo bar" &&
1210 >foo &&
1211 >bar &&
1212 git add foo* &&
1213 git stash -- "foo b*" &&
1214 test_path_is_missing "foo bar" &&
1215 test_path_is_file foo &&
1216 test_path_is_file bar &&
1217 git stash pop &&
1218 test_path_is_file "foo bar" &&
1219 test_path_is_file foo &&
1220 test_path_is_file bar
1221'
1222
e0e7f99e
TG
1223test_expect_success 'stash -k -- <pathspec> leaves unstaged files intact' '
1224 git reset &&
1225 >foo &&
1226 >bar &&
1227 git add foo bar &&
1228 git commit -m "test" &&
1229 echo "foo" >foo &&
1230 echo "bar" >bar &&
1231 git stash -k -- foo &&
1232 test "",bar = $(cat foo),$(cat bar) &&
1233 git stash pop &&
1234 test foo,bar = $(cat foo),$(cat bar)
1235'
1236
bba067d2
TG
1237test_expect_success 'stash -- <subdir> leaves untracked files in subdir intact' '
1238 git reset &&
1239 >subdir/untracked &&
1240 >subdir/tracked1 &&
1241 >subdir/tracked2 &&
1242 git add subdir/tracked* &&
1243 git stash -- subdir/ &&
1244 test_path_is_missing subdir/tracked1 &&
1245 test_path_is_missing subdir/tracked2 &&
1246 test_path_is_file subdir/untracked &&
1247 git stash pop &&
1248 test_path_is_file subdir/tracked1 &&
1249 test_path_is_file subdir/tracked2 &&
1250 test_path_is_file subdir/untracked
1251'
1252
1253test_expect_success 'stash -- <subdir> works with binary files' '
1254 git reset &&
1255 >subdir/untracked &&
1256 >subdir/tracked &&
1257 cp "$TEST_DIRECTORY"/test-binary-1.png subdir/tracked-binary &&
1258 git add subdir/tracked* &&
1259 git stash -- subdir/ &&
1260 test_path_is_missing subdir/tracked &&
1261 test_path_is_missing subdir/tracked-binary &&
1262 test_path_is_file subdir/untracked &&
1263 git stash pop &&
1264 test_path_is_file subdir/tracked &&
1265 test_path_is_file subdir/tracked-binary &&
1266 test_path_is_file subdir/untracked
1267'
1268
0640897d
TG
1269test_expect_success 'stash with user.name and user.email set works' '
1270 test_config user.name "A U Thor" &&
1271 test_config user.email "a.u@thor" &&
1272 git stash
1273'
1274
3bc2111f
SD
1275test_expect_success 'stash works when user.name and user.email are not set' '
1276 git reset &&
1277 >1 &&
1278 git add 1 &&
1279 echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" >expect &&
1280 git stash &&
1281 git show -s --format="%an <%ae>" refs/stash >actual &&
1282 test_cmp expect actual &&
1283 >2 &&
1284 git add 2 &&
1285 test_config user.useconfigonly true &&
3bc2111f
SD
1286 (
1287 sane_unset GIT_AUTHOR_NAME &&
1288 sane_unset GIT_AUTHOR_EMAIL &&
1289 sane_unset GIT_COMMITTER_NAME &&
1290 sane_unset GIT_COMMITTER_EMAIL &&
1291 test_unconfig user.email &&
1292 test_unconfig user.name &&
1293 test_must_fail git commit -m "should fail" &&
1294 echo "git stash <git@stash>" >expect &&
1295 >2 &&
1296 git stash &&
1297 git show -s --format="%an <%ae>" refs/stash >actual &&
1298 test_cmp expect actual
1299 )
1300'
1301
b932f6a5
TG
1302test_expect_success 'stash --keep-index with file deleted in index does not resurrect it on disk' '
1303 test_commit to-remove to-remove &&
1304 git rm to-remove &&
1305 git stash --keep-index &&
1306 test_path_is_missing to-remove
1307'
1308
34933d0e
TG
1309test_expect_success 'stash apply should succeed with unmodified file' '
1310 echo base >file &&
1311 git add file &&
1312 git commit -m base &&
1313
1314 # now stash a modification
1315 echo modified >file &&
1316 git stash &&
1317
1318 # make the file stat dirty
1319 cp file other &&
1320 mv other file &&
1321
1322 git stash apply
1323'
1324
4a58c3d7
JS
1325test_expect_success 'stash handles skip-worktree entries nicely' '
1326 test_commit A &&
1327 echo changed >A.t &&
1328 git add A.t &&
1329 git update-index --skip-worktree A.t &&
1330 rm A.t &&
1331 git stash &&
1332
1333 git rev-parse --verify refs/stash:A.t
1334'
1335
3d40e372 1336test_expect_success 'git stash succeeds despite directory/file change' '
4dbf7f30
EN
1337 test_create_repo directory_file_switch_v1 &&
1338 (
1339 cd directory_file_switch_v1 &&
1340 test_commit init &&
1341
1342 test_write_lines this file has some words >filler &&
1343 git add filler &&
1344 git commit -m filler &&
1345
1346 git rm filler &&
1347 mkdir filler &&
1348 echo contents >filler/file &&
1349 git stash push
1350 )
1351'
1352
bee8691f 1353test_expect_success 'git stash can pop file -> directory saved changes' '
4dbf7f30
EN
1354 test_create_repo directory_file_switch_v2 &&
1355 (
1356 cd directory_file_switch_v2 &&
1357 test_commit init &&
1358
1359 test_write_lines this file has some words >filler &&
1360 git add filler &&
1361 git commit -m filler &&
1362
1363 git rm filler &&
1364 mkdir filler &&
1365 echo contents >filler/file &&
1366 cp filler/file expect &&
1367 git stash push --include-untracked &&
1368 git stash apply --index &&
1369 test_cmp expect filler/file
1370 )
1371'
1372
bee8691f 1373test_expect_success 'git stash can pop directory -> file saved changes' '
4dbf7f30
EN
1374 test_create_repo directory_file_switch_v3 &&
1375 (
1376 cd directory_file_switch_v3 &&
1377 test_commit init &&
1378
1379 mkdir filler &&
1380 test_write_lines some words >filler/file1 &&
1381 test_write_lines and stuff >filler/file2 &&
1382 git add filler &&
1383 git commit -m filler &&
1384
1385 git rm -rf filler &&
1386 echo contents >filler &&
1387 cp filler expect &&
1388 git stash push --include-untracked &&
1389 git stash apply --index &&
1390 test_cmp expect filler
1391 )
1392'
1393
71cade5a
EN
1394test_expect_success 'restore untracked files even when we hit conflicts' '
1395 git init restore_untracked_after_conflict &&
1396 (
1397 cd restore_untracked_after_conflict &&
1398
1399 echo hi >a &&
1400 echo there >b &&
1401 git add . &&
1402 git commit -m first &&
1403 echo hello >a &&
1404 echo something >c &&
1405
1406 git stash push --include-untracked &&
1407
1408 echo conflict >a &&
1409 git add a &&
1410 git commit -m second &&
1411
1412 test_must_fail git stash pop &&
1413
1414 test_path_is_file c
1415 )
1416'
1417
150937c4 1418test_done