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