]>
Commit | Line | Data |
---|---|---|
150937c4 JS |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Johannes E Schindelin | |
4 | # | |
5 | ||
0cb0e143 | 6 | test_description='Test git stash' |
150937c4 JS |
7 | |
8 | . ./test-lib.sh | |
9 | ||
10 | test_expect_success 'stash some dirty working directory' ' | |
11 | echo 1 > file && | |
12 | git add file && | |
88bab59c JK |
13 | echo unrelated >other-file && |
14 | git add other-file && | |
150937c4 JS |
15 | test_tick && |
16 | git commit -m initial && | |
17 | echo 2 > file && | |
18 | git add file && | |
19 | echo 3 > file && | |
20 | test_tick && | |
21 | git stash && | |
22 | git diff-files --quiet && | |
23 | git diff-index --cached --quiet HEAD | |
24 | ' | |
25 | ||
26 | cat > expect << EOF | |
27 | diff --git a/file b/file | |
28 | index 0cfbf08..00750ed 100644 | |
29 | --- a/file | |
30 | +++ b/file | |
31 | @@ -1 +1 @@ | |
32 | -2 | |
33 | +3 | |
34 | EOF | |
35 | ||
36 | test_expect_success 'parents of stash' ' | |
37 | test $(git rev-parse stash^) = $(git rev-parse HEAD) && | |
38 | git diff stash^2..stash > output && | |
82ebb0b6 | 39 | test_cmp output expect |
150937c4 JS |
40 | ' |
41 | ||
59d418fe JK |
42 | test_expect_success 'applying bogus stash does nothing' ' |
43 | test_must_fail git stash apply stash@{1} && | |
44 | echo 1 >expect && | |
45 | test_cmp expect file | |
46 | ' | |
47 | ||
e0e2a9cb JK |
48 | test_expect_success 'apply does not need clean working directory' ' |
49 | echo 4 >other-file && | |
e0e2a9cb JK |
50 | git stash apply && |
51 | echo 3 >expect && | |
52 | test_cmp expect file | |
53 | ' | |
54 | ||
55 | test_expect_success 'apply does not clobber working directory changes' ' | |
56 | git reset --hard && | |
57 | echo 4 >file && | |
58 | test_must_fail git stash apply && | |
59 | echo 4 >expect && | |
60 | test_cmp expect file | |
150937c4 JS |
61 | ' |
62 | ||
63 | test_expect_success 'apply stashed changes' ' | |
e0e2a9cb JK |
64 | git reset --hard && |
65 | echo 5 >other-file && | |
150937c4 JS |
66 | git add other-file && |
67 | test_tick && | |
68 | git commit -m other-file && | |
69 | git stash apply && | |
70 | test 3 = $(cat file) && | |
71 | test 1 = $(git show :file) && | |
72 | test 1 = $(git show HEAD:file) | |
73 | ' | |
74 | ||
75 | test_expect_success 'apply stashed changes (including index)' ' | |
76 | git reset --hard HEAD^ && | |
77 | echo 6 > other-file && | |
78 | git add other-file && | |
79 | test_tick && | |
80 | git commit -m other-file && | |
81 | git stash apply --index && | |
82 | test 3 = $(cat file) && | |
83 | test 2 = $(git show :file) && | |
84 | test 1 = $(git show HEAD:file) | |
85 | ' | |
86 | ||
ceff079b JH |
87 | test_expect_success 'unstashing in a subdirectory' ' |
88 | git reset --hard HEAD && | |
89 | mkdir subdir && | |
18a82692 JN |
90 | ( |
91 | cd subdir && | |
92 | git stash apply | |
fd4ec4f2 | 93 | ) |
b683c080 BC |
94 | ' |
95 | ||
d6cc2df5 JK |
96 | test_expect_success 'stash drop complains of extra options' ' |
97 | test_must_fail git stash drop --foo | |
98 | ' | |
99 | ||
b683c080 BC |
100 | test_expect_success 'drop top stash' ' |
101 | git reset --hard && | |
102 | git stash list > stashlist1 && | |
103 | echo 7 > file && | |
104 | git stash && | |
105 | git stash drop && | |
106 | git stash list > stashlist2 && | |
4fdf71be | 107 | test_cmp stashlist1 stashlist2 && |
b683c080 BC |
108 | git stash apply && |
109 | test 3 = $(cat file) && | |
110 | test 1 = $(git show :file) && | |
111 | test 1 = $(git show HEAD:file) | |
112 | ' | |
113 | ||
114 | test_expect_success 'drop middle stash' ' | |
115 | git reset --hard && | |
116 | echo 8 > file && | |
117 | git stash && | |
118 | echo 9 > file && | |
119 | git stash && | |
120 | git stash drop stash@{1} && | |
121 | test 2 = $(git stash list | wc -l) && | |
122 | git stash apply && | |
123 | test 9 = $(cat file) && | |
124 | test 1 = $(git show :file) && | |
125 | test 1 = $(git show HEAD:file) && | |
126 | git reset --hard && | |
127 | git stash drop && | |
128 | git stash apply && | |
129 | test 3 = $(cat file) && | |
130 | test 1 = $(git show :file) && | |
131 | test 1 = $(git show HEAD:file) | |
132 | ' | |
133 | ||
a56c8f5a AW |
134 | test_expect_success 'drop middle stash by index' ' |
135 | git reset --hard && | |
136 | echo 8 >file && | |
137 | git stash && | |
138 | echo 9 >file && | |
139 | git stash && | |
140 | git stash drop 1 && | |
141 | test 2 = $(git stash list | wc -l) && | |
142 | git stash apply && | |
143 | test 9 = $(cat file) && | |
144 | test 1 = $(git show :file) && | |
145 | test 1 = $(git show HEAD:file) && | |
146 | git reset --hard && | |
147 | git stash drop && | |
148 | git stash apply && | |
149 | test 3 = $(cat file) && | |
150 | test 1 = $(git show :file) && | |
151 | test 1 = $(git show HEAD:file) | |
152 | ' | |
153 | ||
b683c080 BC |
154 | test_expect_success 'stash pop' ' |
155 | git reset --hard && | |
156 | git stash pop && | |
157 | test 3 = $(cat file) && | |
158 | test 1 = $(git show :file) && | |
159 | test 1 = $(git show HEAD:file) && | |
160 | test 0 = $(git stash list | wc -l) | |
ceff079b JH |
161 | ' |
162 | ||
4a588075 AMS |
163 | cat > expect << EOF |
164 | diff --git a/file2 b/file2 | |
165 | new file mode 100644 | |
166 | index 0000000..1fe912c | |
167 | --- /dev/null | |
168 | +++ b/file2 | |
169 | @@ -0,0 +1 @@ | |
170 | +bar2 | |
171 | EOF | |
172 | ||
173 | cat > expect1 << EOF | |
174 | diff --git a/file b/file | |
175 | index 257cc56..5716ca5 100644 | |
176 | --- a/file | |
177 | +++ b/file | |
178 | @@ -1 +1 @@ | |
179 | -foo | |
180 | +bar | |
181 | EOF | |
182 | ||
183 | cat > expect2 << EOF | |
184 | diff --git a/file b/file | |
185 | index 7601807..5716ca5 100644 | |
186 | --- a/file | |
187 | +++ b/file | |
188 | @@ -1 +1 @@ | |
189 | -baz | |
190 | +bar | |
191 | diff --git a/file2 b/file2 | |
192 | new file mode 100644 | |
193 | index 0000000..1fe912c | |
194 | --- /dev/null | |
195 | +++ b/file2 | |
196 | @@ -0,0 +1 @@ | |
197 | +bar2 | |
198 | EOF | |
199 | ||
200 | test_expect_success 'stash branch' ' | |
201 | echo foo > file && | |
a48fcd83 | 202 | git commit file -m first && |
4a588075 AMS |
203 | echo bar > file && |
204 | echo bar2 > file2 && | |
205 | git add file2 && | |
206 | git stash && | |
207 | echo baz > file && | |
208 | git commit file -m second && | |
209 | git stash branch stashbranch && | |
210 | test refs/heads/stashbranch = $(git symbolic-ref HEAD) && | |
211 | test $(git rev-parse HEAD) = $(git rev-parse master^) && | |
212 | git diff --cached > output && | |
213 | test_cmp output expect && | |
214 | git diff > output && | |
215 | test_cmp output expect1 && | |
216 | git add file && | |
217 | git commit -m alternate\ second && | |
218 | git diff master..stashbranch > output && | |
219 | test_cmp output expect2 && | |
220 | test 0 = $(git stash list | wc -l) | |
221 | ' | |
222 | ||
fcdd0e92 SB |
223 | test_expect_success 'apply -q is quiet' ' |
224 | echo foo > file && | |
225 | git stash && | |
226 | git stash apply -q > output.out 2>&1 && | |
ca8d148d | 227 | test_must_be_empty output.out |
fcdd0e92 SB |
228 | ' |
229 | ||
230 | test_expect_success 'save -q is quiet' ' | |
231 | git stash save --quiet > output.out 2>&1 && | |
ca8d148d | 232 | test_must_be_empty output.out |
fcdd0e92 SB |
233 | ' |
234 | ||
235 | test_expect_success 'pop -q is quiet' ' | |
236 | git stash pop -q > output.out 2>&1 && | |
ca8d148d | 237 | test_must_be_empty output.out |
fcdd0e92 SB |
238 | ' |
239 | ||
460ccd0e TR |
240 | test_expect_success 'pop -q --index works and is quiet' ' |
241 | echo foo > file && | |
242 | git add file && | |
243 | git stash save --quiet && | |
244 | git stash pop -q --index > output.out 2>&1 && | |
245 | test foo = "$(git show :file)" && | |
ca8d148d | 246 | test_must_be_empty output.out |
460ccd0e TR |
247 | ' |
248 | ||
fcdd0e92 SB |
249 | test_expect_success 'drop -q is quiet' ' |
250 | git stash && | |
251 | git stash drop -q > output.out 2>&1 && | |
ca8d148d | 252 | test_must_be_empty output.out |
fcdd0e92 SB |
253 | ' |
254 | ||
ea41cfc4 JS |
255 | test_expect_success 'stash -k' ' |
256 | echo bar3 > file && | |
257 | echo bar4 > file2 && | |
258 | git add file2 && | |
259 | git stash -k && | |
260 | test bar,bar4 = $(cat file),$(cat file2) | |
261 | ' | |
262 | ||
21ec98a7 DM |
263 | test_expect_success 'stash --no-keep-index' ' |
264 | echo bar33 > file && | |
265 | echo bar44 > file2 && | |
266 | git add file2 && | |
267 | git stash --no-keep-index && | |
268 | test bar,bar2 = $(cat file),$(cat file2) | |
269 | ' | |
270 | ||
3c2eb80f MM |
271 | test_expect_success 'stash --invalid-option' ' |
272 | echo bar5 > file && | |
273 | echo bar6 > file2 && | |
274 | git add file2 && | |
275 | test_must_fail git stash --invalid-option && | |
276 | test_must_fail git stash save --invalid-option && | |
1ada5020 | 277 | test bar5,bar6 = $(cat file),$(cat file2) |
3c2eb80f MM |
278 | ' |
279 | ||
2ba2fe29 CB |
280 | test_expect_success 'stash an added file' ' |
281 | git reset --hard && | |
282 | echo new >file3 && | |
283 | git add file3 && | |
284 | git stash save "added file" && | |
285 | ! test -r file3 && | |
286 | git stash apply && | |
287 | test new = "$(cat file3)" | |
288 | ' | |
289 | ||
290 | test_expect_success 'stash rm then recreate' ' | |
291 | git reset --hard && | |
292 | git rm file && | |
293 | echo bar7 >file && | |
294 | git stash save "rm then recreate" && | |
295 | test bar = "$(cat file)" && | |
296 | git stash apply && | |
297 | test bar7 = "$(cat file)" | |
298 | ' | |
299 | ||
300 | test_expect_success 'stash rm and ignore' ' | |
301 | git reset --hard && | |
302 | git rm file && | |
303 | echo file >.gitignore && | |
304 | git stash save "rm and ignore" && | |
305 | test bar = "$(cat file)" && | |
a48fcd83 | 306 | test file = "$(cat .gitignore)" && |
2ba2fe29 CB |
307 | git stash apply && |
308 | ! test -r file && | |
309 | test file = "$(cat .gitignore)" | |
310 | ' | |
311 | ||
312 | test_expect_success 'stash rm and ignore (stage .gitignore)' ' | |
313 | git reset --hard && | |
314 | git rm file && | |
315 | echo file >.gitignore && | |
316 | git add .gitignore && | |
317 | git stash save "rm and ignore (stage .gitignore)" && | |
318 | test bar = "$(cat file)" && | |
a48fcd83 | 319 | ! test -r .gitignore && |
2ba2fe29 CB |
320 | git stash apply && |
321 | ! test -r file && | |
322 | test file = "$(cat .gitignore)" | |
323 | ' | |
324 | ||
325 | test_expect_success SYMLINKS 'stash file to symlink' ' | |
326 | git reset --hard && | |
327 | rm file && | |
328 | ln -s file2 file && | |
329 | git stash save "file to symlink" && | |
330 | test -f file && | |
331 | test bar = "$(cat file)" && | |
332 | git stash apply && | |
333 | case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac | |
334 | ' | |
335 | ||
336 | test_expect_success SYMLINKS 'stash file to symlink (stage rm)' ' | |
337 | git reset --hard && | |
338 | git rm file && | |
339 | ln -s file2 file && | |
340 | git stash save "file to symlink (stage rm)" && | |
341 | test -f file && | |
342 | test bar = "$(cat file)" && | |
343 | git stash apply && | |
344 | case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac | |
345 | ' | |
346 | ||
347 | test_expect_success SYMLINKS 'stash file to symlink (full stage)' ' | |
348 | git reset --hard && | |
349 | rm file && | |
350 | ln -s file2 file && | |
351 | git add file && | |
352 | git stash save "file to symlink (full stage)" && | |
353 | test -f file && | |
354 | test bar = "$(cat file)" && | |
355 | git stash apply && | |
356 | case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac | |
357 | ' | |
358 | ||
359 | # This test creates a commit with a symlink used for the following tests | |
360 | ||
889c6f0e | 361 | test_expect_success 'stash symlink to file' ' |
2ba2fe29 | 362 | git reset --hard && |
889c6f0e | 363 | test_ln_s_add file filelink && |
2ba2fe29 CB |
364 | git commit -m "Add symlink" && |
365 | rm filelink && | |
366 | cp file filelink && | |
889c6f0e JS |
367 | git stash save "symlink to file" |
368 | ' | |
369 | ||
370 | test_expect_success SYMLINKS 'this must have re-created the symlink' ' | |
2ba2fe29 | 371 | test -h filelink && |
889c6f0e JS |
372 | case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac |
373 | ' | |
374 | ||
375 | test_expect_success 'unstash must re-create the file' ' | |
2ba2fe29 CB |
376 | git stash apply && |
377 | ! test -h filelink && | |
378 | test bar = "$(cat file)" | |
379 | ' | |
380 | ||
889c6f0e | 381 | test_expect_success 'stash symlink to file (stage rm)' ' |
2ba2fe29 CB |
382 | git reset --hard && |
383 | git rm filelink && | |
384 | cp file filelink && | |
889c6f0e JS |
385 | git stash save "symlink to file (stage rm)" |
386 | ' | |
387 | ||
388 | test_expect_success SYMLINKS 'this must have re-created the symlink' ' | |
2ba2fe29 | 389 | test -h filelink && |
889c6f0e JS |
390 | case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac |
391 | ' | |
392 | ||
393 | test_expect_success 'unstash must re-create the file' ' | |
2ba2fe29 CB |
394 | git stash apply && |
395 | ! test -h filelink && | |
396 | test bar = "$(cat file)" | |
397 | ' | |
398 | ||
889c6f0e | 399 | test_expect_success 'stash symlink to file (full stage)' ' |
2ba2fe29 CB |
400 | git reset --hard && |
401 | rm filelink && | |
402 | cp file filelink && | |
403 | git add filelink && | |
889c6f0e JS |
404 | git stash save "symlink to file (full stage)" |
405 | ' | |
406 | ||
407 | test_expect_success SYMLINKS 'this must have re-created the symlink' ' | |
2ba2fe29 | 408 | test -h filelink && |
889c6f0e JS |
409 | case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac |
410 | ' | |
411 | ||
412 | test_expect_success 'unstash must re-create the file' ' | |
2ba2fe29 CB |
413 | git stash apply && |
414 | ! test -h filelink && | |
415 | test bar = "$(cat file)" | |
416 | ' | |
417 | ||
418 | test_expect_failure 'stash directory to file' ' | |
419 | git reset --hard && | |
420 | mkdir dir && | |
421 | echo foo >dir/file && | |
422 | git add dir/file && | |
423 | git commit -m "Add file in dir" && | |
424 | rm -fr dir && | |
425 | echo bar >dir && | |
426 | git stash save "directory to file" && | |
427 | test -d dir && | |
428 | test foo = "$(cat dir/file)" && | |
429 | test_must_fail git stash apply && | |
430 | test bar = "$(cat dir)" && | |
431 | git reset --soft HEAD^ | |
432 | ' | |
433 | ||
434 | test_expect_failure 'stash file to directory' ' | |
435 | git reset --hard && | |
436 | rm file && | |
437 | mkdir file && | |
438 | echo foo >file/file && | |
439 | git stash save "file to directory" && | |
440 | test -f file && | |
441 | test bar = "$(cat file)" && | |
442 | git stash apply && | |
443 | test -f file/file && | |
444 | test foo = "$(cat file/file)" | |
445 | ' | |
446 | ||
daf7a0c0 JS |
447 | test_expect_success 'stash branch - no stashes on stack, stash-like argument' ' |
448 | git stash clear && | |
449 | test_when_finished "git reset --hard HEAD" && | |
450 | git reset --hard && | |
451 | echo foo >> file && | |
452 | STASH_ID=$(git stash create) && | |
453 | git reset --hard && | |
454 | git stash branch stash-branch ${STASH_ID} && | |
455 | test_when_finished "git reset --hard HEAD && git checkout master && git branch -D stash-branch" && | |
456 | test $(git ls-files --modified | wc -l) -eq 1 | |
457 | ' | |
458 | ||
459 | test_expect_success 'stash branch - stashes on stack, stash-like argument' ' | |
460 | git stash clear && | |
461 | test_when_finished "git reset --hard HEAD" && | |
462 | git reset --hard && | |
463 | echo foo >> file && | |
464 | git stash && | |
465 | test_when_finished "git stash drop" && | |
466 | echo bar >> file && | |
467 | STASH_ID=$(git stash create) && | |
468 | git reset --hard && | |
469 | git stash branch stash-branch ${STASH_ID} && | |
470 | test_when_finished "git reset --hard HEAD && git checkout master && git branch -D stash-branch" && | |
471 | test $(git ls-files --modified | wc -l) -eq 1 | |
472 | ' | |
473 | ||
11452114 | 474 | test_expect_success 'stash show format defaults to --stat' ' |
daf7a0c0 JS |
475 | git stash clear && |
476 | test_when_finished "git reset --hard HEAD" && | |
477 | git reset --hard && | |
478 | echo foo >> file && | |
479 | git stash && | |
480 | test_when_finished "git stash drop" && | |
481 | echo bar >> file && | |
482 | STASH_ID=$(git stash create) && | |
483 | git reset --hard && | |
3fcb8878 | 484 | cat >expected <<-EOF && |
dc801e71 | 485 | file | 1 + |
7f814632 | 486 | 1 file changed, 1 insertion(+) |
3fcb8878 BC |
487 | EOF |
488 | git stash show ${STASH_ID} >actual && | |
fc5877a6 | 489 | test_i18ncmp expected actual |
daf7a0c0 | 490 | ' |
3fcb8878 | 491 | |
11452114 JN |
492 | test_expect_success 'stash show - stashes on stack, stash-like argument' ' |
493 | git stash clear && | |
494 | test_when_finished "git reset --hard HEAD" && | |
495 | git reset --hard && | |
496 | echo foo >> file && | |
497 | git stash && | |
498 | test_when_finished "git stash drop" && | |
499 | echo bar >> file && | |
500 | STASH_ID=$(git stash create) && | |
501 | git reset --hard && | |
502 | echo "1 0 file" >expected && | |
503 | git stash show --numstat ${STASH_ID} >actual && | |
504 | test_cmp expected actual | |
505 | ' | |
506 | ||
9027fa9e | 507 | test_expect_success 'stash show -p - stashes on stack, stash-like argument' ' |
3fcb8878 BC |
508 | git stash clear && |
509 | test_when_finished "git reset --hard HEAD" && | |
510 | git reset --hard && | |
511 | echo foo >> file && | |
512 | git stash && | |
513 | test_when_finished "git stash drop" && | |
514 | echo bar >> file && | |
515 | STASH_ID=$(git stash create) && | |
516 | git reset --hard && | |
517 | cat >expected <<-EOF && | |
518 | diff --git a/file b/file | |
519 | index 7601807..935fbd3 100644 | |
520 | --- a/file | |
521 | +++ b/file | |
522 | @@ -1 +1,2 @@ | |
523 | baz | |
524 | +bar | |
525 | EOF | |
526 | git stash show -p ${STASH_ID} >actual && | |
527 | test_cmp expected actual | |
528 | ' | |
529 | ||
9027fa9e | 530 | test_expect_success 'stash show - no stashes on stack, stash-like argument' ' |
3fcb8878 BC |
531 | git stash clear && |
532 | test_when_finished "git reset --hard HEAD" && | |
533 | git reset --hard && | |
534 | echo foo >> file && | |
535 | STASH_ID=$(git stash create) && | |
536 | git reset --hard && | |
11452114 JN |
537 | echo "1 0 file" >expected && |
538 | git stash show --numstat ${STASH_ID} >actual && | |
539 | test_cmp expected actual | |
3fcb8878 BC |
540 | ' |
541 | ||
9027fa9e | 542 | test_expect_success 'stash show -p - no stashes on stack, stash-like argument' ' |
daf7a0c0 JS |
543 | git stash clear && |
544 | test_when_finished "git reset --hard HEAD" && | |
545 | git reset --hard && | |
546 | echo foo >> file && | |
547 | STASH_ID=$(git stash create) && | |
548 | git reset --hard && | |
3fcb8878 BC |
549 | cat >expected <<-EOF && |
550 | diff --git a/file b/file | |
551 | index 7601807..71b52c4 100644 | |
552 | --- a/file | |
553 | +++ b/file | |
554 | @@ -1 +1,2 @@ | |
555 | baz | |
556 | +foo | |
557 | EOF | |
558 | git stash show -p ${STASH_ID} >actual && | |
559 | test_cmp expected actual | |
daf7a0c0 JS |
560 | ' |
561 | ||
562 | test_expect_success 'stash drop - fail early if specified stash is not a stash reference' ' | |
563 | git stash clear && | |
564 | test_when_finished "git reset --hard HEAD && git stash clear" && | |
565 | git reset --hard && | |
566 | echo foo > file && | |
567 | git stash && | |
568 | echo bar > file && | |
569 | git stash && | |
8d66bb05 | 570 | test_must_fail git stash drop $(git rev-parse stash@{0}) && |
daf7a0c0 JS |
571 | git stash pop && |
572 | test bar = "$(cat file)" && | |
573 | git reset --hard HEAD | |
574 | ' | |
575 | ||
576 | test_expect_success 'stash pop - fail early if specified stash is not a stash reference' ' | |
577 | git stash clear && | |
578 | test_when_finished "git reset --hard HEAD && git stash clear" && | |
579 | git reset --hard && | |
580 | echo foo > file && | |
581 | git stash && | |
582 | echo bar > file && | |
583 | git stash && | |
8d66bb05 | 584 | test_must_fail git stash pop $(git rev-parse stash@{0}) && |
daf7a0c0 JS |
585 | git stash pop && |
586 | test bar = "$(cat file)" && | |
587 | git reset --hard HEAD | |
588 | ' | |
589 | ||
7be8b3ba | 590 | test_expect_success 'ref with non-existent reflog' ' |
daf7a0c0 JS |
591 | git stash clear && |
592 | echo bar5 > file && | |
593 | echo bar6 > file2 && | |
594 | git add file2 && | |
595 | git stash && | |
1ae96444 | 596 | test_must_fail git rev-parse --quiet --verify does-not-exist && |
8d66bb05 JS |
597 | test_must_fail git stash drop does-not-exist && |
598 | test_must_fail git stash drop does-not-exist@{0} && | |
599 | test_must_fail git stash pop does-not-exist && | |
600 | test_must_fail git stash pop does-not-exist@{0} && | |
601 | test_must_fail git stash apply does-not-exist && | |
602 | test_must_fail git stash apply does-not-exist@{0} && | |
603 | test_must_fail git stash show does-not-exist && | |
604 | test_must_fail git stash show does-not-exist@{0} && | |
605 | test_must_fail git stash branch tmp does-not-exist && | |
606 | test_must_fail git stash branch tmp does-not-exist@{0} && | |
daf7a0c0 JS |
607 | git stash drop |
608 | ' | |
609 | ||
610 | test_expect_success 'invalid ref of the form stash@{n}, n >= N' ' | |
611 | git stash clear && | |
8d66bb05 | 612 | test_must_fail git stash drop stash@{0} && |
daf7a0c0 JS |
613 | echo bar5 > file && |
614 | echo bar6 > file2 && | |
615 | git add file2 && | |
616 | git stash && | |
9355fc9c JS |
617 | test_must_fail git stash drop stash@{1} && |
618 | test_must_fail git stash pop stash@{1} && | |
619 | test_must_fail git stash apply stash@{1} && | |
620 | test_must_fail git stash show stash@{1} && | |
621 | test_must_fail git stash branch tmp stash@{1} && | |
daf7a0c0 JS |
622 | git stash drop |
623 | ' | |
624 | ||
a56c8f5a AW |
625 | test_expect_success 'invalid ref of the form "n", n >= N' ' |
626 | git stash clear && | |
627 | test_must_fail git stash drop 0 && | |
628 | echo bar5 >file && | |
629 | echo bar6 >file2 && | |
630 | git add file2 && | |
631 | git stash && | |
632 | test_must_fail git stash drop 1 && | |
633 | test_must_fail git stash pop 1 && | |
634 | test_must_fail git stash apply 1 && | |
635 | test_must_fail git stash show 1 && | |
636 | test_must_fail git stash branch tmp 1 && | |
637 | git stash drop | |
638 | ' | |
639 | ||
57693d03 | 640 | test_expect_success 'stash branch should not drop the stash if the branch exists' ' |
835d6a1f TC |
641 | git stash clear && |
642 | echo foo >file && | |
643 | git add file && | |
644 | git commit -m initial && | |
645 | echo bar >file && | |
646 | git stash && | |
647 | test_must_fail git stash branch master stash@{0} && | |
648 | git rev-parse stash@{0} -- | |
649 | ' | |
650 | ||
6eaf92f3 PK |
651 | test_expect_success 'stash apply shows status same as git status (relative to current directory)' ' |
652 | git stash clear && | |
653 | echo 1 >subdir/subfile1 && | |
654 | echo 2 >subdir/subfile2 && | |
655 | git add subdir/subfile1 && | |
656 | git commit -m subdir && | |
657 | ( | |
658 | cd subdir && | |
659 | echo x >subfile1 && | |
660 | echo x >../file && | |
661 | git status >../expect && | |
662 | git stash && | |
663 | sane_unset GIT_MERGE_VERBOSITY && | |
664 | git stash apply | |
665 | ) | | |
1790f4fe | 666 | sed -e 1d >actual && # drop "Saved..." |
28785688 | 667 | test_i18ncmp expect actual |
6eaf92f3 PK |
668 | ' |
669 | ||
44df2e29 JM |
670 | cat > expect << EOF |
671 | diff --git a/HEAD b/HEAD | |
672 | new file mode 100644 | |
673 | index 0000000..fe0cbee | |
674 | --- /dev/null | |
675 | +++ b/HEAD | |
676 | @@ -0,0 +1 @@ | |
677 | +file-not-a-ref | |
678 | EOF | |
679 | ||
680 | test_expect_success 'stash where working directory contains "HEAD" file' ' | |
681 | git stash clear && | |
682 | git reset --hard && | |
683 | echo file-not-a-ref > HEAD && | |
684 | git add HEAD && | |
685 | test_tick && | |
686 | git stash && | |
687 | git diff-files --quiet && | |
688 | git diff-index --cached --quiet HEAD && | |
689 | test "$(git rev-parse stash^)" = "$(git rev-parse HEAD)" && | |
690 | git diff stash^..stash > output && | |
691 | test_cmp output expect | |
692 | ' | |
693 | ||
bd514cad RR |
694 | test_expect_success 'store called with invalid commit' ' |
695 | test_must_fail git stash store foo | |
696 | ' | |
697 | ||
698 | test_expect_success 'store updates stash ref and reflog' ' | |
699 | git stash clear && | |
700 | git reset --hard && | |
701 | echo quux >bazzy && | |
702 | git add bazzy && | |
703 | STASH_ID=$(git stash create) && | |
704 | git reset --hard && | |
705 | ! grep quux bazzy && | |
706 | git stash store -m quuxery $STASH_ID && | |
707 | test $(cat .git/refs/stash) = $STASH_ID && | |
d0ab0584 | 708 | git reflog --format=%H stash| grep $STASH_ID && |
bd514cad RR |
709 | git stash pop && |
710 | grep quux bazzy | |
711 | ' | |
712 | ||
2a07e437 ØW |
713 | test_expect_success 'handle stash specification with spaces' ' |
714 | git stash clear && | |
715 | echo pig >file && | |
716 | git stash && | |
717 | stamp=$(git log -g --format="%cd" -1 refs/stash) && | |
718 | test_tick && | |
719 | echo cow >file && | |
720 | git stash && | |
721 | git stash apply "stash@{$stamp}" && | |
722 | grep pig file | |
723 | ' | |
724 | ||
288c67ca JK |
725 | test_expect_success 'setup stash with index and worktree changes' ' |
726 | git stash clear && | |
727 | git reset --hard && | |
728 | echo index >file && | |
729 | git add file && | |
730 | echo working >file && | |
731 | git stash | |
732 | ' | |
733 | ||
734 | test_expect_success 'stash list implies --first-parent -m' ' | |
f2f3fc95 JK |
735 | cat >expect <<-EOF && |
736 | stash@{0} | |
288c67ca JK |
737 | |
738 | diff --git a/file b/file | |
739 | index 257cc56..d26b33d 100644 | |
740 | --- a/file | |
741 | +++ b/file | |
742 | @@ -1 +1 @@ | |
743 | -foo | |
744 | +working | |
745 | EOF | |
f2f3fc95 | 746 | git stash list --format=%gd -p >actual && |
288c67ca JK |
747 | test_cmp expect actual |
748 | ' | |
749 | ||
750 | test_expect_success 'stash list --cc shows combined diff' ' | |
751 | cat >expect <<-\EOF && | |
f2f3fc95 | 752 | stash@{0} |
288c67ca JK |
753 | |
754 | diff --cc file | |
755 | index 257cc56,9015a7a..d26b33d | |
756 | --- a/file | |
757 | +++ b/file | |
758 | @@@ -1,1 -1,1 +1,1 @@@ | |
759 | - foo | |
760 | -index | |
761 | ++working | |
762 | EOF | |
f2f3fc95 | 763 | git stash list --format=%gd -p --cc >actual && |
288c67ca JK |
764 | test_cmp expect actual |
765 | ' | |
766 | ||
9d4e28ea JK |
767 | test_expect_success 'stash is not confused by partial renames' ' |
768 | mv file renamed && | |
769 | git add renamed && | |
770 | git stash && | |
771 | git stash apply && | |
772 | test_path_is_file renamed && | |
773 | test_path_is_missing file | |
774 | ' | |
775 | ||
f5727e26 TG |
776 | test_expect_success 'push -m shows right message' ' |
777 | >foo && | |
778 | git add foo && | |
779 | git stash push -m "test message" && | |
780 | echo "stash@{0}: On master: test message" >expect && | |
781 | git stash list -1 >actual && | |
782 | test_cmp expect actual | |
783 | ' | |
784 | ||
6f5ccd4d TG |
785 | test_expect_success 'create stores correct message' ' |
786 | >foo && | |
787 | git add foo && | |
788 | STASH_ID=$(git stash create "create test message") && | |
789 | echo "On master: create test message" >expect && | |
790 | git show --pretty=%s -s ${STASH_ID} >actual && | |
791 | test_cmp expect actual | |
792 | ' | |
793 | ||
794 | test_expect_success 'create with multiple arguments for the message' ' | |
795 | >foo && | |
796 | git add foo && | |
797 | STASH_ID=$(git stash create test untracked) && | |
798 | echo "On master: test untracked" >expect && | |
799 | git show --pretty=%s -s ${STASH_ID} >actual && | |
800 | test_cmp expect actual | |
801 | ' | |
802 | ||
df6bba09 TG |
803 | test_expect_success 'stash -- <pathspec> stashes and restores the file' ' |
804 | >foo && | |
805 | >bar && | |
806 | git add foo bar && | |
807 | git stash push -- foo && | |
808 | test_path_is_file bar && | |
809 | test_path_is_missing foo && | |
810 | git stash pop && | |
811 | test_path_is_file foo && | |
812 | test_path_is_file bar | |
813 | ' | |
814 | ||
22fc703e PS |
815 | test_expect_success 'stash -- <pathspec> stashes in subdirectory' ' |
816 | mkdir sub && | |
817 | >foo && | |
818 | >bar && | |
819 | git add foo bar && | |
820 | ( | |
821 | cd sub && | |
822 | git stash push -- ../foo | |
823 | ) && | |
824 | test_path_is_file bar && | |
825 | test_path_is_missing foo && | |
826 | git stash pop && | |
827 | test_path_is_file foo && | |
828 | test_path_is_file bar | |
829 | ' | |
830 | ||
df6bba09 TG |
831 | test_expect_success 'stash with multiple pathspec arguments' ' |
832 | >foo && | |
833 | >bar && | |
834 | >extra && | |
835 | git add foo bar extra && | |
836 | git stash push -- foo bar && | |
837 | test_path_is_missing bar && | |
838 | test_path_is_missing foo && | |
839 | test_path_is_file extra && | |
840 | git stash pop && | |
841 | test_path_is_file foo && | |
842 | test_path_is_file bar && | |
843 | test_path_is_file extra | |
844 | ' | |
845 | ||
846 | test_expect_success 'stash with file including $IFS character' ' | |
847 | >"foo bar" && | |
848 | >foo && | |
849 | >bar && | |
850 | git add foo* && | |
851 | git stash push -- "foo b*" && | |
852 | test_path_is_missing "foo bar" && | |
853 | test_path_is_file foo && | |
854 | test_path_is_file bar && | |
855 | git stash pop && | |
856 | test_path_is_file "foo bar" && | |
857 | test_path_is_file foo && | |
858 | test_path_is_file bar | |
859 | ' | |
860 | ||
861 | test_expect_success 'stash with pathspec matching multiple paths' ' | |
862 | echo original >file && | |
863 | echo original >other-file && | |
864 | git commit -m "two" file other-file && | |
865 | echo modified >file && | |
866 | echo modified >other-file && | |
867 | git stash push -- "*file" && | |
868 | echo original >expect && | |
869 | test_cmp expect file && | |
870 | test_cmp expect other-file && | |
871 | git stash pop && | |
872 | echo modified >expect && | |
873 | test_cmp expect file && | |
874 | test_cmp expect other-file | |
875 | ' | |
876 | ||
877 | test_expect_success 'stash push -p with pathspec shows no changes only once' ' | |
878 | >foo && | |
879 | git add foo && | |
880 | git commit -m "tmp" && | |
881 | git stash push -p foo >actual && | |
882 | echo "No local changes to save" >expect && | |
883 | git reset --hard HEAD~ && | |
884 | test_cmp expect actual | |
885 | ' | |
886 | ||
887 | test_expect_success 'stash push with pathspec shows no changes when there are none' ' | |
888 | >foo && | |
889 | git add foo && | |
890 | git commit -m "tmp" && | |
891 | git stash push foo >actual && | |
892 | echo "No local changes to save" >expect && | |
893 | git reset --hard HEAD~ && | |
894 | test_cmp expect actual | |
895 | ' | |
896 | ||
897 | test_expect_success 'stash push with pathspec not in the repository errors out' ' | |
898 | >untracked && | |
899 | test_must_fail git stash push untracked && | |
900 | test_path_is_file untracked | |
901 | ' | |
902 | ||
903 | test_expect_success 'untracked files are left in place when -u is not given' ' | |
904 | >file && | |
905 | git add file && | |
906 | >untracked && | |
907 | git stash push file && | |
908 | test_path_is_file untracked | |
909 | ' | |
910 | ||
9e140909 TG |
911 | test_expect_success 'stash without verb with pathspec' ' |
912 | >"foo bar" && | |
913 | >foo && | |
914 | >bar && | |
915 | git add foo* && | |
916 | git stash -- "foo b*" && | |
917 | test_path_is_missing "foo bar" && | |
918 | test_path_is_file foo && | |
919 | test_path_is_file bar && | |
920 | git stash pop && | |
921 | test_path_is_file "foo bar" && | |
922 | test_path_is_file foo && | |
923 | test_path_is_file bar | |
924 | ' | |
925 | ||
e0e7f99e TG |
926 | test_expect_success 'stash -k -- <pathspec> leaves unstaged files intact' ' |
927 | git reset && | |
928 | >foo && | |
929 | >bar && | |
930 | git add foo bar && | |
931 | git commit -m "test" && | |
932 | echo "foo" >foo && | |
933 | echo "bar" >bar && | |
934 | git stash -k -- foo && | |
935 | test "",bar = $(cat foo),$(cat bar) && | |
936 | git stash pop && | |
937 | test foo,bar = $(cat foo),$(cat bar) | |
938 | ' | |
939 | ||
150937c4 | 940 | test_done |