]>
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 | 7 | |
cbc75a12 | 8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
10 | ||
150937c4 JS |
11 | . ./test-lib.sh |
12 | ||
ca7990ce ÆAB |
13 | test_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 | ||
21 | test_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 | ||
27 | test_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 | 32 | diff_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 | 44 | test_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 | 60 | cat >expect <<EOF |
150937c4 JS |
61 | diff --git a/file b/file |
62 | index 0cfbf08..00750ed 100644 | |
63 | --- a/file | |
64 | +++ b/file | |
65 | @@ -1 +1 @@ | |
66 | -2 | |
67 | +3 | |
68 | EOF | |
69 | ||
70 | test_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 |
76 | test_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 |
82 | test_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 | ||
89 | test_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 | ||
97 | test_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 | ||
109 | test_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 |
121 | test_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 |
130 | test_expect_success 'stash drop complains of extra options' ' |
131 | test_must_fail git stash drop --foo | |
132 | ' | |
133 | ||
b683c080 BC |
134 | test_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 | ||
148 | test_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 |
168 | test_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 |
188 | test_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 | 197 | cat >expect <<EOF |
4a588075 AMS |
198 | diff --git a/file2 b/file2 |
199 | new file mode 100644 | |
200 | index 0000000..1fe912c | |
201 | --- /dev/null | |
202 | +++ b/file2 | |
203 | @@ -0,0 +1 @@ | |
204 | +bar2 | |
205 | EOF | |
206 | ||
6a0b88b2 | 207 | cat >expect1 <<EOF |
4a588075 AMS |
208 | diff --git a/file b/file |
209 | index 257cc56..5716ca5 100644 | |
210 | --- a/file | |
211 | +++ b/file | |
212 | @@ -1 +1 @@ | |
213 | -foo | |
214 | +bar | |
215 | EOF | |
216 | ||
6a0b88b2 | 217 | cat >expect2 <<EOF |
4a588075 AMS |
218 | diff --git a/file b/file |
219 | index 7601807..5716ca5 100644 | |
220 | --- a/file | |
221 | +++ b/file | |
222 | @@ -1 +1 @@ | |
223 | -baz | |
224 | +bar | |
225 | diff --git a/file2 b/file2 | |
226 | new file mode 100644 | |
227 | index 0000000..1fe912c | |
228 | --- /dev/null | |
229 | +++ b/file2 | |
230 | @@ -0,0 +1 @@ | |
231 | +bar2 | |
232 | EOF | |
233 | ||
234 | test_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 | 257 | test_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 | ||
264 | test_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 | 269 | test_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 | 277 | test_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 |
288 | test_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 | 294 | test_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 | 302 | test_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 |
310 | test_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 |
321 | test_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 | 326 | test_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 |
335 | test_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 |
345 | test_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 |
353 | test_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 | ||
363 | test_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 | ||
375 | test_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 | ||
388 | test_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 | ||
399 | test_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 | ||
410 | test_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 | 424 | test_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 | ||
433 | test_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 | ||
438 | test_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 | 444 | test_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 | ||
451 | test_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 | ||
456 | test_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 | 462 | test_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 | ||
470 | test_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 | ||
475 | test_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 | ||
481 | test_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 | ||
497 | test_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 |
510 | test_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 | ||
526 | test_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 | ||
534 | test_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 |
540 | test_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 |
548 | test_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 | ||
561 | test_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 |
577 | test_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 | 582 | test_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 |
600 | test_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 | 615 | test_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 | 638 | test_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 | 650 | test_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 |
670 | test_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 | 688 | test_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 | 702 | test_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 | 716 | test_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 | ||
736 | test_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 |
751 | test_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 |
766 | test_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 | 784 | test_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 | 795 | test_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 | 809 | test_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 | 828 | cat >expect <<EOF |
44df2e29 JM |
829 | diff --git a/HEAD b/HEAD |
830 | new file mode 100644 | |
831 | index 0000000..fe0cbee | |
832 | --- /dev/null | |
833 | +++ b/HEAD | |
834 | @@ -0,0 +1 @@ | |
835 | +file-not-a-ref | |
836 | EOF | |
837 | ||
838 | test_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 |
852 | test_expect_success 'store called with invalid commit' ' |
853 | test_must_fail git stash store foo | |
854 | ' | |
855 | ||
856 | test_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 |
871 | test_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 |
883 | test_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 | 892 | test_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 | ||
908 | test_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 |
925 | test_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 |
934 | test_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 |
943 | test_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 | ||
952 | test_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 | ||
964 | test_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 | ||
976 | test_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 | ||
988 | test_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 | ||
1000 | test_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 | ||
1009 | test_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 | ||
1018 | test_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 | ||
1027 | test_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 |
1036 | test_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 | ||
1045 | test_expect_success 'create with multiple arguments for the message' ' | |
1046 | >foo && | |
1047 | git add foo && | |
1048 | STASH_ID=$(git stash create test untracked) && | |
cbc75a12 | 1049 | echo "On main: test untracked" >expect && |
6f5ccd4d TG |
1050 | git show --pretty=%s -s ${STASH_ID} >actual && |
1051 | test_cmp expect actual | |
1052 | ' | |
1053 | ||
4e9bf3dd | 1054 | test_expect_success 'create in a detached state' ' |
cbc75a12 | 1055 | test_when_finished "git checkout main" && |
4e9bf3dd JT |
1056 | git checkout HEAD~1 && |
1057 | >foo && | |
1058 | git add foo && | |
1059 | STASH_ID=$(git stash create) && | |
1060 | HEAD_ID=$(git rev-parse --short HEAD) && | |
1061 | echo "WIP on (no branch): ${HEAD_ID} initial" >expect && | |
1062 | git show --pretty=%s -s ${STASH_ID} >actual && | |
1063 | test_cmp expect actual | |
1064 | ' | |
1065 | ||
df6bba09 TG |
1066 | test_expect_success 'stash -- <pathspec> stashes and restores the file' ' |
1067 | >foo && | |
1068 | >bar && | |
1069 | git add foo bar && | |
1070 | git stash push -- foo && | |
1071 | test_path_is_file bar && | |
1072 | test_path_is_missing foo && | |
1073 | git stash pop && | |
1074 | test_path_is_file foo && | |
1075 | test_path_is_file bar | |
1076 | ' | |
1077 | ||
22fc703e PS |
1078 | test_expect_success 'stash -- <pathspec> stashes in subdirectory' ' |
1079 | mkdir sub && | |
1080 | >foo && | |
1081 | >bar && | |
1082 | git add foo bar && | |
1083 | ( | |
1084 | cd sub && | |
1085 | git stash push -- ../foo | |
1086 | ) && | |
1087 | test_path_is_file bar && | |
1088 | test_path_is_missing foo && | |
1089 | git stash pop && | |
1090 | test_path_is_file foo && | |
1091 | test_path_is_file bar | |
1092 | ' | |
1093 | ||
df6bba09 TG |
1094 | test_expect_success 'stash with multiple pathspec arguments' ' |
1095 | >foo && | |
1096 | >bar && | |
1097 | >extra && | |
1098 | git add foo bar extra && | |
1099 | git stash push -- foo bar && | |
1100 | test_path_is_missing bar && | |
1101 | test_path_is_missing foo && | |
1102 | test_path_is_file extra && | |
1103 | git stash pop && | |
1104 | test_path_is_file foo && | |
1105 | test_path_is_file bar && | |
1106 | test_path_is_file extra | |
1107 | ' | |
1108 | ||
1109 | test_expect_success 'stash with file including $IFS character' ' | |
1110 | >"foo bar" && | |
1111 | >foo && | |
1112 | >bar && | |
1113 | git add foo* && | |
1114 | git stash push -- "foo b*" && | |
1115 | test_path_is_missing "foo bar" && | |
1116 | test_path_is_file foo && | |
1117 | test_path_is_file bar && | |
1118 | git stash pop && | |
1119 | test_path_is_file "foo bar" && | |
1120 | test_path_is_file foo && | |
1121 | test_path_is_file bar | |
1122 | ' | |
1123 | ||
1124 | test_expect_success 'stash with pathspec matching multiple paths' ' | |
1125 | echo original >file && | |
1126 | echo original >other-file && | |
1127 | git commit -m "two" file other-file && | |
1128 | echo modified >file && | |
1129 | echo modified >other-file && | |
1130 | git stash push -- "*file" && | |
1131 | echo original >expect && | |
1132 | test_cmp expect file && | |
1133 | test_cmp expect other-file && | |
1134 | git stash pop && | |
1135 | echo modified >expect && | |
1136 | test_cmp expect file && | |
1137 | test_cmp expect other-file | |
1138 | ' | |
1139 | ||
1140 | test_expect_success 'stash push -p with pathspec shows no changes only once' ' | |
1141 | >foo && | |
1142 | git add foo && | |
1143 | git commit -m "tmp" && | |
1144 | git stash push -p foo >actual && | |
1145 | echo "No local changes to save" >expect && | |
1146 | git reset --hard HEAD~ && | |
1108cea7 | 1147 | test_cmp expect actual |
df6bba09 TG |
1148 | ' |
1149 | ||
ab8ad46e | 1150 | test_expect_success 'push <pathspec>: show no changes when there are none' ' |
df6bba09 TG |
1151 | >foo && |
1152 | git add foo && | |
1153 | git commit -m "tmp" && | |
1154 | git stash push foo >actual && | |
1155 | echo "No local changes to save" >expect && | |
1156 | git reset --hard HEAD~ && | |
1108cea7 | 1157 | test_cmp expect actual |
df6bba09 TG |
1158 | ' |
1159 | ||
ab8ad46e | 1160 | test_expect_success 'push: <pathspec> not in the repository errors out' ' |
df6bba09 TG |
1161 | >untracked && |
1162 | test_must_fail git stash push untracked && | |
1163 | test_path_is_file untracked | |
1164 | ' | |
1165 | ||
1ac528c0 PSU |
1166 | test_expect_success 'push: -q is quiet with changes' ' |
1167 | >foo && | |
1168 | git add foo && | |
1169 | git stash push -q >output 2>&1 && | |
1170 | test_must_be_empty output | |
1171 | ' | |
1172 | ||
1173 | test_expect_success 'push: -q is quiet with no changes' ' | |
1174 | git stash push -q >output 2>&1 && | |
1175 | test_must_be_empty output | |
1176 | ' | |
1177 | ||
1178 | test_expect_success 'push: -q is quiet even if there is no initial commit' ' | |
1179 | git init foo_dir && | |
1180 | test_when_finished rm -rf foo_dir && | |
1181 | ( | |
1182 | cd foo_dir && | |
1183 | >bar && | |
1184 | test_must_fail git stash push -q >output 2>&1 && | |
1185 | test_must_be_empty output | |
1186 | ) | |
1187 | ' | |
1188 | ||
df6bba09 TG |
1189 | test_expect_success 'untracked files are left in place when -u is not given' ' |
1190 | >file && | |
1191 | git add file && | |
1192 | >untracked && | |
1193 | git stash push file && | |
1194 | test_path_is_file untracked | |
1195 | ' | |
1196 | ||
9e140909 TG |
1197 | test_expect_success 'stash without verb with pathspec' ' |
1198 | >"foo bar" && | |
1199 | >foo && | |
1200 | >bar && | |
1201 | git add foo* && | |
1202 | git stash -- "foo b*" && | |
1203 | test_path_is_missing "foo bar" && | |
1204 | test_path_is_file foo && | |
1205 | test_path_is_file bar && | |
1206 | git stash pop && | |
1207 | test_path_is_file "foo bar" && | |
1208 | test_path_is_file foo && | |
1209 | test_path_is_file bar | |
1210 | ' | |
1211 | ||
e0e7f99e TG |
1212 | test_expect_success 'stash -k -- <pathspec> leaves unstaged files intact' ' |
1213 | git reset && | |
1214 | >foo && | |
1215 | >bar && | |
1216 | git add foo bar && | |
1217 | git commit -m "test" && | |
1218 | echo "foo" >foo && | |
1219 | echo "bar" >bar && | |
1220 | git stash -k -- foo && | |
1221 | test "",bar = $(cat foo),$(cat bar) && | |
1222 | git stash pop && | |
1223 | test foo,bar = $(cat foo),$(cat bar) | |
1224 | ' | |
1225 | ||
bba067d2 TG |
1226 | test_expect_success 'stash -- <subdir> leaves untracked files in subdir intact' ' |
1227 | git reset && | |
1228 | >subdir/untracked && | |
1229 | >subdir/tracked1 && | |
1230 | >subdir/tracked2 && | |
1231 | git add subdir/tracked* && | |
1232 | git stash -- subdir/ && | |
1233 | test_path_is_missing subdir/tracked1 && | |
1234 | test_path_is_missing subdir/tracked2 && | |
1235 | test_path_is_file subdir/untracked && | |
1236 | git stash pop && | |
1237 | test_path_is_file subdir/tracked1 && | |
1238 | test_path_is_file subdir/tracked2 && | |
1239 | test_path_is_file subdir/untracked | |
1240 | ' | |
1241 | ||
1242 | test_expect_success 'stash -- <subdir> works with binary files' ' | |
1243 | git reset && | |
1244 | >subdir/untracked && | |
1245 | >subdir/tracked && | |
1246 | cp "$TEST_DIRECTORY"/test-binary-1.png subdir/tracked-binary && | |
1247 | git add subdir/tracked* && | |
1248 | git stash -- subdir/ && | |
1249 | test_path_is_missing subdir/tracked && | |
1250 | test_path_is_missing subdir/tracked-binary && | |
1251 | test_path_is_file subdir/untracked && | |
1252 | git stash pop && | |
1253 | test_path_is_file subdir/tracked && | |
1254 | test_path_is_file subdir/tracked-binary && | |
1255 | test_path_is_file subdir/untracked | |
1256 | ' | |
1257 | ||
0640897d TG |
1258 | test_expect_success 'stash with user.name and user.email set works' ' |
1259 | test_config user.name "A U Thor" && | |
1260 | test_config user.email "a.u@thor" && | |
1261 | git stash | |
1262 | ' | |
1263 | ||
3bc2111f SD |
1264 | test_expect_success 'stash works when user.name and user.email are not set' ' |
1265 | git reset && | |
1266 | >1 && | |
1267 | git add 1 && | |
1268 | echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" >expect && | |
1269 | git stash && | |
1270 | git show -s --format="%an <%ae>" refs/stash >actual && | |
1271 | test_cmp expect actual && | |
1272 | >2 && | |
1273 | git add 2 && | |
1274 | test_config user.useconfigonly true && | |
1275 | test_config stash.usebuiltin true && | |
1276 | ( | |
1277 | sane_unset GIT_AUTHOR_NAME && | |
1278 | sane_unset GIT_AUTHOR_EMAIL && | |
1279 | sane_unset GIT_COMMITTER_NAME && | |
1280 | sane_unset GIT_COMMITTER_EMAIL && | |
1281 | test_unconfig user.email && | |
1282 | test_unconfig user.name && | |
1283 | test_must_fail git commit -m "should fail" && | |
1284 | echo "git stash <git@stash>" >expect && | |
1285 | >2 && | |
1286 | git stash && | |
1287 | git show -s --format="%an <%ae>" refs/stash >actual && | |
1288 | test_cmp expect actual | |
1289 | ) | |
1290 | ' | |
1291 | ||
b932f6a5 TG |
1292 | test_expect_success 'stash --keep-index with file deleted in index does not resurrect it on disk' ' |
1293 | test_commit to-remove to-remove && | |
1294 | git rm to-remove && | |
1295 | git stash --keep-index && | |
1296 | test_path_is_missing to-remove | |
1297 | ' | |
1298 | ||
34933d0e TG |
1299 | test_expect_success 'stash apply should succeed with unmodified file' ' |
1300 | echo base >file && | |
1301 | git add file && | |
1302 | git commit -m base && | |
1303 | ||
1304 | # now stash a modification | |
1305 | echo modified >file && | |
1306 | git stash && | |
1307 | ||
1308 | # make the file stat dirty | |
1309 | cp file other && | |
1310 | mv other file && | |
1311 | ||
1312 | git stash apply | |
1313 | ' | |
1314 | ||
4a58c3d7 JS |
1315 | test_expect_success 'stash handles skip-worktree entries nicely' ' |
1316 | test_commit A && | |
1317 | echo changed >A.t && | |
1318 | git add A.t && | |
1319 | git update-index --skip-worktree A.t && | |
1320 | rm A.t && | |
1321 | git stash && | |
1322 | ||
1323 | git rev-parse --verify refs/stash:A.t | |
1324 | ' | |
1325 | ||
8a2cd3f5 TG |
1326 | test_expect_success 'stash -c stash.useBuiltin=false warning ' ' |
1327 | expected="stash.useBuiltin support has been removed" && | |
1328 | ||
1329 | git -c stash.useBuiltin=false stash 2>err && | |
1330 | test_i18ngrep "$expected" err && | |
1331 | env GIT_TEST_STASH_USE_BUILTIN=false git stash 2>err && | |
1332 | test_i18ngrep "$expected" err && | |
1333 | ||
1334 | git -c stash.useBuiltin=true stash 2>err && | |
1335 | test_must_be_empty err && | |
1336 | env GIT_TEST_STASH_USE_BUILTIN=true git stash 2>err && | |
1337 | test_must_be_empty err | |
1338 | ' | |
1339 | ||
3d40e372 | 1340 | test_expect_success 'git stash succeeds despite directory/file change' ' |
4dbf7f30 EN |
1341 | test_create_repo directory_file_switch_v1 && |
1342 | ( | |
1343 | cd directory_file_switch_v1 && | |
1344 | test_commit init && | |
1345 | ||
1346 | test_write_lines this file has some words >filler && | |
1347 | git add filler && | |
1348 | git commit -m filler && | |
1349 | ||
1350 | git rm filler && | |
1351 | mkdir filler && | |
1352 | echo contents >filler/file && | |
1353 | git stash push | |
1354 | ) | |
1355 | ' | |
1356 | ||
bee8691f | 1357 | test_expect_success 'git stash can pop file -> directory saved changes' ' |
4dbf7f30 EN |
1358 | test_create_repo directory_file_switch_v2 && |
1359 | ( | |
1360 | cd directory_file_switch_v2 && | |
1361 | test_commit init && | |
1362 | ||
1363 | test_write_lines this file has some words >filler && | |
1364 | git add filler && | |
1365 | git commit -m filler && | |
1366 | ||
1367 | git rm filler && | |
1368 | mkdir filler && | |
1369 | echo contents >filler/file && | |
1370 | cp filler/file expect && | |
1371 | git stash push --include-untracked && | |
1372 | git stash apply --index && | |
1373 | test_cmp expect filler/file | |
1374 | ) | |
1375 | ' | |
1376 | ||
bee8691f | 1377 | test_expect_success 'git stash can pop directory -> file saved changes' ' |
4dbf7f30 EN |
1378 | test_create_repo directory_file_switch_v3 && |
1379 | ( | |
1380 | cd directory_file_switch_v3 && | |
1381 | test_commit init && | |
1382 | ||
1383 | mkdir filler && | |
1384 | test_write_lines some words >filler/file1 && | |
1385 | test_write_lines and stuff >filler/file2 && | |
1386 | git add filler && | |
1387 | git commit -m filler && | |
1388 | ||
1389 | git rm -rf filler && | |
1390 | echo contents >filler && | |
1391 | cp filler expect && | |
1392 | git stash push --include-untracked && | |
1393 | git stash apply --index && | |
1394 | test_cmp expect filler | |
1395 | ) | |
1396 | ' | |
1397 | ||
71cade5a EN |
1398 | test_expect_success 'restore untracked files even when we hit conflicts' ' |
1399 | git init restore_untracked_after_conflict && | |
1400 | ( | |
1401 | cd restore_untracked_after_conflict && | |
1402 | ||
1403 | echo hi >a && | |
1404 | echo there >b && | |
1405 | git add . && | |
1406 | git commit -m first && | |
1407 | echo hello >a && | |
1408 | echo something >c && | |
1409 | ||
1410 | git stash push --include-untracked && | |
1411 | ||
1412 | echo conflict >a && | |
1413 | git add a && | |
1414 | git commit -m second && | |
1415 | ||
1416 | test_must_fail git stash pop && | |
1417 | ||
1418 | test_path_is_file c | |
1419 | ) | |
1420 | ' | |
1421 | ||
150937c4 | 1422 | test_done |