]>
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 | ||
8c3713ce AM |
310 | test_expect_success 'dont assume push with non-option args' ' |
311 | test_must_fail git stash -q drop 2>err && | |
312 | test_i18ngrep -e "subcommand wasn'\''t specified; '\''push'\'' can'\''t be assumed due to unexpected token '\''drop'\''" err | |
313 | ' | |
314 | ||
3c2eb80f | 315 | test_expect_success 'stash --invalid-option' ' |
6a0b88b2 PSU |
316 | echo bar5 >file && |
317 | echo bar6 >file2 && | |
3c2eb80f MM |
318 | git add file2 && |
319 | test_must_fail git stash --invalid-option && | |
320 | test_must_fail git stash save --invalid-option && | |
1ada5020 | 321 | test bar5,bar6 = $(cat file),$(cat file2) |
3c2eb80f MM |
322 | ' |
323 | ||
2ba2fe29 CB |
324 | test_expect_success 'stash an added file' ' |
325 | git reset --hard && | |
326 | echo new >file3 && | |
327 | git add file3 && | |
328 | git stash save "added file" && | |
329 | ! test -r file3 && | |
330 | git stash apply && | |
331 | test new = "$(cat file3)" | |
332 | ' | |
333 | ||
b6e531e6 MK |
334 | test_expect_success 'stash --intent-to-add file' ' |
335 | git reset --hard && | |
336 | echo new >file4 && | |
337 | git add --intent-to-add file4 && | |
338 | test_when_finished "git rm -f file4" && | |
339 | test_must_fail git stash | |
340 | ' | |
341 | ||
2ba2fe29 CB |
342 | test_expect_success 'stash rm then recreate' ' |
343 | git reset --hard && | |
344 | git rm file && | |
345 | echo bar7 >file && | |
346 | git stash save "rm then recreate" && | |
347 | test bar = "$(cat file)" && | |
348 | git stash apply && | |
349 | test bar7 = "$(cat file)" | |
350 | ' | |
351 | ||
352 | test_expect_success 'stash rm and ignore' ' | |
353 | git reset --hard && | |
354 | git rm file && | |
355 | echo file >.gitignore && | |
356 | git stash save "rm and ignore" && | |
357 | test bar = "$(cat file)" && | |
a48fcd83 | 358 | test file = "$(cat .gitignore)" && |
2ba2fe29 CB |
359 | git stash apply && |
360 | ! test -r file && | |
361 | test file = "$(cat .gitignore)" | |
362 | ' | |
363 | ||
364 | test_expect_success 'stash rm and ignore (stage .gitignore)' ' | |
365 | git reset --hard && | |
366 | git rm file && | |
367 | echo file >.gitignore && | |
368 | git add .gitignore && | |
369 | git stash save "rm and ignore (stage .gitignore)" && | |
370 | test bar = "$(cat file)" && | |
a48fcd83 | 371 | ! test -r .gitignore && |
2ba2fe29 CB |
372 | git stash apply && |
373 | ! test -r file && | |
374 | test file = "$(cat .gitignore)" | |
375 | ' | |
376 | ||
377 | test_expect_success SYMLINKS 'stash file to symlink' ' | |
378 | git reset --hard && | |
379 | rm file && | |
380 | ln -s file2 file && | |
381 | git stash save "file to symlink" && | |
382 | test -f file && | |
383 | test bar = "$(cat file)" && | |
384 | git stash apply && | |
385 | case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac | |
386 | ' | |
387 | ||
388 | test_expect_success SYMLINKS 'stash file to symlink (stage rm)' ' | |
389 | git reset --hard && | |
390 | git rm file && | |
391 | ln -s file2 file && | |
392 | git stash save "file to symlink (stage rm)" && | |
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 (full stage)' ' | |
400 | git reset --hard && | |
401 | rm file && | |
402 | ln -s file2 file && | |
403 | git add file && | |
404 | git stash save "file to symlink (full stage)" && | |
405 | test -f file && | |
406 | test bar = "$(cat file)" && | |
407 | git stash apply && | |
408 | case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac | |
409 | ' | |
410 | ||
411 | # This test creates a commit with a symlink used for the following tests | |
412 | ||
889c6f0e | 413 | test_expect_success 'stash symlink to file' ' |
2ba2fe29 | 414 | git reset --hard && |
889c6f0e | 415 | test_ln_s_add file filelink && |
2ba2fe29 CB |
416 | git commit -m "Add symlink" && |
417 | rm filelink && | |
418 | cp file filelink && | |
889c6f0e JS |
419 | git stash save "symlink to file" |
420 | ' | |
421 | ||
422 | test_expect_success SYMLINKS 'this must have re-created the symlink' ' | |
2ba2fe29 | 423 | test -h filelink && |
889c6f0e JS |
424 | case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac |
425 | ' | |
426 | ||
427 | test_expect_success 'unstash must re-create the file' ' | |
2ba2fe29 CB |
428 | git stash apply && |
429 | ! test -h filelink && | |
430 | test bar = "$(cat file)" | |
431 | ' | |
432 | ||
889c6f0e | 433 | test_expect_success 'stash symlink to file (stage rm)' ' |
2ba2fe29 CB |
434 | git reset --hard && |
435 | git rm filelink && | |
436 | cp file filelink && | |
889c6f0e JS |
437 | git stash save "symlink to file (stage rm)" |
438 | ' | |
439 | ||
440 | test_expect_success SYMLINKS 'this must have re-created the symlink' ' | |
2ba2fe29 | 441 | test -h filelink && |
889c6f0e JS |
442 | case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac |
443 | ' | |
444 | ||
445 | test_expect_success 'unstash must re-create the file' ' | |
2ba2fe29 CB |
446 | git stash apply && |
447 | ! test -h filelink && | |
448 | test bar = "$(cat file)" | |
449 | ' | |
450 | ||
889c6f0e | 451 | test_expect_success 'stash symlink to file (full stage)' ' |
2ba2fe29 CB |
452 | git reset --hard && |
453 | rm filelink && | |
454 | cp file filelink && | |
455 | git add filelink && | |
889c6f0e JS |
456 | git stash save "symlink to file (full stage)" |
457 | ' | |
458 | ||
459 | test_expect_success SYMLINKS 'this must have re-created the symlink' ' | |
2ba2fe29 | 460 | test -h filelink && |
889c6f0e JS |
461 | case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac |
462 | ' | |
463 | ||
464 | test_expect_success 'unstash must re-create the file' ' | |
2ba2fe29 CB |
465 | git stash apply && |
466 | ! test -h filelink && | |
467 | test bar = "$(cat file)" | |
468 | ' | |
469 | ||
470 | test_expect_failure 'stash directory to file' ' | |
471 | git reset --hard && | |
472 | mkdir dir && | |
473 | echo foo >dir/file && | |
474 | git add dir/file && | |
475 | git commit -m "Add file in dir" && | |
476 | rm -fr dir && | |
477 | echo bar >dir && | |
478 | git stash save "directory to file" && | |
479 | test -d dir && | |
480 | test foo = "$(cat dir/file)" && | |
481 | test_must_fail git stash apply && | |
482 | test bar = "$(cat dir)" && | |
483 | git reset --soft HEAD^ | |
484 | ' | |
485 | ||
486 | test_expect_failure 'stash file to directory' ' | |
487 | git reset --hard && | |
488 | rm file && | |
489 | mkdir file && | |
490 | echo foo >file/file && | |
491 | git stash save "file to directory" && | |
492 | test -f file && | |
493 | test bar = "$(cat file)" && | |
494 | git stash apply && | |
495 | test -f file/file && | |
496 | test foo = "$(cat file/file)" | |
497 | ' | |
498 | ||
93415f58 JT |
499 | test_expect_success 'giving too many ref arguments does not modify files' ' |
500 | git stash clear && | |
501 | test_when_finished "git reset --hard HEAD" && | |
502 | echo foo >file2 && | |
503 | git stash && | |
504 | echo bar >file2 && | |
505 | git stash && | |
506 | test-tool chmtime =123456789 file2 && | |
507 | for type in apply pop "branch stash-branch" | |
508 | do | |
509 | test_must_fail git stash $type stash@{0} stash@{1} 2>err && | |
510 | test_i18ngrep "Too many revisions" err && | |
511 | test 123456789 = $(test-tool chmtime -g file2) || return 1 | |
512 | done | |
513 | ' | |
514 | ||
515 | test_expect_success 'drop: too many arguments errors out (does nothing)' ' | |
516 | git stash list >expect && | |
517 | test_must_fail git stash drop stash@{0} stash@{1} 2>err && | |
518 | test_i18ngrep "Too many revisions" err && | |
519 | git stash list >actual && | |
520 | test_cmp expect actual | |
521 | ' | |
522 | ||
523 | test_expect_success 'show: too many arguments errors out (does nothing)' ' | |
524 | test_must_fail git stash show stash@{0} stash@{1} 2>err 1>out && | |
525 | test_i18ngrep "Too many revisions" err && | |
526 | test_must_be_empty out | |
527 | ' | |
528 | ||
c95bc226 JT |
529 | test_expect_success 'stash create - no changes' ' |
530 | git stash clear && | |
531 | test_when_finished "git reset --hard HEAD" && | |
532 | git reset --hard && | |
533 | git stash create >actual && | |
534 | test_must_be_empty actual | |
535 | ' | |
536 | ||
daf7a0c0 JS |
537 | test_expect_success 'stash branch - no stashes on stack, stash-like argument' ' |
538 | git stash clear && | |
539 | test_when_finished "git reset --hard HEAD" && | |
540 | git reset --hard && | |
6a0b88b2 | 541 | echo foo >>file && |
daf7a0c0 JS |
542 | STASH_ID=$(git stash create) && |
543 | git reset --hard && | |
544 | git stash branch stash-branch ${STASH_ID} && | |
cbc75a12 | 545 | test_when_finished "git reset --hard HEAD && git checkout main && |
6a0b88b2 | 546 | git branch -D stash-branch" && |
daf7a0c0 JS |
547 | test $(git ls-files --modified | wc -l) -eq 1 |
548 | ' | |
549 | ||
550 | test_expect_success 'stash branch - stashes on stack, stash-like argument' ' | |
551 | git stash clear && | |
552 | test_when_finished "git reset --hard HEAD" && | |
553 | git reset --hard && | |
6a0b88b2 | 554 | echo foo >>file && |
daf7a0c0 JS |
555 | git stash && |
556 | test_when_finished "git stash drop" && | |
6a0b88b2 | 557 | echo bar >>file && |
daf7a0c0 JS |
558 | STASH_ID=$(git stash create) && |
559 | git reset --hard && | |
560 | git stash branch stash-branch ${STASH_ID} && | |
cbc75a12 | 561 | test_when_finished "git reset --hard HEAD && git checkout main && |
6a0b88b2 | 562 | git branch -D stash-branch" && |
daf7a0c0 JS |
563 | test $(git ls-files --modified | wc -l) -eq 1 |
564 | ' | |
565 | ||
93415f58 JT |
566 | test_expect_success 'stash branch complains with no arguments' ' |
567 | test_must_fail git stash branch 2>err && | |
568 | test_i18ngrep "No branch name specified" err | |
569 | ' | |
570 | ||
11452114 | 571 | test_expect_success 'stash show format defaults to --stat' ' |
daf7a0c0 JS |
572 | git stash clear && |
573 | test_when_finished "git reset --hard HEAD" && | |
574 | git reset --hard && | |
6a0b88b2 | 575 | echo foo >>file && |
daf7a0c0 JS |
576 | git stash && |
577 | test_when_finished "git stash drop" && | |
6a0b88b2 | 578 | echo bar >>file && |
daf7a0c0 JS |
579 | STASH_ID=$(git stash create) && |
580 | git reset --hard && | |
3fcb8878 | 581 | cat >expected <<-EOF && |
dc801e71 | 582 | file | 1 + |
7f814632 | 583 | 1 file changed, 1 insertion(+) |
3fcb8878 BC |
584 | EOF |
585 | git stash show ${STASH_ID} >actual && | |
1108cea7 | 586 | test_cmp expected actual |
daf7a0c0 | 587 | ' |
3fcb8878 | 588 | |
11452114 JN |
589 | test_expect_success 'stash show - stashes on stack, stash-like argument' ' |
590 | git stash clear && | |
591 | test_when_finished "git reset --hard HEAD" && | |
592 | git reset --hard && | |
6a0b88b2 | 593 | echo foo >>file && |
11452114 JN |
594 | git stash && |
595 | test_when_finished "git stash drop" && | |
6a0b88b2 | 596 | echo bar >>file && |
11452114 JN |
597 | STASH_ID=$(git stash create) && |
598 | git reset --hard && | |
599 | echo "1 0 file" >expected && | |
600 | git stash show --numstat ${STASH_ID} >actual && | |
601 | test_cmp expected actual | |
602 | ' | |
603 | ||
9027fa9e | 604 | test_expect_success 'stash show -p - stashes on stack, stash-like argument' ' |
3fcb8878 BC |
605 | git stash clear && |
606 | test_when_finished "git reset --hard HEAD" && | |
607 | git reset --hard && | |
6a0b88b2 | 608 | echo foo >>file && |
3fcb8878 BC |
609 | git stash && |
610 | test_when_finished "git stash drop" && | |
6a0b88b2 | 611 | echo bar >>file && |
3fcb8878 BC |
612 | STASH_ID=$(git stash create) && |
613 | git reset --hard && | |
614 | cat >expected <<-EOF && | |
615 | diff --git a/file b/file | |
616 | index 7601807..935fbd3 100644 | |
617 | --- a/file | |
618 | +++ b/file | |
619 | @@ -1 +1,2 @@ | |
620 | baz | |
621 | +bar | |
622 | EOF | |
623 | git stash show -p ${STASH_ID} >actual && | |
c7848150 | 624 | diff_cmp expected actual |
3fcb8878 BC |
625 | ' |
626 | ||
9027fa9e | 627 | test_expect_success 'stash show - no stashes on stack, stash-like argument' ' |
3fcb8878 BC |
628 | git stash clear && |
629 | test_when_finished "git reset --hard HEAD" && | |
630 | git reset --hard && | |
6a0b88b2 | 631 | echo foo >>file && |
3fcb8878 BC |
632 | STASH_ID=$(git stash create) && |
633 | git reset --hard && | |
11452114 JN |
634 | echo "1 0 file" >expected && |
635 | git stash show --numstat ${STASH_ID} >actual && | |
636 | test_cmp expected actual | |
3fcb8878 BC |
637 | ' |
638 | ||
9027fa9e | 639 | test_expect_success 'stash show -p - no stashes on stack, stash-like argument' ' |
daf7a0c0 JS |
640 | git stash clear && |
641 | test_when_finished "git reset --hard HEAD" && | |
642 | git reset --hard && | |
6a0b88b2 | 643 | echo foo >>file && |
daf7a0c0 JS |
644 | STASH_ID=$(git stash create) && |
645 | git reset --hard && | |
3fcb8878 BC |
646 | cat >expected <<-EOF && |
647 | diff --git a/file b/file | |
648 | index 7601807..71b52c4 100644 | |
649 | --- a/file | |
650 | +++ b/file | |
651 | @@ -1 +1,2 @@ | |
652 | baz | |
653 | +foo | |
654 | EOF | |
655 | git stash show -p ${STASH_ID} >actual && | |
c7848150 | 656 | diff_cmp expected actual |
daf7a0c0 JS |
657 | ' |
658 | ||
8e407bc8 TG |
659 | test_expect_success 'stash show --patience shows diff' ' |
660 | git reset --hard && | |
661 | echo foo >>file && | |
662 | STASH_ID=$(git stash create) && | |
663 | git reset --hard && | |
664 | cat >expected <<-EOF && | |
665 | diff --git a/file b/file | |
666 | index 7601807..71b52c4 100644 | |
667 | --- a/file | |
668 | +++ b/file | |
669 | @@ -1 +1,2 @@ | |
670 | baz | |
671 | +foo | |
672 | EOF | |
673 | git stash show --patience ${STASH_ID} >actual && | |
c7848150 | 674 | diff_cmp expected actual |
8e407bc8 TG |
675 | ' |
676 | ||
ab8ad46e | 677 | test_expect_success 'drop: fail early if specified stash is not a stash ref' ' |
daf7a0c0 JS |
678 | git stash clear && |
679 | test_when_finished "git reset --hard HEAD && git stash clear" && | |
680 | git reset --hard && | |
6a0b88b2 | 681 | echo foo >file && |
daf7a0c0 | 682 | git stash && |
6a0b88b2 | 683 | echo bar >file && |
daf7a0c0 | 684 | git stash && |
8d66bb05 | 685 | test_must_fail git stash drop $(git rev-parse stash@{0}) && |
daf7a0c0 JS |
686 | git stash pop && |
687 | test bar = "$(cat file)" && | |
688 | git reset --hard HEAD | |
689 | ' | |
690 | ||
ab8ad46e | 691 | test_expect_success 'pop: fail early if specified stash is not a stash ref' ' |
daf7a0c0 JS |
692 | git stash clear && |
693 | test_when_finished "git reset --hard HEAD && git stash clear" && | |
694 | git reset --hard && | |
6a0b88b2 | 695 | echo foo >file && |
daf7a0c0 | 696 | git stash && |
6a0b88b2 | 697 | echo bar >file && |
daf7a0c0 | 698 | git stash && |
8d66bb05 | 699 | test_must_fail git stash pop $(git rev-parse stash@{0}) && |
daf7a0c0 JS |
700 | git stash pop && |
701 | test bar = "$(cat file)" && | |
702 | git reset --hard HEAD | |
703 | ' | |
704 | ||
7be8b3ba | 705 | test_expect_success 'ref with non-existent reflog' ' |
daf7a0c0 | 706 | git stash clear && |
6a0b88b2 PSU |
707 | echo bar5 >file && |
708 | echo bar6 >file2 && | |
daf7a0c0 JS |
709 | git add file2 && |
710 | git stash && | |
1ae96444 | 711 | test_must_fail git rev-parse --quiet --verify does-not-exist && |
8d66bb05 JS |
712 | test_must_fail git stash drop does-not-exist && |
713 | test_must_fail git stash drop does-not-exist@{0} && | |
714 | test_must_fail git stash pop does-not-exist && | |
715 | test_must_fail git stash pop does-not-exist@{0} && | |
716 | test_must_fail git stash apply does-not-exist && | |
717 | test_must_fail git stash apply does-not-exist@{0} && | |
718 | test_must_fail git stash show does-not-exist && | |
719 | test_must_fail git stash show does-not-exist@{0} && | |
720 | test_must_fail git stash branch tmp does-not-exist && | |
721 | test_must_fail git stash branch tmp does-not-exist@{0} && | |
daf7a0c0 JS |
722 | git stash drop |
723 | ' | |
724 | ||
725 | test_expect_success 'invalid ref of the form stash@{n}, n >= N' ' | |
726 | git stash clear && | |
8d66bb05 | 727 | test_must_fail git stash drop stash@{0} && |
6a0b88b2 PSU |
728 | echo bar5 >file && |
729 | echo bar6 >file2 && | |
daf7a0c0 JS |
730 | git add file2 && |
731 | git stash && | |
9355fc9c JS |
732 | test_must_fail git stash drop stash@{1} && |
733 | test_must_fail git stash pop stash@{1} && | |
734 | test_must_fail git stash apply stash@{1} && | |
735 | test_must_fail git stash show stash@{1} && | |
736 | test_must_fail git stash branch tmp stash@{1} && | |
daf7a0c0 JS |
737 | git stash drop |
738 | ' | |
739 | ||
a56c8f5a AW |
740 | test_expect_success 'invalid ref of the form "n", n >= N' ' |
741 | git stash clear && | |
742 | test_must_fail git stash drop 0 && | |
743 | echo bar5 >file && | |
744 | echo bar6 >file2 && | |
745 | git add file2 && | |
746 | git stash && | |
747 | test_must_fail git stash drop 1 && | |
748 | test_must_fail git stash pop 1 && | |
749 | test_must_fail git stash apply 1 && | |
750 | test_must_fail git stash show 1 && | |
751 | test_must_fail git stash branch tmp 1 && | |
752 | git stash drop | |
753 | ' | |
754 | ||
63b50c8f TG |
755 | test_expect_success 'valid ref of the form "n", n < N' ' |
756 | git stash clear && | |
757 | echo bar5 >file && | |
758 | echo bar6 >file2 && | |
759 | git add file2 && | |
760 | git stash && | |
761 | git stash show 0 && | |
762 | git stash branch tmp 0 && | |
cbc75a12 | 763 | git checkout main && |
63b50c8f TG |
764 | git stash && |
765 | git stash apply 0 && | |
766 | git reset --hard && | |
767 | git stash pop 0 && | |
768 | git stash && | |
769 | git stash drop 0 && | |
770 | test_must_fail git stash drop | |
771 | ' | |
772 | ||
ab8ad46e | 773 | test_expect_success 'branch: do not drop the stash if the branch exists' ' |
835d6a1f TC |
774 | git stash clear && |
775 | echo foo >file && | |
776 | git add file && | |
777 | git commit -m initial && | |
778 | echo bar >file && | |
779 | git stash && | |
cbc75a12 | 780 | test_must_fail git stash branch main stash@{0} && |
835d6a1f TC |
781 | git rev-parse stash@{0} -- |
782 | ' | |
783 | ||
ab8ad46e | 784 | test_expect_success 'branch: should not drop the stash if the apply fails' ' |
b04e6915 JT |
785 | git stash clear && |
786 | git reset HEAD~1 --hard && | |
787 | echo foo >file && | |
788 | git add file && | |
789 | git commit -m initial && | |
790 | echo bar >file && | |
791 | git stash && | |
792 | echo baz >file && | |
cbc75a12 | 793 | test_when_finished "git checkout main" && |
b04e6915 JT |
794 | test_must_fail git stash branch new_branch stash@{0} && |
795 | git rev-parse stash@{0} -- | |
796 | ' | |
797 | ||
ab8ad46e | 798 | test_expect_success 'apply: show same status as git status (relative to ./)' ' |
6eaf92f3 PK |
799 | git stash clear && |
800 | echo 1 >subdir/subfile1 && | |
801 | echo 2 >subdir/subfile2 && | |
802 | git add subdir/subfile1 && | |
803 | git commit -m subdir && | |
804 | ( | |
805 | cd subdir && | |
806 | echo x >subfile1 && | |
807 | echo x >../file && | |
808 | git status >../expect && | |
809 | git stash && | |
810 | sane_unset GIT_MERGE_VERBOSITY && | |
811 | git stash apply | |
812 | ) | | |
1790f4fe | 813 | sed -e 1d >actual && # drop "Saved..." |
1108cea7 | 814 | test_cmp expect actual |
6eaf92f3 PK |
815 | ' |
816 | ||
6a0b88b2 | 817 | cat >expect <<EOF |
44df2e29 JM |
818 | diff --git a/HEAD b/HEAD |
819 | new file mode 100644 | |
820 | index 0000000..fe0cbee | |
821 | --- /dev/null | |
822 | +++ b/HEAD | |
823 | @@ -0,0 +1 @@ | |
824 | +file-not-a-ref | |
825 | EOF | |
826 | ||
827 | test_expect_success 'stash where working directory contains "HEAD" file' ' | |
828 | git stash clear && | |
829 | git reset --hard && | |
6a0b88b2 | 830 | echo file-not-a-ref >HEAD && |
44df2e29 JM |
831 | git add HEAD && |
832 | test_tick && | |
833 | git stash && | |
834 | git diff-files --quiet && | |
835 | git diff-index --cached --quiet HEAD && | |
836 | test "$(git rev-parse stash^)" = "$(git rev-parse HEAD)" && | |
6a0b88b2 | 837 | git diff stash^..stash >output && |
c7848150 | 838 | diff_cmp expect output |
44df2e29 JM |
839 | ' |
840 | ||
bd514cad RR |
841 | test_expect_success 'store called with invalid commit' ' |
842 | test_must_fail git stash store foo | |
843 | ' | |
844 | ||
845 | test_expect_success 'store updates stash ref and reflog' ' | |
846 | git stash clear && | |
847 | git reset --hard && | |
848 | echo quux >bazzy && | |
849 | git add bazzy && | |
850 | STASH_ID=$(git stash create) && | |
851 | git reset --hard && | |
79b04f9b | 852 | test_path_is_missing bazzy && |
bd514cad | 853 | git stash store -m quuxery $STASH_ID && |
cbc5cf7c | 854 | test $(git rev-parse stash) = $STASH_ID && |
d0ab0584 | 855 | git reflog --format=%H stash| grep $STASH_ID && |
bd514cad RR |
856 | git stash pop && |
857 | grep quux bazzy | |
858 | ' | |
859 | ||
2a07e437 ØW |
860 | test_expect_success 'handle stash specification with spaces' ' |
861 | git stash clear && | |
862 | echo pig >file && | |
863 | git stash && | |
864 | stamp=$(git log -g --format="%cd" -1 refs/stash) && | |
865 | test_tick && | |
866 | echo cow >file && | |
867 | git stash && | |
868 | git stash apply "stash@{$stamp}" && | |
869 | grep pig file | |
870 | ' | |
871 | ||
288c67ca JK |
872 | test_expect_success 'setup stash with index and worktree changes' ' |
873 | git stash clear && | |
874 | git reset --hard && | |
875 | echo index >file && | |
876 | git add file && | |
877 | echo working >file && | |
878 | git stash | |
879 | ' | |
880 | ||
1e20a407 | 881 | test_expect_success 'stash list -p shows simple diff' ' |
f2f3fc95 JK |
882 | cat >expect <<-EOF && |
883 | stash@{0} | |
288c67ca JK |
884 | |
885 | diff --git a/file b/file | |
886 | index 257cc56..d26b33d 100644 | |
887 | --- a/file | |
888 | +++ b/file | |
889 | @@ -1 +1 @@ | |
890 | -foo | |
891 | +working | |
892 | EOF | |
f2f3fc95 | 893 | git stash list --format=%gd -p >actual && |
c7848150 | 894 | diff_cmp expect actual |
288c67ca JK |
895 | ' |
896 | ||
897 | test_expect_success 'stash list --cc shows combined diff' ' | |
898 | cat >expect <<-\EOF && | |
f2f3fc95 | 899 | stash@{0} |
288c67ca JK |
900 | |
901 | diff --cc file | |
902 | index 257cc56,9015a7a..d26b33d | |
903 | --- a/file | |
904 | +++ b/file | |
905 | @@@ -1,1 -1,1 +1,1 @@@ | |
906 | - foo | |
907 | -index | |
908 | ++working | |
909 | EOF | |
f2f3fc95 | 910 | git stash list --format=%gd -p --cc >actual && |
c7848150 | 911 | diff_cmp expect actual |
288c67ca JK |
912 | ' |
913 | ||
9d4e28ea JK |
914 | test_expect_success 'stash is not confused by partial renames' ' |
915 | mv file renamed && | |
916 | git add renamed && | |
917 | git stash && | |
918 | git stash apply && | |
919 | test_path_is_file renamed && | |
920 | test_path_is_missing file | |
921 | ' | |
922 | ||
f5727e26 TG |
923 | test_expect_success 'push -m shows right message' ' |
924 | >foo && | |
925 | git add foo && | |
926 | git stash push -m "test message" && | |
cbc75a12 | 927 | echo "stash@{0}: On main: test message" >expect && |
f5727e26 TG |
928 | git stash list -1 >actual && |
929 | test_cmp expect actual | |
930 | ' | |
931 | ||
5675473f PH |
932 | test_expect_success 'push -m also works without space' ' |
933 | >foo && | |
934 | git add foo && | |
935 | git stash push -m"unspaced test message" && | |
cbc75a12 | 936 | echo "stash@{0}: On main: unspaced test message" >expect && |
5675473f PH |
937 | git stash list -1 >actual && |
938 | test_cmp expect actual | |
939 | ' | |
940 | ||
941 | test_expect_success 'store -m foo shows right message' ' | |
942 | git stash clear && | |
943 | git reset --hard && | |
944 | echo quux >bazzy && | |
945 | git add bazzy && | |
946 | STASH_ID=$(git stash create) && | |
947 | git stash store -m "store m" $STASH_ID && | |
948 | echo "stash@{0}: store m" >expect && | |
949 | git stash list -1 >actual && | |
950 | test_cmp expect actual | |
951 | ' | |
952 | ||
953 | test_expect_success 'store -mfoo shows right message' ' | |
954 | git stash clear && | |
955 | git reset --hard && | |
956 | echo quux >bazzy && | |
957 | git add bazzy && | |
958 | STASH_ID=$(git stash create) && | |
959 | git stash store -m"store mfoo" $STASH_ID && | |
960 | echo "stash@{0}: store mfoo" >expect && | |
961 | git stash list -1 >actual && | |
962 | test_cmp expect actual | |
963 | ' | |
964 | ||
965 | test_expect_success 'store --message=foo shows right message' ' | |
966 | git stash clear && | |
967 | git reset --hard && | |
968 | echo quux >bazzy && | |
969 | git add bazzy && | |
970 | STASH_ID=$(git stash create) && | |
971 | git stash store --message="store message=foo" $STASH_ID && | |
972 | echo "stash@{0}: store message=foo" >expect && | |
973 | git stash list -1 >actual && | |
974 | test_cmp expect actual | |
975 | ' | |
976 | ||
977 | test_expect_success 'store --message foo shows right message' ' | |
978 | git stash clear && | |
979 | git reset --hard && | |
980 | echo quux >bazzy && | |
981 | git add bazzy && | |
982 | STASH_ID=$(git stash create) && | |
983 | git stash store --message "store message foo" $STASH_ID && | |
984 | echo "stash@{0}: store message foo" >expect && | |
985 | git stash list -1 >actual && | |
986 | test_cmp expect actual | |
987 | ' | |
988 | ||
989 | test_expect_success 'push -mfoo uses right message' ' | |
990 | >foo && | |
991 | git add foo && | |
992 | git stash push -m"test mfoo" && | |
cbc75a12 | 993 | echo "stash@{0}: On main: test mfoo" >expect && |
5675473f PH |
994 | git stash list -1 >actual && |
995 | test_cmp expect actual | |
996 | ' | |
997 | ||
998 | test_expect_success 'push --message foo is synonym for -mfoo' ' | |
999 | >foo && | |
1000 | git add foo && | |
1001 | git stash push --message "test message foo" && | |
cbc75a12 | 1002 | echo "stash@{0}: On main: test message foo" >expect && |
5675473f PH |
1003 | git stash list -1 >actual && |
1004 | test_cmp expect actual | |
1005 | ' | |
1006 | ||
1007 | test_expect_success 'push --message=foo is synonym for -mfoo' ' | |
1008 | >foo && | |
1009 | git add foo && | |
1010 | git stash push --message="test message=foo" && | |
cbc75a12 | 1011 | echo "stash@{0}: On main: test message=foo" >expect && |
5675473f PH |
1012 | git stash list -1 >actual && |
1013 | test_cmp expect actual | |
1014 | ' | |
1015 | ||
1016 | test_expect_success 'push -m shows right message' ' | |
1017 | >foo && | |
1018 | git add foo && | |
1019 | git stash push -m "test m foo" && | |
cbc75a12 | 1020 | echo "stash@{0}: On main: test m foo" >expect && |
5675473f PH |
1021 | git stash list -1 >actual && |
1022 | test_cmp expect actual | |
1023 | ' | |
1024 | ||
6f5ccd4d TG |
1025 | test_expect_success 'create stores correct message' ' |
1026 | >foo && | |
1027 | git add foo && | |
1028 | STASH_ID=$(git stash create "create test message") && | |
cbc75a12 | 1029 | echo "On main: create test message" >expect && |
6f5ccd4d TG |
1030 | git show --pretty=%s -s ${STASH_ID} >actual && |
1031 | test_cmp expect actual | |
1032 | ' | |
1033 | ||
1034 | test_expect_success 'create with multiple arguments for the message' ' | |
1035 | >foo && | |
1036 | git add foo && | |
1037 | STASH_ID=$(git stash create test untracked) && | |
cbc75a12 | 1038 | echo "On main: test untracked" >expect && |
6f5ccd4d TG |
1039 | git show --pretty=%s -s ${STASH_ID} >actual && |
1040 | test_cmp expect actual | |
1041 | ' | |
1042 | ||
4e9bf3dd | 1043 | test_expect_success 'create in a detached state' ' |
cbc75a12 | 1044 | test_when_finished "git checkout main" && |
4e9bf3dd JT |
1045 | git checkout HEAD~1 && |
1046 | >foo && | |
1047 | git add foo && | |
1048 | STASH_ID=$(git stash create) && | |
1049 | HEAD_ID=$(git rev-parse --short HEAD) && | |
1050 | echo "WIP on (no branch): ${HEAD_ID} initial" >expect && | |
1051 | git show --pretty=%s -s ${STASH_ID} >actual && | |
1052 | test_cmp expect actual | |
1053 | ' | |
1054 | ||
df6bba09 TG |
1055 | test_expect_success 'stash -- <pathspec> stashes and restores the file' ' |
1056 | >foo && | |
1057 | >bar && | |
1058 | git add foo bar && | |
1059 | git stash push -- foo && | |
1060 | test_path_is_file bar && | |
1061 | test_path_is_missing foo && | |
1062 | git stash pop && | |
1063 | test_path_is_file foo && | |
1064 | test_path_is_file bar | |
1065 | ' | |
1066 | ||
22fc703e PS |
1067 | test_expect_success 'stash -- <pathspec> stashes in subdirectory' ' |
1068 | mkdir sub && | |
1069 | >foo && | |
1070 | >bar && | |
1071 | git add foo bar && | |
1072 | ( | |
1073 | cd sub && | |
1074 | git stash push -- ../foo | |
1075 | ) && | |
1076 | test_path_is_file bar && | |
1077 | test_path_is_missing foo && | |
1078 | git stash pop && | |
1079 | test_path_is_file foo && | |
1080 | test_path_is_file bar | |
1081 | ' | |
1082 | ||
df6bba09 TG |
1083 | test_expect_success 'stash with multiple pathspec arguments' ' |
1084 | >foo && | |
1085 | >bar && | |
1086 | >extra && | |
1087 | git add foo bar extra && | |
1088 | git stash push -- foo bar && | |
1089 | test_path_is_missing bar && | |
1090 | test_path_is_missing foo && | |
1091 | test_path_is_file extra && | |
1092 | git stash pop && | |
1093 | test_path_is_file foo && | |
1094 | test_path_is_file bar && | |
1095 | test_path_is_file extra | |
1096 | ' | |
1097 | ||
1098 | test_expect_success 'stash with file including $IFS character' ' | |
1099 | >"foo bar" && | |
1100 | >foo && | |
1101 | >bar && | |
1102 | git add foo* && | |
1103 | git stash push -- "foo b*" && | |
1104 | test_path_is_missing "foo bar" && | |
1105 | test_path_is_file foo && | |
1106 | test_path_is_file bar && | |
1107 | git stash pop && | |
1108 | test_path_is_file "foo bar" && | |
1109 | test_path_is_file foo && | |
1110 | test_path_is_file bar | |
1111 | ' | |
1112 | ||
1113 | test_expect_success 'stash with pathspec matching multiple paths' ' | |
1114 | echo original >file && | |
1115 | echo original >other-file && | |
1116 | git commit -m "two" file other-file && | |
1117 | echo modified >file && | |
1118 | echo modified >other-file && | |
1119 | git stash push -- "*file" && | |
1120 | echo original >expect && | |
1121 | test_cmp expect file && | |
1122 | test_cmp expect other-file && | |
1123 | git stash pop && | |
1124 | echo modified >expect && | |
1125 | test_cmp expect file && | |
1126 | test_cmp expect other-file | |
1127 | ' | |
1128 | ||
1129 | test_expect_success 'stash push -p with pathspec shows no changes only once' ' | |
1130 | >foo && | |
1131 | git add foo && | |
1132 | git commit -m "tmp" && | |
1133 | git stash push -p foo >actual && | |
1134 | echo "No local changes to save" >expect && | |
1135 | git reset --hard HEAD~ && | |
1108cea7 | 1136 | test_cmp expect actual |
df6bba09 TG |
1137 | ' |
1138 | ||
ab8ad46e | 1139 | test_expect_success 'push <pathspec>: show no changes when there are none' ' |
df6bba09 TG |
1140 | >foo && |
1141 | git add foo && | |
1142 | git commit -m "tmp" && | |
1143 | git stash push foo >actual && | |
1144 | echo "No local changes to save" >expect && | |
1145 | git reset --hard HEAD~ && | |
1108cea7 | 1146 | test_cmp expect actual |
df6bba09 TG |
1147 | ' |
1148 | ||
ab8ad46e | 1149 | test_expect_success 'push: <pathspec> not in the repository errors out' ' |
df6bba09 TG |
1150 | >untracked && |
1151 | test_must_fail git stash push untracked && | |
1152 | test_path_is_file untracked | |
1153 | ' | |
1154 | ||
1ac528c0 PSU |
1155 | test_expect_success 'push: -q is quiet with changes' ' |
1156 | >foo && | |
1157 | git add foo && | |
1158 | git stash push -q >output 2>&1 && | |
1159 | test_must_be_empty output | |
1160 | ' | |
1161 | ||
1162 | test_expect_success 'push: -q is quiet with no changes' ' | |
1163 | git stash push -q >output 2>&1 && | |
1164 | test_must_be_empty output | |
1165 | ' | |
1166 | ||
1167 | test_expect_success 'push: -q is quiet even if there is no initial commit' ' | |
1168 | git init foo_dir && | |
1169 | test_when_finished rm -rf foo_dir && | |
1170 | ( | |
1171 | cd foo_dir && | |
1172 | >bar && | |
1173 | test_must_fail git stash push -q >output 2>&1 && | |
1174 | test_must_be_empty output | |
1175 | ) | |
1176 | ' | |
1177 | ||
df6bba09 TG |
1178 | test_expect_success 'untracked files are left in place when -u is not given' ' |
1179 | >file && | |
1180 | git add file && | |
1181 | >untracked && | |
1182 | git stash push file && | |
1183 | test_path_is_file untracked | |
1184 | ' | |
1185 | ||
9e140909 TG |
1186 | test_expect_success 'stash without verb with pathspec' ' |
1187 | >"foo bar" && | |
1188 | >foo && | |
1189 | >bar && | |
1190 | git add foo* && | |
1191 | git stash -- "foo b*" && | |
1192 | test_path_is_missing "foo bar" && | |
1193 | test_path_is_file foo && | |
1194 | test_path_is_file bar && | |
1195 | git stash pop && | |
1196 | test_path_is_file "foo bar" && | |
1197 | test_path_is_file foo && | |
1198 | test_path_is_file bar | |
1199 | ' | |
1200 | ||
e0e7f99e TG |
1201 | test_expect_success 'stash -k -- <pathspec> leaves unstaged files intact' ' |
1202 | git reset && | |
1203 | >foo && | |
1204 | >bar && | |
1205 | git add foo bar && | |
1206 | git commit -m "test" && | |
1207 | echo "foo" >foo && | |
1208 | echo "bar" >bar && | |
1209 | git stash -k -- foo && | |
1210 | test "",bar = $(cat foo),$(cat bar) && | |
1211 | git stash pop && | |
1212 | test foo,bar = $(cat foo),$(cat bar) | |
1213 | ' | |
1214 | ||
bba067d2 TG |
1215 | test_expect_success 'stash -- <subdir> leaves untracked files in subdir intact' ' |
1216 | git reset && | |
1217 | >subdir/untracked && | |
1218 | >subdir/tracked1 && | |
1219 | >subdir/tracked2 && | |
1220 | git add subdir/tracked* && | |
1221 | git stash -- subdir/ && | |
1222 | test_path_is_missing subdir/tracked1 && | |
1223 | test_path_is_missing subdir/tracked2 && | |
1224 | test_path_is_file subdir/untracked && | |
1225 | git stash pop && | |
1226 | test_path_is_file subdir/tracked1 && | |
1227 | test_path_is_file subdir/tracked2 && | |
1228 | test_path_is_file subdir/untracked | |
1229 | ' | |
1230 | ||
1231 | test_expect_success 'stash -- <subdir> works with binary files' ' | |
1232 | git reset && | |
1233 | >subdir/untracked && | |
1234 | >subdir/tracked && | |
1235 | cp "$TEST_DIRECTORY"/test-binary-1.png subdir/tracked-binary && | |
1236 | git add subdir/tracked* && | |
1237 | git stash -- subdir/ && | |
1238 | test_path_is_missing subdir/tracked && | |
1239 | test_path_is_missing subdir/tracked-binary && | |
1240 | test_path_is_file subdir/untracked && | |
1241 | git stash pop && | |
1242 | test_path_is_file subdir/tracked && | |
1243 | test_path_is_file subdir/tracked-binary && | |
1244 | test_path_is_file subdir/untracked | |
1245 | ' | |
1246 | ||
0640897d TG |
1247 | test_expect_success 'stash with user.name and user.email set works' ' |
1248 | test_config user.name "A U Thor" && | |
1249 | test_config user.email "a.u@thor" && | |
1250 | git stash | |
1251 | ' | |
1252 | ||
3bc2111f SD |
1253 | test_expect_success 'stash works when user.name and user.email are not set' ' |
1254 | git reset && | |
1255 | >1 && | |
1256 | git add 1 && | |
1257 | echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" >expect && | |
1258 | git stash && | |
1259 | git show -s --format="%an <%ae>" refs/stash >actual && | |
1260 | test_cmp expect actual && | |
1261 | >2 && | |
1262 | git add 2 && | |
1263 | test_config user.useconfigonly true && | |
1264 | test_config stash.usebuiltin true && | |
1265 | ( | |
1266 | sane_unset GIT_AUTHOR_NAME && | |
1267 | sane_unset GIT_AUTHOR_EMAIL && | |
1268 | sane_unset GIT_COMMITTER_NAME && | |
1269 | sane_unset GIT_COMMITTER_EMAIL && | |
1270 | test_unconfig user.email && | |
1271 | test_unconfig user.name && | |
1272 | test_must_fail git commit -m "should fail" && | |
1273 | echo "git stash <git@stash>" >expect && | |
1274 | >2 && | |
1275 | git stash && | |
1276 | git show -s --format="%an <%ae>" refs/stash >actual && | |
1277 | test_cmp expect actual | |
1278 | ) | |
1279 | ' | |
1280 | ||
b932f6a5 TG |
1281 | test_expect_success 'stash --keep-index with file deleted in index does not resurrect it on disk' ' |
1282 | test_commit to-remove to-remove && | |
1283 | git rm to-remove && | |
1284 | git stash --keep-index && | |
1285 | test_path_is_missing to-remove | |
1286 | ' | |
1287 | ||
34933d0e TG |
1288 | test_expect_success 'stash apply should succeed with unmodified file' ' |
1289 | echo base >file && | |
1290 | git add file && | |
1291 | git commit -m base && | |
1292 | ||
1293 | # now stash a modification | |
1294 | echo modified >file && | |
1295 | git stash && | |
1296 | ||
1297 | # make the file stat dirty | |
1298 | cp file other && | |
1299 | mv other file && | |
1300 | ||
1301 | git stash apply | |
1302 | ' | |
1303 | ||
4a58c3d7 JS |
1304 | test_expect_success 'stash handles skip-worktree entries nicely' ' |
1305 | test_commit A && | |
1306 | echo changed >A.t && | |
1307 | git add A.t && | |
1308 | git update-index --skip-worktree A.t && | |
1309 | rm A.t && | |
1310 | git stash && | |
1311 | ||
1312 | git rev-parse --verify refs/stash:A.t | |
1313 | ' | |
1314 | ||
8a2cd3f5 TG |
1315 | test_expect_success 'stash -c stash.useBuiltin=false warning ' ' |
1316 | expected="stash.useBuiltin support has been removed" && | |
1317 | ||
1318 | git -c stash.useBuiltin=false stash 2>err && | |
1319 | test_i18ngrep "$expected" err && | |
1320 | env GIT_TEST_STASH_USE_BUILTIN=false git stash 2>err && | |
1321 | test_i18ngrep "$expected" err && | |
1322 | ||
1323 | git -c stash.useBuiltin=true stash 2>err && | |
1324 | test_must_be_empty err && | |
1325 | env GIT_TEST_STASH_USE_BUILTIN=true git stash 2>err && | |
1326 | test_must_be_empty err | |
1327 | ' | |
1328 | ||
3d40e372 | 1329 | test_expect_success 'git stash succeeds despite directory/file change' ' |
4dbf7f30 EN |
1330 | test_create_repo directory_file_switch_v1 && |
1331 | ( | |
1332 | cd directory_file_switch_v1 && | |
1333 | test_commit init && | |
1334 | ||
1335 | test_write_lines this file has some words >filler && | |
1336 | git add filler && | |
1337 | git commit -m filler && | |
1338 | ||
1339 | git rm filler && | |
1340 | mkdir filler && | |
1341 | echo contents >filler/file && | |
1342 | git stash push | |
1343 | ) | |
1344 | ' | |
1345 | ||
bee8691f | 1346 | test_expect_success 'git stash can pop file -> directory saved changes' ' |
4dbf7f30 EN |
1347 | test_create_repo directory_file_switch_v2 && |
1348 | ( | |
1349 | cd directory_file_switch_v2 && | |
1350 | test_commit init && | |
1351 | ||
1352 | test_write_lines this file has some words >filler && | |
1353 | git add filler && | |
1354 | git commit -m filler && | |
1355 | ||
1356 | git rm filler && | |
1357 | mkdir filler && | |
1358 | echo contents >filler/file && | |
1359 | cp filler/file expect && | |
1360 | git stash push --include-untracked && | |
1361 | git stash apply --index && | |
1362 | test_cmp expect filler/file | |
1363 | ) | |
1364 | ' | |
1365 | ||
bee8691f | 1366 | test_expect_success 'git stash can pop directory -> file saved changes' ' |
4dbf7f30 EN |
1367 | test_create_repo directory_file_switch_v3 && |
1368 | ( | |
1369 | cd directory_file_switch_v3 && | |
1370 | test_commit init && | |
1371 | ||
1372 | mkdir filler && | |
1373 | test_write_lines some words >filler/file1 && | |
1374 | test_write_lines and stuff >filler/file2 && | |
1375 | git add filler && | |
1376 | git commit -m filler && | |
1377 | ||
1378 | git rm -rf filler && | |
1379 | echo contents >filler && | |
1380 | cp filler expect && | |
1381 | git stash push --include-untracked && | |
1382 | git stash apply --index && | |
1383 | test_cmp expect filler | |
1384 | ) | |
1385 | ' | |
1386 | ||
150937c4 | 1387 | test_done |