use get_tagged_oid()
[git/debian.git] / t / t3600-rm.sh
blob66282a720ee853e7442334c889e199978aac9260
1 #!/bin/sh
3 # Copyright (c) 2006 Carl D. Worth
6 test_description='Test of the various options to git rm.'
8 . ./test-lib.sh
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"
17 if test_have_prereq !FUNNYNAMES
18 then
19 say 'Your filesystem does not allow tabs in filenames.'
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"
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
33 test_expect_success 'Test that git rm foo succeeds' '
34 git rm --cached foo
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
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
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
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
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
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
81 test_expect_success 'Test that "git rm bar" succeeds' '
82 git rm bar
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
90 test_expect_success 'Test that "git rm -- -q" succeeds (remove a file that looks like an option)' '
91 git rm -- -q
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"
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
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
108 test_expect_success 'Remove nonexistent file with --ignore-unmatch' '
109 git rm --ignore-unmatch nonexistent
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 &&
117 test $(grep "^rm " rm-output | wc -l) = 1 &&
118 rm -f test-file rm-output &&
119 git commit -m "remove file from rm test"
122 test_expect_success '"rm" command suppressed with --quiet' '
123 echo frotz >test-file &&
124 git add test-file &&
125 git commit -m "add file for rm --quiet test" &&
126 git rm --quiet test-file >rm-output &&
127 test_must_be_empty rm-output &&
128 rm -f test-file rm-output &&
129 git commit -m "remove file from rm --quiet test"
132 # Now, failure cases.
133 test_expect_success 'Re-add foo and baz' '
134 git add foo baz &&
135 git ls-files --error-unmatch foo baz
138 test_expect_success 'Modify foo -- rm should refuse' '
139 echo >>foo &&
140 test_must_fail git rm foo baz &&
141 test_path_is_file foo &&
142 test_path_is_file baz &&
143 git ls-files --error-unmatch foo baz
146 test_expect_success 'Modified foo -- rm -f should work' '
147 git rm -f foo baz &&
148 test_path_is_missing foo &&
149 test_path_is_missing baz &&
150 test_must_fail git ls-files --error-unmatch foo &&
151 test_must_fail git ls-files --error-unmatch bar
154 test_expect_success 'Re-add foo and baz for HEAD tests' '
155 echo frotz >foo &&
156 git checkout HEAD -- baz &&
157 git add foo baz &&
158 git ls-files --error-unmatch foo baz
161 test_expect_success 'foo is different in index from HEAD -- rm should refuse' '
162 test_must_fail git rm foo baz &&
163 test_path_is_file foo &&
164 test_path_is_file baz &&
165 git ls-files --error-unmatch foo baz
168 test_expect_success 'but with -f it should work.' '
169 git rm -f foo baz &&
170 test_path_is_missing foo &&
171 test_path_is_missing baz &&
172 test_must_fail git ls-files --error-unmatch foo &&
173 test_must_fail git ls-files --error-unmatch baz
176 test_expect_success 'refuse to remove cached empty file with modifications' '
177 >empty &&
178 git add empty &&
179 echo content >empty &&
180 test_must_fail git rm --cached empty
183 test_expect_success 'remove intent-to-add file without --force' '
184 echo content >intent-to-add &&
185 git add -N intent-to-add &&
186 git rm --cached intent-to-add
189 test_expect_success 'Recursive test setup' '
190 mkdir -p frotz &&
191 echo qfwfq >frotz/nitfol &&
192 git add frotz &&
193 git commit -m "subdir test"
196 test_expect_success 'Recursive without -r fails' '
197 test_must_fail git rm frotz &&
198 test_path_is_dir frotz &&
199 test_path_is_file frotz/nitfol
202 test_expect_success 'Recursive with -r but dirty' '
203 echo qfwfq >>frotz/nitfol &&
204 test_must_fail git rm -r frotz &&
205 test_path_is_dir frotz &&
206 test_path_is_file frotz/nitfol
209 test_expect_success 'Recursive with -r -f' '
210 git rm -f -r frotz &&
211 test_path_is_missing frotz/nitfol &&
212 test_path_is_missing frotz
215 test_expect_success 'Remove nonexistent file returns nonzero exit status' '
216 test_must_fail git rm nonexistent
219 test_expect_success 'Call "rm" from outside the work tree' '
220 mkdir repo &&
222 cd repo &&
223 git init &&
224 echo something >somefile &&
225 git add somefile &&
226 git commit -m "add a file" &&
228 cd .. &&
229 git --git-dir=repo/.git --work-tree=repo rm somefile
230 ) &&
231 test_must_fail git ls-files --error-unmatch somefile
235 test_expect_success 'refresh index before checking if it is up-to-date' '
236 git reset --hard &&
237 test-tool chmtime -86400 frotz/nitfol &&
238 git rm frotz/nitfol &&
239 test_path_is_missing frotz/nitfol
242 test_expect_success 'choking "git rm" should not let it die with cruft' '
243 git reset -q --hard &&
244 test_when_finished "rm -f .git/index.lock && git reset -q --hard" &&
245 i=0 &&
246 while test $i -lt 12000
248 echo "100644 1234567890123456789012345678901234567890 0 some-file-$i"
249 i=$(( $i + 1 ))
250 done | git update-index --index-info &&
251 git rm -n "some-file-*" | : &&
252 test_path_is_missing .git/index.lock
255 test_expect_success 'Resolving by removal is not a warning-worthy event' '
256 git reset -q --hard &&
257 test_when_finished "rm -f .git/index.lock msg && git reset -q --hard" &&
258 blob=$(echo blob | git hash-object -w --stdin) &&
259 for stage in 1 2 3
261 echo "100644 $blob $stage blob"
262 done | git update-index --index-info &&
263 git rm blob >msg 2>&1 &&
264 test_i18ngrep ! "needs merge" msg &&
265 test_must_fail git ls-files -s --error-unmatch blob
268 test_expect_success 'rm removes subdirectories recursively' '
269 mkdir -p dir/subdir/subsubdir &&
270 echo content >dir/subdir/subsubdir/file &&
271 git add dir/subdir/subsubdir/file &&
272 git rm -f dir/subdir/subsubdir/file &&
273 test_path_is_missing dir
276 cat >expect <<EOF
277 M .gitmodules
278 D submod
281 cat >expect.modified <<EOF
282 M submod
285 cat >expect.modified_inside <<EOF
286 m submod
289 cat >expect.modified_untracked <<EOF
290 ? submod
293 cat >expect.cached <<EOF
294 D submod
297 cat >expect.both_deleted<<EOF
298 D .gitmodules
299 D submod
302 test_expect_success 'rm removes empty submodules from work tree' '
303 mkdir submod &&
304 git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) submod &&
305 git config -f .gitmodules submodule.sub.url ./. &&
306 git config -f .gitmodules submodule.sub.path submod &&
307 git submodule init &&
308 git add .gitmodules &&
309 git commit -m "add submodule" &&
310 git rm submod &&
311 test_path_is_missing submod &&
312 git status -s -uno --ignore-submodules=none >actual &&
313 test_cmp expect actual &&
314 test_must_fail git config -f .gitmodules submodule.sub.url &&
315 test_must_fail git config -f .gitmodules submodule.sub.path
318 test_expect_success 'rm removes removed submodule from index and .gitmodules' '
319 git reset --hard &&
320 git submodule update &&
321 rm -rf submod &&
322 git rm submod &&
323 git status -s -uno --ignore-submodules=none >actual &&
324 test_cmp expect actual &&
325 test_must_fail git config -f .gitmodules submodule.sub.url &&
326 test_must_fail git config -f .gitmodules submodule.sub.path
329 test_expect_success 'rm removes work tree of unmodified submodules' '
330 git reset --hard &&
331 git submodule update &&
332 git rm submod &&
333 test_path_is_missing submod &&
334 git status -s -uno --ignore-submodules=none >actual &&
335 test_cmp expect actual &&
336 test_must_fail git config -f .gitmodules submodule.sub.url &&
337 test_must_fail git config -f .gitmodules submodule.sub.path
340 test_expect_success 'rm removes a submodule with a trailing /' '
341 git reset --hard &&
342 git submodule update &&
343 git rm submod/ &&
344 test_path_is_missing submod &&
345 git status -s -uno --ignore-submodules=none >actual &&
346 test_cmp expect actual
349 test_expect_success 'rm fails when given a file with a trailing /' '
350 test_must_fail git rm empty/
353 test_expect_success 'rm succeeds when given a directory with a trailing /' '
354 git rm -r frotz/
357 test_expect_success 'rm of a populated submodule with different HEAD fails unless forced' '
358 git reset --hard &&
359 git submodule update &&
360 git -C submod checkout HEAD^ &&
361 test_must_fail git rm submod &&
362 test_path_is_dir submod &&
363 test_path_is_file submod/.git &&
364 git status -s -uno --ignore-submodules=none >actual &&
365 test_cmp expect.modified actual &&
366 git rm -f submod &&
367 test_path_is_missing submod &&
368 git status -s -uno --ignore-submodules=none >actual &&
369 test_cmp expect actual &&
370 test_must_fail git config -f .gitmodules submodule.sub.url &&
371 test_must_fail git config -f .gitmodules submodule.sub.path
374 test_expect_success 'rm --cached leaves work tree of populated submodules and .gitmodules alone' '
375 git reset --hard &&
376 git submodule update &&
377 git rm --cached submod &&
378 test_path_is_dir submod &&
379 test_path_is_file submod/.git &&
380 git status -s -uno >actual &&
381 test_cmp expect.cached actual &&
382 git config -f .gitmodules submodule.sub.url &&
383 git config -f .gitmodules submodule.sub.path
386 test_expect_success 'rm --dry-run does not touch the submodule or .gitmodules' '
387 git reset --hard &&
388 git submodule update &&
389 git rm -n submod &&
390 test_path_is_file submod/.git &&
391 git diff-index --exit-code HEAD
394 test_expect_success 'rm does not complain when no .gitmodules file is found' '
395 git reset --hard &&
396 git submodule update &&
397 git rm .gitmodules &&
398 git rm submod >actual 2>actual.err &&
399 test_must_be_empty actual.err &&
400 test_path_is_missing submod &&
401 test_path_is_missing submod/.git &&
402 git status -s -uno >actual &&
403 test_cmp expect.both_deleted actual
406 test_expect_success 'rm will error out on a modified .gitmodules file unless staged' '
407 git reset --hard &&
408 git submodule update &&
409 git config -f .gitmodules foo.bar true &&
410 test_must_fail git rm submod >actual 2>actual.err &&
411 test_file_not_empty actual.err &&
412 test_path_is_dir submod &&
413 test_path_is_file submod/.git &&
414 git diff-files --quiet -- submod &&
415 git add .gitmodules &&
416 git rm submod >actual 2>actual.err &&
417 test_must_be_empty actual.err &&
418 test_path_is_missing submod &&
419 test_path_is_missing submod/.git &&
420 git status -s -uno >actual &&
421 test_cmp expect actual
424 test_expect_success 'rm issues a warning when section is not found in .gitmodules' '
425 git reset --hard &&
426 git submodule update &&
427 git config -f .gitmodules --remove-section submodule.sub &&
428 git add .gitmodules &&
429 echo "warning: Could not find section in .gitmodules where path=submod" >expect.err &&
430 git rm submod >actual 2>actual.err &&
431 test_i18ncmp expect.err actual.err &&
432 test_path_is_missing submod &&
433 test_path_is_missing submod/.git &&
434 git status -s -uno >actual &&
435 test_cmp expect actual
438 test_expect_success 'rm of a populated submodule with modifications fails unless forced' '
439 git reset --hard &&
440 git submodule update &&
441 echo X >submod/empty &&
442 test_must_fail git rm submod &&
443 test_path_is_dir submod &&
444 test_path_is_file submod/.git &&
445 git status -s -uno --ignore-submodules=none >actual &&
446 test_cmp expect.modified_inside actual &&
447 git rm -f submod &&
448 test_path_is_missing submod &&
449 git status -s -uno --ignore-submodules=none >actual &&
450 test_cmp expect actual
453 test_expect_success 'rm of a populated submodule with untracked files fails unless forced' '
454 git reset --hard &&
455 git submodule update &&
456 echo X >submod/untracked &&
457 test_must_fail git rm submod &&
458 test_path_is_dir submod &&
459 test_path_is_file submod/.git &&
460 git status -s -uno --ignore-submodules=none >actual &&
461 test_cmp expect.modified_untracked actual &&
462 git rm -f submod &&
463 test_path_is_missing submod &&
464 git status -s -uno --ignore-submodules=none >actual &&
465 test_cmp expect actual
468 test_expect_success 'setup submodule conflict' '
469 git reset --hard &&
470 git submodule update &&
471 git checkout -b branch1 &&
472 echo 1 >nitfol &&
473 git add nitfol &&
474 git commit -m "added nitfol 1" &&
475 git checkout -b branch2 master &&
476 echo 2 >nitfol &&
477 git add nitfol &&
478 git commit -m "added nitfol 2" &&
479 git checkout -b conflict1 master &&
480 git -C submod fetch &&
481 git -C submod checkout branch1 &&
482 git add submod &&
483 git commit -m "submod 1" &&
484 git checkout -b conflict2 master &&
485 git -C submod checkout branch2 &&
486 git add submod &&
487 git commit -m "submod 2"
490 cat >expect.conflict <<EOF
491 UU submod
494 test_expect_success 'rm removes work tree of unmodified conflicted submodule' '
495 git checkout conflict1 &&
496 git reset --hard &&
497 git submodule update &&
498 test_must_fail git merge conflict2 &&
499 git rm submod &&
500 test_path_is_missing submod &&
501 git status -s -uno --ignore-submodules=none >actual &&
502 test_cmp expect actual
505 test_expect_success 'rm of a conflicted populated submodule with different HEAD fails unless forced' '
506 git checkout conflict1 &&
507 git reset --hard &&
508 git submodule update &&
509 git -C submod checkout HEAD^ &&
510 test_must_fail git merge conflict2 &&
511 test_must_fail git rm submod &&
512 test_path_is_dir submod &&
513 test_path_is_file submod/.git &&
514 git status -s -uno --ignore-submodules=none >actual &&
515 test_cmp expect.conflict actual &&
516 git rm -f submod &&
517 test_path_is_missing submod &&
518 git status -s -uno --ignore-submodules=none >actual &&
519 test_cmp expect actual &&
520 test_must_fail git config -f .gitmodules submodule.sub.url &&
521 test_must_fail git config -f .gitmodules submodule.sub.path
524 test_expect_success 'rm of a conflicted populated submodule with modifications fails unless forced' '
525 git checkout conflict1 &&
526 git reset --hard &&
527 git submodule update &&
528 echo X >submod/empty &&
529 test_must_fail git merge conflict2 &&
530 test_must_fail git rm submod &&
531 test_path_is_dir submod &&
532 test_path_is_file submod/.git &&
533 git status -s -uno --ignore-submodules=none >actual &&
534 test_cmp expect.conflict actual &&
535 git rm -f submod &&
536 test_path_is_missing submod &&
537 git status -s -uno --ignore-submodules=none >actual &&
538 test_cmp expect actual &&
539 test_must_fail git config -f .gitmodules submodule.sub.url &&
540 test_must_fail git config -f .gitmodules submodule.sub.path
543 test_expect_success 'rm of a conflicted populated submodule with untracked files fails unless forced' '
544 git checkout conflict1 &&
545 git reset --hard &&
546 git submodule update &&
547 echo X >submod/untracked &&
548 test_must_fail git merge conflict2 &&
549 test_must_fail git rm submod &&
550 test_path_is_dir submod &&
551 test_path_is_file submod/.git &&
552 git status -s -uno --ignore-submodules=none >actual &&
553 test_cmp expect.conflict actual &&
554 git rm -f submod &&
555 test_path_is_missing submod &&
556 git status -s -uno --ignore-submodules=none >actual &&
557 test_cmp expect actual
560 test_expect_success 'rm of a conflicted populated submodule with a .git directory fails even when forced' '
561 git checkout conflict1 &&
562 git reset --hard &&
563 git submodule update &&
565 cd submod &&
566 rm .git &&
567 cp -R ../.git/modules/sub .git &&
568 GIT_WORK_TREE=. git config --unset core.worktree
569 ) &&
570 test_must_fail git merge conflict2 &&
571 test_must_fail git rm submod &&
572 test_path_is_dir submod &&
573 test_path_is_dir submod/.git &&
574 git status -s -uno --ignore-submodules=none >actual &&
575 test_cmp expect.conflict actual &&
576 test_must_fail git rm -f submod &&
577 test_path_is_dir submod &&
578 test_path_is_dir submod/.git &&
579 git status -s -uno --ignore-submodules=none >actual &&
580 test_cmp expect.conflict actual &&
581 git merge --abort &&
582 rm -rf submod
585 test_expect_success 'rm of a conflicted unpopulated submodule succeeds' '
586 git checkout conflict1 &&
587 git reset --hard &&
588 test_must_fail git merge conflict2 &&
589 git rm submod &&
590 test_path_is_missing submod &&
591 git status -s -uno --ignore-submodules=none >actual &&
592 test_cmp expect actual
595 test_expect_success 'rm of a populated submodule with a .git directory migrates git dir' '
596 git checkout -f master &&
597 git reset --hard &&
598 git submodule update &&
600 cd submod &&
601 rm .git &&
602 cp -R ../.git/modules/sub .git &&
603 GIT_WORK_TREE=. git config --unset core.worktree &&
604 rm -r ../.git/modules/sub
605 ) &&
606 git rm submod 2>output.err &&
607 test_path_is_missing submod &&
608 test_path_is_missing submod/.git &&
609 git status -s -uno --ignore-submodules=none >actual &&
610 test_file_not_empty actual &&
611 test_i18ngrep Migrating output.err
614 cat >expect.deepmodified <<EOF
615 M submod/subsubmod
618 test_expect_success 'setup subsubmodule' '
619 git reset --hard &&
620 git submodule update &&
622 cd submod &&
623 git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) subsubmod &&
624 git config -f .gitmodules submodule.sub.url ../. &&
625 git config -f .gitmodules submodule.sub.path subsubmod &&
626 git submodule init &&
627 git add .gitmodules &&
628 git commit -m "add subsubmodule" &&
629 git submodule update subsubmod
630 ) &&
631 git commit -a -m "added deep submodule"
634 test_expect_success 'rm recursively removes work tree of unmodified submodules' '
635 git rm submod &&
636 test_path_is_missing submod &&
637 git status -s -uno --ignore-submodules=none >actual &&
638 test_cmp expect actual
641 test_expect_success 'rm of a populated nested submodule with different nested HEAD fails unless forced' '
642 git reset --hard &&
643 git submodule update --recursive &&
644 git -C submod/subsubmod checkout HEAD^ &&
645 test_must_fail git rm submod &&
646 test_path_is_dir submod &&
647 test_path_is_file submod/.git &&
648 git status -s -uno --ignore-submodules=none >actual &&
649 test_cmp expect.modified_inside actual &&
650 git rm -f submod &&
651 test_path_is_missing submod &&
652 git status -s -uno --ignore-submodules=none >actual &&
653 test_cmp expect actual
656 test_expect_success 'rm of a populated nested submodule with nested modifications fails unless forced' '
657 git reset --hard &&
658 git submodule update --recursive &&
659 echo X >submod/subsubmod/empty &&
660 test_must_fail git rm submod &&
661 test_path_is_dir submod &&
662 test_path_is_file submod/.git &&
663 git status -s -uno --ignore-submodules=none >actual &&
664 test_cmp expect.modified_inside actual &&
665 git rm -f submod &&
666 test_path_is_missing submod &&
667 git status -s -uno --ignore-submodules=none >actual &&
668 test_cmp expect actual
671 test_expect_success 'rm of a populated nested submodule with nested untracked files fails unless forced' '
672 git reset --hard &&
673 git submodule update --recursive &&
674 echo X >submod/subsubmod/untracked &&
675 test_must_fail git rm submod &&
676 test_path_is_dir submod &&
677 test_path_is_file submod/.git &&
678 git status -s -uno --ignore-submodules=none >actual &&
679 test_cmp expect.modified_untracked actual &&
680 git rm -f submod &&
681 test_path_is_missing submod &&
682 git status -s -uno --ignore-submodules=none >actual &&
683 test_cmp expect actual
686 test_expect_success "rm absorbs submodule's nested .git directory" '
687 git reset --hard &&
688 git submodule update --recursive &&
690 cd submod/subsubmod &&
691 rm .git &&
692 mv ../../.git/modules/sub/modules/sub .git &&
693 GIT_WORK_TREE=. git config --unset core.worktree
694 ) &&
695 git rm submod 2>output.err &&
696 test_path_is_missing submod &&
697 test_path_is_missing submod/subsubmod/.git &&
698 git status -s -uno --ignore-submodules=none >actual &&
699 test_file_not_empty actual &&
700 test_i18ngrep Migrating output.err
703 test_expect_success 'checking out a commit after submodule removal needs manual updates' '
704 git commit -m "submodule removal" submod .gitmodules &&
705 git checkout HEAD^ &&
706 git submodule update &&
707 git checkout -q HEAD^ &&
708 git checkout -q master 2>actual &&
709 test_i18ngrep "^warning: unable to rmdir '\''submod'\'':" actual &&
710 git status -s submod >actual &&
711 echo "?? submod/" >expected &&
712 test_cmp expected actual &&
713 rm -rf submod &&
714 git status -s -uno --ignore-submodules=none >actual &&
715 test_must_be_empty actual
718 test_expect_success 'rm of d/f when d has become a non-directory' '
719 rm -rf d &&
720 mkdir d &&
721 >d/f &&
722 git add d &&
723 rm -rf d &&
724 >d &&
725 git rm d/f &&
726 test_must_fail git rev-parse --verify :d/f &&
727 test_path_is_file d
730 test_expect_success SYMLINKS 'rm of d/f when d has become a dangling symlink' '
731 rm -rf d &&
732 mkdir d &&
733 >d/f &&
734 git add d &&
735 rm -rf d &&
736 ln -s nonexistent d &&
737 git rm d/f &&
738 test_must_fail git rev-parse --verify :d/f &&
739 test -h d &&
740 test_path_is_missing d
743 test_expect_success 'rm of file when it has become a directory' '
744 rm -rf d &&
745 >d &&
746 git add d &&
747 rm -f d &&
748 mkdir d &&
749 >d/f &&
750 test_must_fail git rm d &&
751 git rev-parse --verify :d &&
752 test_path_is_file d/f
755 test_expect_success SYMLINKS 'rm across a symlinked leading path (no index)' '
756 rm -rf d e &&
757 mkdir e &&
758 echo content >e/f &&
759 ln -s e d &&
760 git add -A e d &&
761 git commit -m "symlink d to e, e/f exists" &&
762 test_must_fail git rm d/f &&
763 git rev-parse --verify :d &&
764 git rev-parse --verify :e/f &&
765 test -h d &&
766 test_path_is_file e/f
769 test_expect_failure SYMLINKS 'rm across a symlinked leading path (w/ index)' '
770 rm -rf d e &&
771 mkdir d &&
772 echo content >d/f &&
773 git add -A e d &&
774 git commit -m "d/f exists" &&
775 mv d e &&
776 ln -s e d &&
777 test_must_fail git rm d/f &&
778 git rev-parse --verify :d/f &&
779 test -h d &&
780 test_path_is_file e/f
783 test_expect_success 'setup for testing rm messages' '
784 >bar.txt &&
785 >foo.txt &&
786 git add bar.txt foo.txt
789 test_expect_success 'rm files with different staged content' '
790 cat >expect <<-\EOF &&
791 error: the following files have staged content different from both the
792 file and the HEAD:
793 bar.txt
794 foo.txt
795 (use -f to force removal)
797 echo content1 >foo.txt &&
798 echo content1 >bar.txt &&
799 test_must_fail git rm foo.txt bar.txt 2>actual &&
800 test_i18ncmp expect actual
803 test_expect_success 'rm files with different staged content without hints' '
804 cat >expect <<-\EOF &&
805 error: the following files have staged content different from both the
806 file and the HEAD:
807 bar.txt
808 foo.txt
810 echo content2 >foo.txt &&
811 echo content2 >bar.txt &&
812 test_must_fail git -c advice.rmhints=false rm foo.txt bar.txt 2>actual &&
813 test_i18ncmp expect actual
816 test_expect_success 'rm file with local modification' '
817 cat >expect <<-\EOF &&
818 error: the following file has local modifications:
819 foo.txt
820 (use --cached to keep the file, or -f to force removal)
822 git commit -m "testing rm 3" &&
823 echo content3 >foo.txt &&
824 test_must_fail git rm foo.txt 2>actual &&
825 test_i18ncmp expect actual
828 test_expect_success 'rm file with local modification without hints' '
829 cat >expect <<-\EOF &&
830 error: the following file has local modifications:
831 bar.txt
833 echo content4 >bar.txt &&
834 test_must_fail git -c advice.rmhints=false rm bar.txt 2>actual &&
835 test_i18ncmp expect actual
838 test_expect_success 'rm file with changes in the index' '
839 cat >expect <<-\EOF &&
840 error: the following file has changes staged in the index:
841 foo.txt
842 (use --cached to keep the file, or -f to force removal)
844 git reset --hard &&
845 echo content5 >foo.txt &&
846 git add foo.txt &&
847 test_must_fail git rm foo.txt 2>actual &&
848 test_i18ncmp expect actual
851 test_expect_success 'rm file with changes in the index without hints' '
852 cat >expect <<-\EOF &&
853 error: the following file has changes staged in the index:
854 foo.txt
856 test_must_fail git -c advice.rmhints=false rm foo.txt 2>actual &&
857 test_i18ncmp expect actual
860 test_expect_success 'rm files with two different errors' '
861 cat >expect <<-\EOF &&
862 error: the following file has staged content different from both the
863 file and the HEAD:
864 foo1.txt
865 (use -f to force removal)
866 error: the following file has changes staged in the index:
867 bar1.txt
868 (use --cached to keep the file, or -f to force removal)
870 echo content >foo1.txt &&
871 git add foo1.txt &&
872 echo content6 >foo1.txt &&
873 echo content6 >bar1.txt &&
874 git add bar1.txt &&
875 test_must_fail git rm bar1.txt foo1.txt 2>actual &&
876 test_i18ncmp expect actual
879 test_expect_success 'rm empty string should fail' '
880 test_must_fail git rm -rf ""
883 test_done