Merge branch 'master' of git://git.kernel.org/pub/scm/git/git
[git.git] / t / t3600-rm.sh
blob85ae7dc1e4618275413a8b498f43d43f3e0ead92
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 'rm removes subdirectories recursively' '
256 mkdir -p dir/subdir/subsubdir &&
257 echo content >dir/subdir/subsubdir/file &&
258 git add dir/subdir/subsubdir/file &&
259 git rm -f dir/subdir/subsubdir/file &&
260 test_path_is_missing dir
263 cat >expect <<EOF
264 M .gitmodules
265 D submod
268 cat >expect.modified <<EOF
269 M submod
272 cat >expect.modified_inside <<EOF
273 m submod
276 cat >expect.modified_untracked <<EOF
277 ? submod
280 cat >expect.cached <<EOF
281 D submod
284 cat >expect.both_deleted<<EOF
285 D .gitmodules
286 D submod
289 test_expect_success 'rm removes empty submodules from work tree' '
290 mkdir submod &&
291 git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) submod &&
292 git config -f .gitmodules submodule.sub.url ./. &&
293 git config -f .gitmodules submodule.sub.path submod &&
294 git submodule init &&
295 git add .gitmodules &&
296 git commit -m "add submodule" &&
297 git rm submod &&
298 test_path_is_missing submod &&
299 git status -s -uno --ignore-submodules=none >actual &&
300 test_cmp expect actual &&
301 test_must_fail git config -f .gitmodules submodule.sub.url &&
302 test_must_fail git config -f .gitmodules submodule.sub.path
305 test_expect_success 'rm removes removed submodule from index and .gitmodules' '
306 git reset --hard &&
307 git submodule update &&
308 rm -rf submod &&
309 git rm submod &&
310 git status -s -uno --ignore-submodules=none >actual &&
311 test_cmp expect actual &&
312 test_must_fail git config -f .gitmodules submodule.sub.url &&
313 test_must_fail git config -f .gitmodules submodule.sub.path
316 test_expect_success 'rm removes work tree of unmodified submodules' '
317 git reset --hard &&
318 git submodule update &&
319 git rm submod &&
320 test_path_is_missing submod &&
321 git status -s -uno --ignore-submodules=none >actual &&
322 test_cmp expect actual &&
323 test_must_fail git config -f .gitmodules submodule.sub.url &&
324 test_must_fail git config -f .gitmodules submodule.sub.path
327 test_expect_success 'rm removes a submodule with a trailing /' '
328 git reset --hard &&
329 git submodule update &&
330 git rm submod/ &&
331 test_path_is_missing submod &&
332 git status -s -uno --ignore-submodules=none >actual &&
333 test_cmp expect actual
336 test_expect_success 'rm fails when given a file with a trailing /' '
337 test_must_fail git rm empty/
340 test_expect_success 'rm succeeds when given a directory with a trailing /' '
341 git rm -r frotz/
344 test_expect_success 'rm of a populated submodule with different HEAD fails unless forced' '
345 git reset --hard &&
346 git submodule update &&
347 git -C submod checkout HEAD^ &&
348 test_must_fail git rm submod &&
349 test_path_is_dir submod &&
350 test_path_is_file submod/.git &&
351 git status -s -uno --ignore-submodules=none >actual &&
352 test_cmp expect.modified actual &&
353 git rm -f submod &&
354 test_path_is_missing submod &&
355 git status -s -uno --ignore-submodules=none >actual &&
356 test_cmp expect actual &&
357 test_must_fail git config -f .gitmodules submodule.sub.url &&
358 test_must_fail git config -f .gitmodules submodule.sub.path
361 test_expect_success 'rm --cached leaves work tree of populated submodules and .gitmodules alone' '
362 git reset --hard &&
363 git submodule update &&
364 git rm --cached submod &&
365 test_path_is_dir submod &&
366 test_path_is_file submod/.git &&
367 git status -s -uno >actual &&
368 test_cmp expect.cached actual &&
369 git config -f .gitmodules submodule.sub.url &&
370 git config -f .gitmodules submodule.sub.path
373 test_expect_success 'rm --dry-run does not touch the submodule or .gitmodules' '
374 git reset --hard &&
375 git submodule update &&
376 git rm -n submod &&
377 test_path_is_file submod/.git &&
378 git diff-index --exit-code HEAD
381 test_expect_success 'rm does not complain when no .gitmodules file is found' '
382 git reset --hard &&
383 git submodule update &&
384 git rm .gitmodules &&
385 git rm submod >actual 2>actual.err &&
386 test_must_be_empty actual.err &&
387 test_path_is_missing submod &&
388 test_path_is_missing submod/.git &&
389 git status -s -uno >actual &&
390 test_cmp expect.both_deleted actual
393 test_expect_success 'rm will error out on a modified .gitmodules file unless staged' '
394 git reset --hard &&
395 git submodule update &&
396 git config -f .gitmodules foo.bar true &&
397 test_must_fail git rm submod >actual 2>actual.err &&
398 test_file_not_empty actual.err &&
399 test_path_is_dir submod &&
400 test_path_is_file submod/.git &&
401 git diff-files --quiet -- submod &&
402 git add .gitmodules &&
403 git rm submod >actual 2>actual.err &&
404 test_must_be_empty actual.err &&
405 test_path_is_missing submod &&
406 test_path_is_missing submod/.git &&
407 git status -s -uno >actual &&
408 test_cmp expect actual
411 test_expect_success 'rm issues a warning when section is not found in .gitmodules' '
412 git reset --hard &&
413 git submodule update &&
414 git config -f .gitmodules --remove-section submodule.sub &&
415 git add .gitmodules &&
416 echo "warning: Could not find section in .gitmodules where path=submod" >expect.err &&
417 git rm submod >actual 2>actual.err &&
418 test_i18ncmp expect.err actual.err &&
419 test_path_is_missing submod &&
420 test_path_is_missing submod/.git &&
421 git status -s -uno >actual &&
422 test_cmp expect actual
425 test_expect_success 'rm of a populated submodule with modifications fails unless forced' '
426 git reset --hard &&
427 git submodule update &&
428 echo X >submod/empty &&
429 test_must_fail git rm submod &&
430 test_path_is_dir submod &&
431 test_path_is_file submod/.git &&
432 git status -s -uno --ignore-submodules=none >actual &&
433 test_cmp expect.modified_inside actual &&
434 git rm -f submod &&
435 test_path_is_missing submod &&
436 git status -s -uno --ignore-submodules=none >actual &&
437 test_cmp expect actual
440 test_expect_success 'rm of a populated submodule with untracked files fails unless forced' '
441 git reset --hard &&
442 git submodule update &&
443 echo X >submod/untracked &&
444 test_must_fail git rm submod &&
445 test_path_is_dir submod &&
446 test_path_is_file submod/.git &&
447 git status -s -uno --ignore-submodules=none >actual &&
448 test_cmp expect.modified_untracked actual &&
449 git rm -f submod &&
450 test_path_is_missing submod &&
451 git status -s -uno --ignore-submodules=none >actual &&
452 test_cmp expect actual
455 test_expect_success 'setup submodule conflict' '
456 git reset --hard &&
457 git submodule update &&
458 git checkout -b branch1 &&
459 echo 1 >nitfol &&
460 git add nitfol &&
461 git commit -m "added nitfol 1" &&
462 git checkout -b branch2 master &&
463 echo 2 >nitfol &&
464 git add nitfol &&
465 git commit -m "added nitfol 2" &&
466 git checkout -b conflict1 master &&
467 git -C submod fetch &&
468 git -C submod checkout branch1 &&
469 git add submod &&
470 git commit -m "submod 1" &&
471 git checkout -b conflict2 master &&
472 git -C submod checkout branch2 &&
473 git add submod &&
474 git commit -m "submod 2"
477 cat >expect.conflict <<EOF
478 UU submod
481 test_expect_success 'rm removes work tree of unmodified conflicted submodule' '
482 git checkout conflict1 &&
483 git reset --hard &&
484 git submodule update &&
485 test_must_fail git merge conflict2 &&
486 git rm 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 'rm of a conflicted populated submodule with different HEAD fails unless forced' '
493 git checkout conflict1 &&
494 git reset --hard &&
495 git submodule update &&
496 git -C submod checkout HEAD^ &&
497 test_must_fail git merge conflict2 &&
498 test_must_fail git rm submod &&
499 test_path_is_dir submod &&
500 test_path_is_file submod/.git &&
501 git status -s -uno --ignore-submodules=none >actual &&
502 test_cmp expect.conflict actual &&
503 git rm -f submod &&
504 test_path_is_missing submod &&
505 git status -s -uno --ignore-submodules=none >actual &&
506 test_cmp expect actual &&
507 test_must_fail git config -f .gitmodules submodule.sub.url &&
508 test_must_fail git config -f .gitmodules submodule.sub.path
511 test_expect_success 'rm of a conflicted populated submodule with modifications fails unless forced' '
512 git checkout conflict1 &&
513 git reset --hard &&
514 git submodule update &&
515 echo X >submod/empty &&
516 test_must_fail git merge conflict2 &&
517 test_must_fail git rm submod &&
518 test_path_is_dir submod &&
519 test_path_is_file submod/.git &&
520 git status -s -uno --ignore-submodules=none >actual &&
521 test_cmp expect.conflict actual &&
522 git rm -f submod &&
523 test_path_is_missing submod &&
524 git status -s -uno --ignore-submodules=none >actual &&
525 test_cmp expect actual &&
526 test_must_fail git config -f .gitmodules submodule.sub.url &&
527 test_must_fail git config -f .gitmodules submodule.sub.path
530 test_expect_success 'rm of a conflicted populated submodule with untracked files fails unless forced' '
531 git checkout conflict1 &&
532 git reset --hard &&
533 git submodule update &&
534 echo X >submod/untracked &&
535 test_must_fail git merge conflict2 &&
536 test_must_fail git rm submod &&
537 test_path_is_dir submod &&
538 test_path_is_file submod/.git &&
539 git status -s -uno --ignore-submodules=none >actual &&
540 test_cmp expect.conflict actual &&
541 git rm -f submod &&
542 test_path_is_missing submod &&
543 git status -s -uno --ignore-submodules=none >actual &&
544 test_cmp expect actual
547 test_expect_success 'rm of a conflicted populated submodule with a .git directory fails even when forced' '
548 git checkout conflict1 &&
549 git reset --hard &&
550 git submodule update &&
552 cd submod &&
553 rm .git &&
554 cp -R ../.git/modules/sub .git &&
555 GIT_WORK_TREE=. git config --unset core.worktree
556 ) &&
557 test_must_fail git merge conflict2 &&
558 test_must_fail git rm submod &&
559 test_path_is_dir submod &&
560 test_path_is_dir submod/.git &&
561 git status -s -uno --ignore-submodules=none >actual &&
562 test_cmp expect.conflict actual &&
563 test_must_fail git rm -f submod &&
564 test_path_is_dir submod &&
565 test_path_is_dir submod/.git &&
566 git status -s -uno --ignore-submodules=none >actual &&
567 test_cmp expect.conflict actual &&
568 git merge --abort &&
569 rm -rf submod
572 test_expect_success 'rm of a conflicted unpopulated submodule succeeds' '
573 git checkout conflict1 &&
574 git reset --hard &&
575 test_must_fail git merge conflict2 &&
576 git rm submod &&
577 test_path_is_missing submod &&
578 git status -s -uno --ignore-submodules=none >actual &&
579 test_cmp expect actual
582 test_expect_success 'rm of a populated submodule with a .git directory migrates git dir' '
583 git checkout -f master &&
584 git reset --hard &&
585 git submodule update &&
587 cd submod &&
588 rm .git &&
589 cp -R ../.git/modules/sub .git &&
590 GIT_WORK_TREE=. git config --unset core.worktree &&
591 rm -r ../.git/modules/sub
592 ) &&
593 git rm submod 2>output.err &&
594 test_path_is_missing submod &&
595 test_path_is_missing submod/.git &&
596 git status -s -uno --ignore-submodules=none >actual &&
597 test_file_not_empty actual &&
598 test_i18ngrep Migrating output.err
601 cat >expect.deepmodified <<EOF
602 M submod/subsubmod
605 test_expect_success 'setup subsubmodule' '
606 git reset --hard &&
607 git submodule update &&
609 cd submod &&
610 git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) subsubmod &&
611 git config -f .gitmodules submodule.sub.url ../. &&
612 git config -f .gitmodules submodule.sub.path subsubmod &&
613 git submodule init &&
614 git add .gitmodules &&
615 git commit -m "add subsubmodule" &&
616 git submodule update subsubmod
617 ) &&
618 git commit -a -m "added deep submodule"
621 test_expect_success 'rm recursively removes work tree of unmodified submodules' '
622 git rm submod &&
623 test_path_is_missing submod &&
624 git status -s -uno --ignore-submodules=none >actual &&
625 test_cmp expect actual
628 test_expect_success 'rm of a populated nested submodule with different nested HEAD fails unless forced' '
629 git reset --hard &&
630 git submodule update --recursive &&
631 git -C submod/subsubmod checkout HEAD^ &&
632 test_must_fail git rm submod &&
633 test_path_is_dir submod &&
634 test_path_is_file submod/.git &&
635 git status -s -uno --ignore-submodules=none >actual &&
636 test_cmp expect.modified_inside actual &&
637 git rm -f submod &&
638 test_path_is_missing submod &&
639 git status -s -uno --ignore-submodules=none >actual &&
640 test_cmp expect actual
643 test_expect_success 'rm of a populated nested submodule with nested modifications fails unless forced' '
644 git reset --hard &&
645 git submodule update --recursive &&
646 echo X >submod/subsubmod/empty &&
647 test_must_fail git rm submod &&
648 test_path_is_dir submod &&
649 test_path_is_file submod/.git &&
650 git status -s -uno --ignore-submodules=none >actual &&
651 test_cmp expect.modified_inside actual &&
652 git rm -f submod &&
653 test_path_is_missing submod &&
654 git status -s -uno --ignore-submodules=none >actual &&
655 test_cmp expect actual
658 test_expect_success 'rm of a populated nested submodule with nested untracked files fails unless forced' '
659 git reset --hard &&
660 git submodule update --recursive &&
661 echo X >submod/subsubmod/untracked &&
662 test_must_fail git rm submod &&
663 test_path_is_dir submod &&
664 test_path_is_file submod/.git &&
665 git status -s -uno --ignore-submodules=none >actual &&
666 test_cmp expect.modified_untracked actual &&
667 git rm -f submod &&
668 test_path_is_missing submod &&
669 git status -s -uno --ignore-submodules=none >actual &&
670 test_cmp expect actual
673 test_expect_success "rm absorbs submodule's nested .git directory" '
674 git reset --hard &&
675 git submodule update --recursive &&
677 cd submod/subsubmod &&
678 rm .git &&
679 mv ../../.git/modules/sub/modules/sub .git &&
680 GIT_WORK_TREE=. git config --unset core.worktree
681 ) &&
682 git rm submod 2>output.err &&
683 test_path_is_missing submod &&
684 test_path_is_missing submod/subsubmod/.git &&
685 git status -s -uno --ignore-submodules=none >actual &&
686 test_file_not_empty actual &&
687 test_i18ngrep Migrating output.err
690 test_expect_success 'checking out a commit after submodule removal needs manual updates' '
691 git commit -m "submodule removal" submod .gitmodules &&
692 git checkout HEAD^ &&
693 git submodule update &&
694 git checkout -q HEAD^ &&
695 git checkout -q master 2>actual &&
696 test_i18ngrep "^warning: unable to rmdir '\''submod'\'':" actual &&
697 git status -s submod >actual &&
698 echo "?? submod/" >expected &&
699 test_cmp expected actual &&
700 rm -rf submod &&
701 git status -s -uno --ignore-submodules=none >actual &&
702 test_must_be_empty actual
705 test_expect_success 'rm of d/f when d has become a non-directory' '
706 rm -rf d &&
707 mkdir d &&
708 >d/f &&
709 git add d &&
710 rm -rf d &&
711 >d &&
712 git rm d/f &&
713 test_must_fail git rev-parse --verify :d/f &&
714 test_path_is_file d
717 test_expect_success SYMLINKS 'rm of d/f when d has become a dangling symlink' '
718 rm -rf d &&
719 mkdir d &&
720 >d/f &&
721 git add d &&
722 rm -rf d &&
723 ln -s nonexistent d &&
724 git rm d/f &&
725 test_must_fail git rev-parse --verify :d/f &&
726 test -h d &&
727 test_path_is_missing d
730 test_expect_success 'rm of file when it has become a directory' '
731 rm -rf d &&
732 >d &&
733 git add d &&
734 rm -f d &&
735 mkdir d &&
736 >d/f &&
737 test_must_fail git rm d &&
738 git rev-parse --verify :d &&
739 test_path_is_file d/f
742 test_expect_success SYMLINKS 'rm across a symlinked leading path (no index)' '
743 rm -rf d e &&
744 mkdir e &&
745 echo content >e/f &&
746 ln -s e d &&
747 git add -A e d &&
748 git commit -m "symlink d to e, e/f exists" &&
749 test_must_fail git rm d/f &&
750 git rev-parse --verify :d &&
751 git rev-parse --verify :e/f &&
752 test -h d &&
753 test_path_is_file e/f
756 test_expect_failure SYMLINKS 'rm across a symlinked leading path (w/ index)' '
757 rm -rf d e &&
758 mkdir d &&
759 echo content >d/f &&
760 git add -A e d &&
761 git commit -m "d/f exists" &&
762 mv d e &&
763 ln -s e d &&
764 test_must_fail git rm d/f &&
765 git rev-parse --verify :d/f &&
766 test -h d &&
767 test_path_is_file e/f
770 test_expect_success 'setup for testing rm messages' '
771 >bar.txt &&
772 >foo.txt &&
773 git add bar.txt foo.txt
776 test_expect_success 'rm files with different staged content' '
777 cat >expect <<-\EOF &&
778 error: the following files have staged content different from both the
779 file and the HEAD:
780 bar.txt
781 foo.txt
782 (use -f to force removal)
784 echo content1 >foo.txt &&
785 echo content1 >bar.txt &&
786 test_must_fail git rm foo.txt bar.txt 2>actual &&
787 test_i18ncmp expect actual
790 test_expect_success 'rm files with different staged content without hints' '
791 cat >expect <<-\EOF &&
792 error: the following files have staged content different from both the
793 file and the HEAD:
794 bar.txt
795 foo.txt
797 echo content2 >foo.txt &&
798 echo content2 >bar.txt &&
799 test_must_fail git -c advice.rmhints=false rm foo.txt bar.txt 2>actual &&
800 test_i18ncmp expect actual
803 test_expect_success 'rm file with local modification' '
804 cat >expect <<-\EOF &&
805 error: the following file has local modifications:
806 foo.txt
807 (use --cached to keep the file, or -f to force removal)
809 git commit -m "testing rm 3" &&
810 echo content3 >foo.txt &&
811 test_must_fail git rm foo.txt 2>actual &&
812 test_i18ncmp expect actual
815 test_expect_success 'rm file with local modification without hints' '
816 cat >expect <<-\EOF &&
817 error: the following file has local modifications:
818 bar.txt
820 echo content4 >bar.txt &&
821 test_must_fail git -c advice.rmhints=false rm bar.txt 2>actual &&
822 test_i18ncmp expect actual
825 test_expect_success 'rm file with changes in the index' '
826 cat >expect <<-\EOF &&
827 error: the following file has changes staged in the index:
828 foo.txt
829 (use --cached to keep the file, or -f to force removal)
831 git reset --hard &&
832 echo content5 >foo.txt &&
833 git add foo.txt &&
834 test_must_fail git rm foo.txt 2>actual &&
835 test_i18ncmp expect actual
838 test_expect_success 'rm file with changes in the index without hints' '
839 cat >expect <<-\EOF &&
840 error: the following file has changes staged in the index:
841 foo.txt
843 test_must_fail git -c advice.rmhints=false rm foo.txt 2>actual &&
844 test_i18ncmp expect actual
847 test_expect_success 'rm files with two different errors' '
848 cat >expect <<-\EOF &&
849 error: the following file has staged content different from both the
850 file and the HEAD:
851 foo1.txt
852 (use -f to force removal)
853 error: the following file has changes staged in the index:
854 bar1.txt
855 (use --cached to keep the file, or -f to force removal)
857 echo content >foo1.txt &&
858 git add foo1.txt &&
859 echo content6 >foo1.txt &&
860 echo content6 >bar1.txt &&
861 git add bar1.txt &&
862 test_must_fail git rm bar1.txt foo1.txt 2>actual &&
863 test_i18ncmp expect actual
866 test_expect_success 'rm empty string should fail' '
867 test_must_fail git rm -rf ""
870 test_done