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