]> git.ipfire.org Git - thirdparty/git.git/blob - t/t3600-rm.sh
Merge branch 'sg/t5310-jgit-wants-sha1'
[thirdparty/git.git] / t / t3600-rm.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Carl D. Worth
4 #
5
6 test_description='Test of the various options to git rm.'
7
8 . ./test-lib.sh
9
10 # Setup some files to be removed, some with funny characters
11 test_expect_success 'Initialize test directory' '
12 touch -- foo bar baz "space embedded" -q &&
13 git add -- foo bar baz "space embedded" -q &&
14 git commit -m "add normal files"
15 '
16
17 if test_have_prereq !FUNNYNAMES
18 then
19 say 'Your filesystem does not allow tabs in filenames.'
20 fi
21
22 test_expect_success FUNNYNAMES 'add files with funny names' '
23 touch -- "tab embedded" "newline${LF}embedded" &&
24 git add -- "tab embedded" "newline${LF}embedded" &&
25 git commit -m "add files with tabs and newlines"
26 '
27
28 test_expect_success 'Pre-check that foo exists and is in index before git rm foo' '
29 test_path_is_file foo &&
30 git ls-files --error-unmatch foo
31 '
32
33 test_expect_success 'Test that git rm foo succeeds' '
34 git rm --cached foo
35 '
36
37 test_expect_success 'Test that git rm --cached foo succeeds if the index matches the file' '
38 echo content >foo &&
39 git add foo &&
40 git rm --cached foo
41 '
42
43 test_expect_success 'Test that git rm --cached foo succeeds if the index matches the file' '
44 echo content >foo &&
45 git add foo &&
46 git commit -m foo &&
47 echo "other content" >foo &&
48 git rm --cached foo
49 '
50
51 test_expect_success 'Test that git rm --cached foo fails if the index matches neither the file nor HEAD' '
52 echo content >foo &&
53 git add foo &&
54 git commit -m foo --allow-empty &&
55 echo "other content" >foo &&
56 git add foo &&
57 echo "yet another content" >foo &&
58 test_must_fail git rm --cached foo
59 '
60
61 test_expect_success 'Test that git rm --cached -f foo works in case where --cached only did not' '
62 echo content >foo &&
63 git add foo &&
64 git commit -m foo --allow-empty &&
65 echo "other content" >foo &&
66 git add foo &&
67 echo "yet another content" >foo &&
68 git rm --cached -f foo
69 '
70
71 test_expect_success 'Post-check that foo exists but is not in index after git rm foo' '
72 test_path_is_file foo &&
73 test_must_fail git ls-files --error-unmatch foo
74 '
75
76 test_expect_success 'Pre-check that bar exists and is in index before "git rm bar"' '
77 test_path_is_file bar &&
78 git ls-files --error-unmatch bar
79 '
80
81 test_expect_success 'Test that "git rm bar" succeeds' '
82 git rm bar
83 '
84
85 test_expect_success 'Post-check that bar does not exist and is not in index after "git rm -f bar"' '
86 test_path_is_missing bar &&
87 test_must_fail git ls-files --error-unmatch bar
88 '
89
90 test_expect_success 'Test that "git rm -- -q" succeeds (remove a file that looks like an option)' '
91 git rm -- -q
92 '
93
94 test_expect_success FUNNYNAMES 'Test that "git rm -f" succeeds with embedded space, tab, or newline characters.' '
95 git rm -f "space embedded" "tab embedded" "newline${LF}embedded"
96 '
97
98 test_expect_success SANITY 'Test that "git rm -f" fails if its rm fails' '
99 test_when_finished "chmod 775 ." &&
100 chmod a-w . &&
101 test_must_fail git rm -f baz
102 '
103
104 test_expect_success 'When the rm in "git rm -f" fails, it should not remove the file from the index' '
105 git ls-files --error-unmatch baz
106 '
107
108 test_expect_success 'Remove nonexistent file with --ignore-unmatch' '
109 git rm --ignore-unmatch nonexistent
110 '
111
112 test_expect_success '"rm" command printed' '
113 echo frotz >test-file &&
114 git add test-file &&
115 git commit -m "add file for rm test" &&
116 git rm test-file >rm-output.raw &&
117 grep "^rm " rm-output.raw >rm-output &&
118 test_line_count = 1 rm-output &&
119 rm -f test-file rm-output.raw rm-output &&
120 git commit -m "remove file from rm test"
121 '
122
123 test_expect_success '"rm" command suppressed with --quiet' '
124 echo frotz >test-file &&
125 git add test-file &&
126 git commit -m "add file for rm --quiet test" &&
127 git rm --quiet test-file >rm-output &&
128 test_must_be_empty rm-output &&
129 rm -f test-file rm-output &&
130 git commit -m "remove file from rm --quiet test"
131 '
132
133 # Now, failure cases.
134 test_expect_success 'Re-add foo and baz' '
135 git add foo baz &&
136 git ls-files --error-unmatch foo baz
137 '
138
139 test_expect_success 'Modify foo -- rm should refuse' '
140 echo >>foo &&
141 test_must_fail git rm foo baz &&
142 test_path_is_file foo &&
143 test_path_is_file baz &&
144 git ls-files --error-unmatch foo baz
145 '
146
147 test_expect_success 'Modified foo -- rm -f should work' '
148 git rm -f foo baz &&
149 test_path_is_missing foo &&
150 test_path_is_missing baz &&
151 test_must_fail git ls-files --error-unmatch foo &&
152 test_must_fail git ls-files --error-unmatch bar
153 '
154
155 test_expect_success 'Re-add foo and baz for HEAD tests' '
156 echo frotz >foo &&
157 git checkout HEAD -- baz &&
158 git add foo baz &&
159 git ls-files --error-unmatch foo baz
160 '
161
162 test_expect_success 'foo is different in index from HEAD -- rm should refuse' '
163 test_must_fail git rm foo baz &&
164 test_path_is_file foo &&
165 test_path_is_file baz &&
166 git ls-files --error-unmatch foo baz
167 '
168
169 test_expect_success 'but with -f it should work.' '
170 git rm -f foo baz &&
171 test_path_is_missing foo &&
172 test_path_is_missing baz &&
173 test_must_fail git ls-files --error-unmatch foo &&
174 test_must_fail git ls-files --error-unmatch baz
175 '
176
177 test_expect_success 'refuse to remove cached empty file with modifications' '
178 >empty &&
179 git add empty &&
180 echo content >empty &&
181 test_must_fail git rm --cached empty
182 '
183
184 test_expect_success 'remove intent-to-add file without --force' '
185 echo content >intent-to-add &&
186 git add -N intent-to-add &&
187 git rm --cached intent-to-add
188 '
189
190 test_expect_success 'Recursive test setup' '
191 mkdir -p frotz &&
192 echo qfwfq >frotz/nitfol &&
193 git add frotz &&
194 git commit -m "subdir test"
195 '
196
197 test_expect_success 'Recursive without -r fails' '
198 test_must_fail git rm frotz &&
199 test_path_is_dir frotz &&
200 test_path_is_file frotz/nitfol
201 '
202
203 test_expect_success 'Recursive with -r but dirty' '
204 echo qfwfq >>frotz/nitfol &&
205 test_must_fail git rm -r frotz &&
206 test_path_is_dir frotz &&
207 test_path_is_file frotz/nitfol
208 '
209
210 test_expect_success 'Recursive with -r -f' '
211 git rm -f -r frotz &&
212 test_path_is_missing frotz/nitfol &&
213 test_path_is_missing frotz
214 '
215
216 test_expect_success 'Remove nonexistent file returns nonzero exit status' '
217 test_must_fail git rm nonexistent
218 '
219
220 test_expect_success 'Call "rm" from outside the work tree' '
221 mkdir repo &&
222 (
223 cd repo &&
224 git init &&
225 echo something >somefile &&
226 git add somefile &&
227 git commit -m "add a file" &&
228 (
229 cd .. &&
230 git --git-dir=repo/.git --work-tree=repo rm somefile
231 ) &&
232 test_must_fail git ls-files --error-unmatch somefile
233 )
234 '
235
236 test_expect_success 'refresh index before checking if it is up-to-date' '
237 git reset --hard &&
238 test-tool chmtime -86400 frotz/nitfol &&
239 git rm frotz/nitfol &&
240 test_path_is_missing frotz/nitfol
241 '
242
243 test_expect_success 'choking "git rm" should not let it die with cruft' '
244 git reset -q --hard &&
245 test_when_finished "rm -f .git/index.lock && git reset -q --hard" &&
246 i=0 &&
247 hash=$(test_oid deadbeef) &&
248 while test $i -lt 12000
249 do
250 echo "100644 $hash 0 some-file-$i"
251 i=$(( $i + 1 ))
252 done | git update-index --index-info &&
253 # git command is intentionally placed upstream of pipe to induce SIGPIPE
254 git rm -n "some-file-*" | : &&
255 test_path_is_missing .git/index.lock
256 '
257
258 test_expect_success 'Resolving by removal is not a warning-worthy event' '
259 git reset -q --hard &&
260 test_when_finished "rm -f .git/index.lock msg && git reset -q --hard" &&
261 blob=$(echo blob | git hash-object -w --stdin) &&
262 for stage in 1 2 3
263 do
264 echo "100644 $blob $stage blob"
265 done | git update-index --index-info &&
266 git rm blob >msg 2>&1 &&
267 test_i18ngrep ! "needs merge" msg &&
268 test_must_fail git ls-files -s --error-unmatch blob
269 '
270
271 test_expect_success 'rm removes subdirectories recursively' '
272 mkdir -p dir/subdir/subsubdir &&
273 echo content >dir/subdir/subsubdir/file &&
274 git add dir/subdir/subsubdir/file &&
275 git rm -f dir/subdir/subsubdir/file &&
276 test_path_is_missing dir
277 '
278
279 cat >expect <<EOF
280 M .gitmodules
281 D submod
282 EOF
283
284 cat >expect.modified <<EOF
285 M submod
286 EOF
287
288 cat >expect.modified_inside <<EOF
289 m submod
290 EOF
291
292 cat >expect.modified_untracked <<EOF
293 ? submod
294 EOF
295
296 cat >expect.cached <<EOF
297 D submod
298 EOF
299
300 cat >expect.both_deleted<<EOF
301 D .gitmodules
302 D submod
303 EOF
304
305 test_expect_success 'rm removes empty submodules from work tree' '
306 mkdir submod &&
307 hash=$(git rev-parse HEAD) &&
308 git update-index --add --cacheinfo 160000 "$hash" submod &&
309 git config -f .gitmodules submodule.sub.url ./. &&
310 git config -f .gitmodules submodule.sub.path submod &&
311 git submodule init &&
312 git add .gitmodules &&
313 git commit -m "add submodule" &&
314 git rm submod &&
315 test_path_is_missing submod &&
316 git status -s -uno --ignore-submodules=none >actual &&
317 test_cmp expect actual &&
318 test_must_fail git config -f .gitmodules submodule.sub.url &&
319 test_must_fail git config -f .gitmodules submodule.sub.path
320 '
321
322 test_expect_success 'rm removes removed submodule from index and .gitmodules' '
323 git reset --hard &&
324 git submodule update &&
325 rm -rf submod &&
326 git rm submod &&
327 git status -s -uno --ignore-submodules=none >actual &&
328 test_cmp expect actual &&
329 test_must_fail git config -f .gitmodules submodule.sub.url &&
330 test_must_fail git config -f .gitmodules submodule.sub.path
331 '
332
333 test_expect_success 'rm removes work tree of unmodified submodules' '
334 git reset --hard &&
335 git submodule update &&
336 git rm submod &&
337 test_path_is_missing submod &&
338 git status -s -uno --ignore-submodules=none >actual &&
339 test_cmp expect actual &&
340 test_must_fail git config -f .gitmodules submodule.sub.url &&
341 test_must_fail git config -f .gitmodules submodule.sub.path
342 '
343
344 test_expect_success 'rm removes a submodule with a trailing /' '
345 git reset --hard &&
346 git submodule update &&
347 git rm submod/ &&
348 test_path_is_missing submod &&
349 git status -s -uno --ignore-submodules=none >actual &&
350 test_cmp expect actual
351 '
352
353 test_expect_success 'rm fails when given a file with a trailing /' '
354 test_must_fail git rm empty/
355 '
356
357 test_expect_success 'rm succeeds when given a directory with a trailing /' '
358 git rm -r frotz/
359 '
360
361 test_expect_success 'rm of a populated submodule with different HEAD fails unless forced' '
362 git reset --hard &&
363 git submodule update &&
364 git -C submod checkout HEAD^ &&
365 test_must_fail git rm submod &&
366 test_path_is_dir submod &&
367 test_path_is_file submod/.git &&
368 git status -s -uno --ignore-submodules=none >actual &&
369 test_cmp expect.modified actual &&
370 git rm -f submod &&
371 test_path_is_missing submod &&
372 git status -s -uno --ignore-submodules=none >actual &&
373 test_cmp expect actual &&
374 test_must_fail git config -f .gitmodules submodule.sub.url &&
375 test_must_fail git config -f .gitmodules submodule.sub.path
376 '
377
378 test_expect_success 'rm --cached leaves work tree of populated submodules and .gitmodules alone' '
379 git reset --hard &&
380 git submodule update &&
381 git rm --cached submod &&
382 test_path_is_dir submod &&
383 test_path_is_file submod/.git &&
384 git status -s -uno >actual &&
385 test_cmp expect.cached actual &&
386 git config -f .gitmodules submodule.sub.url &&
387 git config -f .gitmodules submodule.sub.path
388 '
389
390 test_expect_success 'rm --dry-run does not touch the submodule or .gitmodules' '
391 git reset --hard &&
392 git submodule update &&
393 git rm -n submod &&
394 test_path_is_file submod/.git &&
395 git diff-index --exit-code HEAD
396 '
397
398 test_expect_success 'rm does not complain when no .gitmodules file is found' '
399 git reset --hard &&
400 git submodule update &&
401 git rm .gitmodules &&
402 git rm submod >actual 2>actual.err &&
403 test_must_be_empty actual.err &&
404 test_path_is_missing submod &&
405 test_path_is_missing submod/.git &&
406 git status -s -uno >actual &&
407 test_cmp expect.both_deleted actual
408 '
409
410 test_expect_success 'rm will error out on a modified .gitmodules file unless staged' '
411 git reset --hard &&
412 git submodule update &&
413 git config -f .gitmodules foo.bar true &&
414 test_must_fail git rm submod >actual 2>actual.err &&
415 test_file_not_empty actual.err &&
416 test_path_is_dir submod &&
417 test_path_is_file submod/.git &&
418 git diff-files --quiet -- submod &&
419 git add .gitmodules &&
420 git rm submod >actual 2>actual.err &&
421 test_must_be_empty actual.err &&
422 test_path_is_missing submod &&
423 test_path_is_missing submod/.git &&
424 git status -s -uno >actual &&
425 test_cmp expect actual
426 '
427 test_expect_success 'rm will not error out on .gitmodules file with zero stat data' '
428 git reset --hard &&
429 git submodule update &&
430 git read-tree HEAD &&
431 git rm submod &&
432 test_path_is_missing submod
433 '
434
435 test_expect_success 'rm issues a warning when section is not found in .gitmodules' '
436 git reset --hard &&
437 git submodule update &&
438 git config -f .gitmodules --remove-section submodule.sub &&
439 git add .gitmodules &&
440 echo "warning: Could not find section in .gitmodules where path=submod" >expect.err &&
441 git rm submod >actual 2>actual.err &&
442 test_i18ncmp expect.err actual.err &&
443 test_path_is_missing submod &&
444 test_path_is_missing submod/.git &&
445 git status -s -uno >actual &&
446 test_cmp expect actual
447 '
448
449 test_expect_success 'rm of a populated submodule with modifications fails unless forced' '
450 git reset --hard &&
451 git submodule update &&
452 echo X >submod/empty &&
453 test_must_fail git rm submod &&
454 test_path_is_dir submod &&
455 test_path_is_file submod/.git &&
456 git status -s -uno --ignore-submodules=none >actual &&
457 test_cmp expect.modified_inside actual &&
458 git rm -f submod &&
459 test_path_is_missing submod &&
460 git status -s -uno --ignore-submodules=none >actual &&
461 test_cmp expect actual
462 '
463
464 test_expect_success 'rm of a populated submodule with untracked files fails unless forced' '
465 git reset --hard &&
466 git submodule update &&
467 echo X >submod/untracked &&
468 test_must_fail git rm submod &&
469 test_path_is_dir submod &&
470 test_path_is_file submod/.git &&
471 git status -s -uno --ignore-submodules=none >actual &&
472 test_cmp expect.modified_untracked actual &&
473 git rm -f submod &&
474 test_path_is_missing submod &&
475 git status -s -uno --ignore-submodules=none >actual &&
476 test_cmp expect actual
477 '
478
479 test_expect_success 'setup submodule conflict' '
480 git reset --hard &&
481 git submodule update &&
482 git checkout -b branch1 &&
483 echo 1 >nitfol &&
484 git add nitfol &&
485 git commit -m "added nitfol 1" &&
486 git checkout -b branch2 master &&
487 echo 2 >nitfol &&
488 git add nitfol &&
489 git commit -m "added nitfol 2" &&
490 git checkout -b conflict1 master &&
491 git -C submod fetch &&
492 git -C submod checkout branch1 &&
493 git add submod &&
494 git commit -m "submod 1" &&
495 git checkout -b conflict2 master &&
496 git -C submod checkout branch2 &&
497 git add submod &&
498 git commit -m "submod 2"
499 '
500
501 cat >expect.conflict <<EOF
502 UU submod
503 EOF
504
505 test_expect_success 'rm removes work tree of unmodified conflicted submodule' '
506 git checkout conflict1 &&
507 git reset --hard &&
508 git submodule update &&
509 test_must_fail git merge conflict2 &&
510 git rm submod &&
511 test_path_is_missing submod &&
512 git status -s -uno --ignore-submodules=none >actual &&
513 test_cmp expect actual
514 '
515
516 test_expect_success 'rm of a conflicted populated submodule with different HEAD fails unless forced' '
517 git checkout conflict1 &&
518 git reset --hard &&
519 git submodule update &&
520 git -C submod checkout HEAD^ &&
521 test_must_fail git merge conflict2 &&
522 test_must_fail git rm submod &&
523 test_path_is_dir submod &&
524 test_path_is_file submod/.git &&
525 git status -s -uno --ignore-submodules=none >actual &&
526 test_cmp expect.conflict actual &&
527 git rm -f submod &&
528 test_path_is_missing submod &&
529 git status -s -uno --ignore-submodules=none >actual &&
530 test_cmp expect actual &&
531 test_must_fail git config -f .gitmodules submodule.sub.url &&
532 test_must_fail git config -f .gitmodules submodule.sub.path
533 '
534
535 test_expect_success 'rm of a conflicted populated submodule with modifications fails unless forced' '
536 git checkout conflict1 &&
537 git reset --hard &&
538 git submodule update &&
539 echo X >submod/empty &&
540 test_must_fail git merge conflict2 &&
541 test_must_fail git rm submod &&
542 test_path_is_dir submod &&
543 test_path_is_file submod/.git &&
544 git status -s -uno --ignore-submodules=none >actual &&
545 test_cmp expect.conflict actual &&
546 git rm -f submod &&
547 test_path_is_missing submod &&
548 git status -s -uno --ignore-submodules=none >actual &&
549 test_cmp expect actual &&
550 test_must_fail git config -f .gitmodules submodule.sub.url &&
551 test_must_fail git config -f .gitmodules submodule.sub.path
552 '
553
554 test_expect_success 'rm of a conflicted populated submodule with untracked files fails unless forced' '
555 git checkout conflict1 &&
556 git reset --hard &&
557 git submodule update &&
558 echo X >submod/untracked &&
559 test_must_fail git merge conflict2 &&
560 test_must_fail git rm submod &&
561 test_path_is_dir submod &&
562 test_path_is_file submod/.git &&
563 git status -s -uno --ignore-submodules=none >actual &&
564 test_cmp expect.conflict actual &&
565 git rm -f submod &&
566 test_path_is_missing submod &&
567 git status -s -uno --ignore-submodules=none >actual &&
568 test_cmp expect actual
569 '
570
571 test_expect_success 'rm of a conflicted populated submodule with a .git directory fails even when forced' '
572 git checkout conflict1 &&
573 git reset --hard &&
574 git submodule update &&
575 (
576 cd submod &&
577 rm .git &&
578 cp -R ../.git/modules/sub .git &&
579 GIT_WORK_TREE=. git config --unset core.worktree
580 ) &&
581 test_must_fail git merge conflict2 &&
582 test_must_fail git rm submod &&
583 test_path_is_dir submod &&
584 test_path_is_dir submod/.git &&
585 git status -s -uno --ignore-submodules=none >actual &&
586 test_cmp expect.conflict actual &&
587 test_must_fail git rm -f submod &&
588 test_path_is_dir submod &&
589 test_path_is_dir submod/.git &&
590 git status -s -uno --ignore-submodules=none >actual &&
591 test_cmp expect.conflict actual &&
592 git merge --abort &&
593 rm -rf submod
594 '
595
596 test_expect_success 'rm of a conflicted unpopulated submodule succeeds' '
597 git checkout conflict1 &&
598 git reset --hard &&
599 test_must_fail git merge conflict2 &&
600 git rm submod &&
601 test_path_is_missing submod &&
602 git status -s -uno --ignore-submodules=none >actual &&
603 test_cmp expect actual
604 '
605
606 test_expect_success 'rm of a populated submodule with a .git directory migrates git dir' '
607 git checkout -f master &&
608 git reset --hard &&
609 git submodule update &&
610 (
611 cd submod &&
612 rm .git &&
613 cp -R ../.git/modules/sub .git &&
614 GIT_WORK_TREE=. git config --unset core.worktree &&
615 rm -r ../.git/modules/sub
616 ) &&
617 git rm submod 2>output.err &&
618 test_path_is_missing submod &&
619 test_path_is_missing submod/.git &&
620 git status -s -uno --ignore-submodules=none >actual &&
621 test_file_not_empty actual &&
622 test_i18ngrep Migrating output.err
623 '
624
625 cat >expect.deepmodified <<EOF
626 M submod/subsubmod
627 EOF
628
629 test_expect_success 'setup subsubmodule' '
630 git reset --hard &&
631 git submodule update &&
632 (
633 cd submod &&
634 hash=$(git rev-parse HEAD) &&
635 git update-index --add --cacheinfo 160000 "$hash" subsubmod &&
636 git config -f .gitmodules submodule.sub.url ../. &&
637 git config -f .gitmodules submodule.sub.path subsubmod &&
638 git submodule init &&
639 git add .gitmodules &&
640 git commit -m "add subsubmodule" &&
641 git submodule update subsubmod
642 ) &&
643 git commit -a -m "added deep submodule"
644 '
645
646 test_expect_success 'rm recursively removes work tree of unmodified submodules' '
647 git rm submod &&
648 test_path_is_missing submod &&
649 git status -s -uno --ignore-submodules=none >actual &&
650 test_cmp expect actual
651 '
652
653 test_expect_success 'rm of a populated nested submodule with different nested HEAD fails unless forced' '
654 git reset --hard &&
655 git submodule update --recursive &&
656 git -C submod/subsubmod checkout HEAD^ &&
657 test_must_fail git rm submod &&
658 test_path_is_dir submod &&
659 test_path_is_file submod/.git &&
660 git status -s -uno --ignore-submodules=none >actual &&
661 test_cmp expect.modified_inside actual &&
662 git rm -f submod &&
663 test_path_is_missing submod &&
664 git status -s -uno --ignore-submodules=none >actual &&
665 test_cmp expect actual
666 '
667
668 test_expect_success 'rm of a populated nested submodule with nested modifications fails unless forced' '
669 git reset --hard &&
670 git submodule update --recursive &&
671 echo X >submod/subsubmod/empty &&
672 test_must_fail git rm submod &&
673 test_path_is_dir submod &&
674 test_path_is_file submod/.git &&
675 git status -s -uno --ignore-submodules=none >actual &&
676 test_cmp expect.modified_inside actual &&
677 git rm -f submod &&
678 test_path_is_missing submod &&
679 git status -s -uno --ignore-submodules=none >actual &&
680 test_cmp expect actual
681 '
682
683 test_expect_success 'rm of a populated nested submodule with nested untracked files fails unless forced' '
684 git reset --hard &&
685 git submodule update --recursive &&
686 echo X >submod/subsubmod/untracked &&
687 test_must_fail git rm submod &&
688 test_path_is_dir submod &&
689 test_path_is_file submod/.git &&
690 git status -s -uno --ignore-submodules=none >actual &&
691 test_cmp expect.modified_untracked actual &&
692 git rm -f submod &&
693 test_path_is_missing submod &&
694 git status -s -uno --ignore-submodules=none >actual &&
695 test_cmp expect actual
696 '
697
698 test_expect_success "rm absorbs submodule's nested .git directory" '
699 git reset --hard &&
700 git submodule update --recursive &&
701 (
702 cd submod/subsubmod &&
703 rm .git &&
704 mv ../../.git/modules/sub/modules/sub .git &&
705 GIT_WORK_TREE=. git config --unset core.worktree
706 ) &&
707 git rm submod 2>output.err &&
708 test_path_is_missing submod &&
709 test_path_is_missing submod/subsubmod/.git &&
710 git status -s -uno --ignore-submodules=none >actual &&
711 test_file_not_empty actual &&
712 test_i18ngrep Migrating output.err
713 '
714
715 test_expect_success 'checking out a commit after submodule removal needs manual updates' '
716 git commit -m "submodule removal" submod .gitmodules &&
717 git checkout HEAD^ &&
718 git submodule update &&
719 git checkout -q HEAD^ &&
720 git checkout -q master 2>actual &&
721 test_i18ngrep "^warning: unable to rmdir '\''submod'\'':" actual &&
722 git status -s submod >actual &&
723 echo "?? submod/" >expected &&
724 test_cmp expected actual &&
725 rm -rf submod &&
726 git status -s -uno --ignore-submodules=none >actual &&
727 test_must_be_empty actual
728 '
729
730 test_expect_success 'rm of d/f when d has become a non-directory' '
731 rm -rf d &&
732 mkdir d &&
733 >d/f &&
734 git add d &&
735 rm -rf d &&
736 >d &&
737 git rm d/f &&
738 test_must_fail git rev-parse --verify :d/f &&
739 test_path_is_file d
740 '
741
742 test_expect_success SYMLINKS 'rm of d/f when d has become a dangling symlink' '
743 rm -rf d &&
744 mkdir d &&
745 >d/f &&
746 git add d &&
747 rm -rf d &&
748 ln -s nonexistent d &&
749 git rm d/f &&
750 test_must_fail git rev-parse --verify :d/f &&
751 test -h d &&
752 test_path_is_missing d
753 '
754
755 test_expect_success 'rm of file when it has become a directory' '
756 rm -rf d &&
757 >d &&
758 git add d &&
759 rm -f d &&
760 mkdir d &&
761 >d/f &&
762 test_must_fail git rm d &&
763 git rev-parse --verify :d &&
764 test_path_is_file d/f
765 '
766
767 test_expect_success SYMLINKS 'rm across a symlinked leading path (no index)' '
768 rm -rf d e &&
769 mkdir e &&
770 echo content >e/f &&
771 ln -s e d &&
772 git add -A e d &&
773 git commit -m "symlink d to e, e/f exists" &&
774 test_must_fail git rm d/f &&
775 git rev-parse --verify :d &&
776 git rev-parse --verify :e/f &&
777 test -h d &&
778 test_path_is_file e/f
779 '
780
781 test_expect_failure SYMLINKS 'rm across a symlinked leading path (w/ index)' '
782 rm -rf d e &&
783 mkdir d &&
784 echo content >d/f &&
785 git add -A e d &&
786 git commit -m "d/f exists" &&
787 mv d e &&
788 ln -s e d &&
789 test_must_fail git rm d/f &&
790 git rev-parse --verify :d/f &&
791 test -h d &&
792 test_path_is_file e/f
793 '
794
795 test_expect_success 'setup for testing rm messages' '
796 >bar.txt &&
797 >foo.txt &&
798 git add bar.txt foo.txt
799 '
800
801 test_expect_success 'rm files with different staged content' '
802 cat >expect <<-\EOF &&
803 error: the following files have staged content different from both the
804 file and the HEAD:
805 bar.txt
806 foo.txt
807 (use -f to force removal)
808 EOF
809 echo content1 >foo.txt &&
810 echo content1 >bar.txt &&
811 test_must_fail git rm foo.txt bar.txt 2>actual &&
812 test_i18ncmp expect actual
813 '
814
815 test_expect_success 'rm files with different staged content without hints' '
816 cat >expect <<-\EOF &&
817 error: the following files have staged content different from both the
818 file and the HEAD:
819 bar.txt
820 foo.txt
821 EOF
822 echo content2 >foo.txt &&
823 echo content2 >bar.txt &&
824 test_must_fail git -c advice.rmhints=false rm foo.txt bar.txt 2>actual &&
825 test_i18ncmp expect actual
826 '
827
828 test_expect_success 'rm file with local modification' '
829 cat >expect <<-\EOF &&
830 error: the following file has local modifications:
831 foo.txt
832 (use --cached to keep the file, or -f to force removal)
833 EOF
834 git commit -m "testing rm 3" &&
835 echo content3 >foo.txt &&
836 test_must_fail git rm foo.txt 2>actual &&
837 test_i18ncmp expect actual
838 '
839
840 test_expect_success 'rm file with local modification without hints' '
841 cat >expect <<-\EOF &&
842 error: the following file has local modifications:
843 bar.txt
844 EOF
845 echo content4 >bar.txt &&
846 test_must_fail git -c advice.rmhints=false rm bar.txt 2>actual &&
847 test_i18ncmp expect actual
848 '
849
850 test_expect_success 'rm file with changes in the index' '
851 cat >expect <<-\EOF &&
852 error: the following file has changes staged in the index:
853 foo.txt
854 (use --cached to keep the file, or -f to force removal)
855 EOF
856 git reset --hard &&
857 echo content5 >foo.txt &&
858 git add foo.txt &&
859 test_must_fail git rm foo.txt 2>actual &&
860 test_i18ncmp expect actual
861 '
862
863 test_expect_success 'rm file with changes in the index without hints' '
864 cat >expect <<-\EOF &&
865 error: the following file has changes staged in the index:
866 foo.txt
867 EOF
868 test_must_fail git -c advice.rmhints=false rm foo.txt 2>actual &&
869 test_i18ncmp expect actual
870 '
871
872 test_expect_success 'rm files with two different errors' '
873 cat >expect <<-\EOF &&
874 error: the following file has staged content different from both the
875 file and the HEAD:
876 foo1.txt
877 (use -f to force removal)
878 error: the following file has changes staged in the index:
879 bar1.txt
880 (use --cached to keep the file, or -f to force removal)
881 EOF
882 echo content >foo1.txt &&
883 git add foo1.txt &&
884 echo content6 >foo1.txt &&
885 echo content6 >bar1.txt &&
886 git add bar1.txt &&
887 test_must_fail git rm bar1.txt foo1.txt 2>actual &&
888 test_i18ncmp expect actual
889 '
890
891 test_expect_success 'rm empty string should fail' '
892 test_must_fail git rm -rf ""
893 '
894
895 test_done