use strpbrk(3) to search for characters from a given set
[git/debian.git] / t / t3600-rm.sh
blob0ea858d652fcb5aee58e8a71c6d68cdbcfb974ea
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.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"
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"
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
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
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
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
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
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
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
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
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"
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
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
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
216 test_expect_success 'Remove nonexistent file returns nonzero exit status' '
217 test_must_fail git rm nonexistent
220 test_expect_success 'Call "rm" from outside the work tree' '
221 mkdir repo &&
223 cd repo &&
224 git init &&
225 echo something >somefile &&
226 git add somefile &&
227 git commit -m "add a file" &&
229 cd .. &&
230 git --git-dir=repo/.git --work-tree=repo rm somefile
231 ) &&
232 test_must_fail git ls-files --error-unmatch somefile
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
243 test_expect_success 'choking "git rm" should not let it die with cruft' '
244 test_oid_init &&
245 git reset -q --hard &&
246 test_when_finished "rm -f .git/index.lock && git reset -q --hard" &&
247 i=0 &&
248 hash=$(test_oid deadbeef) &&
249 while test $i -lt 12000
251 echo "100644 $hash 0 some-file-$i"
252 i=$(( $i + 1 ))
253 done | git update-index --index-info &&
254 # git command is intentionally placed upstream of pipe to induce SIGPIPE
255 git rm -n "some-file-*" | : &&
256 test_path_is_missing .git/index.lock
259 test_expect_success 'Resolving by removal is not a warning-worthy event' '
260 git reset -q --hard &&
261 test_when_finished "rm -f .git/index.lock msg && git reset -q --hard" &&
262 blob=$(echo blob | git hash-object -w --stdin) &&
263 for stage in 1 2 3
265 echo "100644 $blob $stage blob"
266 done | git update-index --index-info &&
267 git rm blob >msg 2>&1 &&
268 test_i18ngrep ! "needs merge" msg &&
269 test_must_fail git ls-files -s --error-unmatch blob
272 test_expect_success 'rm removes subdirectories recursively' '
273 mkdir -p dir/subdir/subsubdir &&
274 echo content >dir/subdir/subsubdir/file &&
275 git add dir/subdir/subsubdir/file &&
276 git rm -f dir/subdir/subsubdir/file &&
277 test_path_is_missing dir
280 cat >expect <<EOF
281 M .gitmodules
282 D submod
285 cat >expect.modified <<EOF
286 M submod
289 cat >expect.modified_inside <<EOF
290 m submod
293 cat >expect.modified_untracked <<EOF
294 ? submod
297 cat >expect.cached <<EOF
298 D submod
301 cat >expect.both_deleted<<EOF
302 D .gitmodules
303 D submod
306 test_expect_success 'rm removes empty submodules from work tree' '
307 mkdir submod &&
308 hash=$(git rev-parse HEAD) &&
309 git update-index --add --cacheinfo 160000 "$hash" submod &&
310 git config -f .gitmodules submodule.sub.url ./. &&
311 git config -f .gitmodules submodule.sub.path submod &&
312 git submodule init &&
313 git add .gitmodules &&
314 git commit -m "add submodule" &&
315 git rm submod &&
316 test_path_is_missing submod &&
317 git status -s -uno --ignore-submodules=none >actual &&
318 test_cmp expect actual &&
319 test_must_fail git config -f .gitmodules submodule.sub.url &&
320 test_must_fail git config -f .gitmodules submodule.sub.path
323 test_expect_success 'rm removes removed submodule from index and .gitmodules' '
324 git reset --hard &&
325 git submodule update &&
326 rm -rf submod &&
327 git rm submod &&
328 git status -s -uno --ignore-submodules=none >actual &&
329 test_cmp expect actual &&
330 test_must_fail git config -f .gitmodules submodule.sub.url &&
331 test_must_fail git config -f .gitmodules submodule.sub.path
334 test_expect_success 'rm removes work tree of unmodified submodules' '
335 git reset --hard &&
336 git submodule update &&
337 git rm submod &&
338 test_path_is_missing submod &&
339 git status -s -uno --ignore-submodules=none >actual &&
340 test_cmp expect actual &&
341 test_must_fail git config -f .gitmodules submodule.sub.url &&
342 test_must_fail git config -f .gitmodules submodule.sub.path
345 test_expect_success 'rm removes a submodule with a trailing /' '
346 git reset --hard &&
347 git submodule update &&
348 git rm submod/ &&
349 test_path_is_missing submod &&
350 git status -s -uno --ignore-submodules=none >actual &&
351 test_cmp expect actual
354 test_expect_success 'rm fails when given a file with a trailing /' '
355 test_must_fail git rm empty/
358 test_expect_success 'rm succeeds when given a directory with a trailing /' '
359 git rm -r frotz/
362 test_expect_success 'rm of a populated submodule with different HEAD fails unless forced' '
363 git reset --hard &&
364 git submodule update &&
365 git -C submod checkout HEAD^ &&
366 test_must_fail git rm submod &&
367 test_path_is_dir submod &&
368 test_path_is_file submod/.git &&
369 git status -s -uno --ignore-submodules=none >actual &&
370 test_cmp expect.modified actual &&
371 git rm -f submod &&
372 test_path_is_missing submod &&
373 git status -s -uno --ignore-submodules=none >actual &&
374 test_cmp expect actual &&
375 test_must_fail git config -f .gitmodules submodule.sub.url &&
376 test_must_fail git config -f .gitmodules submodule.sub.path
379 test_expect_success 'rm --cached leaves work tree of populated submodules and .gitmodules alone' '
380 git reset --hard &&
381 git submodule update &&
382 git rm --cached submod &&
383 test_path_is_dir submod &&
384 test_path_is_file submod/.git &&
385 git status -s -uno >actual &&
386 test_cmp expect.cached actual &&
387 git config -f .gitmodules submodule.sub.url &&
388 git config -f .gitmodules submodule.sub.path
391 test_expect_success 'rm --dry-run does not touch the submodule or .gitmodules' '
392 git reset --hard &&
393 git submodule update &&
394 git rm -n submod &&
395 test_path_is_file submod/.git &&
396 git diff-index --exit-code HEAD
399 test_expect_success 'rm does not complain when no .gitmodules file is found' '
400 git reset --hard &&
401 git submodule update &&
402 git rm .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.both_deleted actual
411 test_expect_success 'rm will error out on a modified .gitmodules file unless staged' '
412 git reset --hard &&
413 git submodule update &&
414 git config -f .gitmodules foo.bar true &&
415 test_must_fail git rm submod >actual 2>actual.err &&
416 test_file_not_empty actual.err &&
417 test_path_is_dir submod &&
418 test_path_is_file submod/.git &&
419 git diff-files --quiet -- submod &&
420 git add .gitmodules &&
421 git rm submod >actual 2>actual.err &&
422 test_must_be_empty actual.err &&
423 test_path_is_missing submod &&
424 test_path_is_missing submod/.git &&
425 git status -s -uno >actual &&
426 test_cmp expect actual
429 test_expect_success 'rm issues a warning when section is not found in .gitmodules' '
430 git reset --hard &&
431 git submodule update &&
432 git config -f .gitmodules --remove-section submodule.sub &&
433 git add .gitmodules &&
434 echo "warning: Could not find section in .gitmodules where path=submod" >expect.err &&
435 git rm submod >actual 2>actual.err &&
436 test_i18ncmp expect.err actual.err &&
437 test_path_is_missing submod &&
438 test_path_is_missing submod/.git &&
439 git status -s -uno >actual &&
440 test_cmp expect actual
443 test_expect_success 'rm of a populated submodule with modifications fails unless forced' '
444 git reset --hard &&
445 git submodule update &&
446 echo X >submod/empty &&
447 test_must_fail git rm submod &&
448 test_path_is_dir submod &&
449 test_path_is_file submod/.git &&
450 git status -s -uno --ignore-submodules=none >actual &&
451 test_cmp expect.modified_inside actual &&
452 git rm -f submod &&
453 test_path_is_missing submod &&
454 git status -s -uno --ignore-submodules=none >actual &&
455 test_cmp expect actual
458 test_expect_success 'rm of a populated submodule with untracked files fails unless forced' '
459 git reset --hard &&
460 git submodule update &&
461 echo X >submod/untracked &&
462 test_must_fail git rm submod &&
463 test_path_is_dir submod &&
464 test_path_is_file submod/.git &&
465 git status -s -uno --ignore-submodules=none >actual &&
466 test_cmp expect.modified_untracked actual &&
467 git rm -f submod &&
468 test_path_is_missing submod &&
469 git status -s -uno --ignore-submodules=none >actual &&
470 test_cmp expect actual
473 test_expect_success 'setup submodule conflict' '
474 git reset --hard &&
475 git submodule update &&
476 git checkout -b branch1 &&
477 echo 1 >nitfol &&
478 git add nitfol &&
479 git commit -m "added nitfol 1" &&
480 git checkout -b branch2 master &&
481 echo 2 >nitfol &&
482 git add nitfol &&
483 git commit -m "added nitfol 2" &&
484 git checkout -b conflict1 master &&
485 git -C submod fetch &&
486 git -C submod checkout branch1 &&
487 git add submod &&
488 git commit -m "submod 1" &&
489 git checkout -b conflict2 master &&
490 git -C submod checkout branch2 &&
491 git add submod &&
492 git commit -m "submod 2"
495 cat >expect.conflict <<EOF
496 UU submod
499 test_expect_success 'rm removes work tree of unmodified conflicted submodule' '
500 git checkout conflict1 &&
501 git reset --hard &&
502 git submodule update &&
503 test_must_fail git merge conflict2 &&
504 git rm submod &&
505 test_path_is_missing submod &&
506 git status -s -uno --ignore-submodules=none >actual &&
507 test_cmp expect actual
510 test_expect_success 'rm of a conflicted populated submodule with different HEAD fails unless forced' '
511 git checkout conflict1 &&
512 git reset --hard &&
513 git submodule update &&
514 git -C submod checkout HEAD^ &&
515 test_must_fail git merge conflict2 &&
516 test_must_fail git rm submod &&
517 test_path_is_dir submod &&
518 test_path_is_file submod/.git &&
519 git status -s -uno --ignore-submodules=none >actual &&
520 test_cmp expect.conflict actual &&
521 git rm -f submod &&
522 test_path_is_missing submod &&
523 git status -s -uno --ignore-submodules=none >actual &&
524 test_cmp expect actual &&
525 test_must_fail git config -f .gitmodules submodule.sub.url &&
526 test_must_fail git config -f .gitmodules submodule.sub.path
529 test_expect_success 'rm of a conflicted populated submodule with modifications fails unless forced' '
530 git checkout conflict1 &&
531 git reset --hard &&
532 git submodule update &&
533 echo X >submod/empty &&
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 untracked files fails unless forced' '
549 git checkout conflict1 &&
550 git reset --hard &&
551 git submodule update &&
552 echo X >submod/untracked &&
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
565 test_expect_success 'rm of a conflicted populated submodule with a .git directory fails even when forced' '
566 git checkout conflict1 &&
567 git reset --hard &&
568 git submodule update &&
570 cd submod &&
571 rm .git &&
572 cp -R ../.git/modules/sub .git &&
573 GIT_WORK_TREE=. git config --unset core.worktree
574 ) &&
575 test_must_fail git merge conflict2 &&
576 test_must_fail git rm 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 test_must_fail git rm -f submod &&
582 test_path_is_dir submod &&
583 test_path_is_dir submod/.git &&
584 git status -s -uno --ignore-submodules=none >actual &&
585 test_cmp expect.conflict actual &&
586 git merge --abort &&
587 rm -rf submod
590 test_expect_success 'rm of a conflicted unpopulated submodule succeeds' '
591 git checkout conflict1 &&
592 git reset --hard &&
593 test_must_fail git merge conflict2 &&
594 git rm submod &&
595 test_path_is_missing submod &&
596 git status -s -uno --ignore-submodules=none >actual &&
597 test_cmp expect actual
600 test_expect_success 'rm of a populated submodule with a .git directory migrates git dir' '
601 git checkout -f master &&
602 git reset --hard &&
603 git submodule update &&
605 cd submod &&
606 rm .git &&
607 cp -R ../.git/modules/sub .git &&
608 GIT_WORK_TREE=. git config --unset core.worktree &&
609 rm -r ../.git/modules/sub
610 ) &&
611 git rm submod 2>output.err &&
612 test_path_is_missing submod &&
613 test_path_is_missing submod/.git &&
614 git status -s -uno --ignore-submodules=none >actual &&
615 test_file_not_empty actual &&
616 test_i18ngrep Migrating output.err
619 cat >expect.deepmodified <<EOF
620 M submod/subsubmod
623 test_expect_success 'setup subsubmodule' '
624 git reset --hard &&
625 git submodule update &&
627 cd submod &&
628 hash=$(git rev-parse HEAD) &&
629 git update-index --add --cacheinfo 160000 "$hash" subsubmod &&
630 git config -f .gitmodules submodule.sub.url ../. &&
631 git config -f .gitmodules submodule.sub.path subsubmod &&
632 git submodule init &&
633 git add .gitmodules &&
634 git commit -m "add subsubmodule" &&
635 git submodule update subsubmod
636 ) &&
637 git commit -a -m "added deep submodule"
640 test_expect_success 'rm recursively removes work tree of unmodified submodules' '
641 git rm submod &&
642 test_path_is_missing submod &&
643 git status -s -uno --ignore-submodules=none >actual &&
644 test_cmp expect actual
647 test_expect_success 'rm of a populated nested submodule with different nested HEAD fails unless forced' '
648 git reset --hard &&
649 git submodule update --recursive &&
650 git -C submod/subsubmod checkout HEAD^ &&
651 test_must_fail git rm submod &&
652 test_path_is_dir submod &&
653 test_path_is_file submod/.git &&
654 git status -s -uno --ignore-submodules=none >actual &&
655 test_cmp expect.modified_inside actual &&
656 git rm -f submod &&
657 test_path_is_missing submod &&
658 git status -s -uno --ignore-submodules=none >actual &&
659 test_cmp expect actual
662 test_expect_success 'rm of a populated nested submodule with nested modifications fails unless forced' '
663 git reset --hard &&
664 git submodule update --recursive &&
665 echo X >submod/subsubmod/empty &&
666 test_must_fail git rm submod &&
667 test_path_is_dir submod &&
668 test_path_is_file submod/.git &&
669 git status -s -uno --ignore-submodules=none >actual &&
670 test_cmp expect.modified_inside actual &&
671 git rm -f submod &&
672 test_path_is_missing submod &&
673 git status -s -uno --ignore-submodules=none >actual &&
674 test_cmp expect actual
677 test_expect_success 'rm of a populated nested submodule with nested untracked files fails unless forced' '
678 git reset --hard &&
679 git submodule update --recursive &&
680 echo X >submod/subsubmod/untracked &&
681 test_must_fail git rm submod &&
682 test_path_is_dir submod &&
683 test_path_is_file submod/.git &&
684 git status -s -uno --ignore-submodules=none >actual &&
685 test_cmp expect.modified_untracked actual &&
686 git rm -f submod &&
687 test_path_is_missing submod &&
688 git status -s -uno --ignore-submodules=none >actual &&
689 test_cmp expect actual
692 test_expect_success "rm absorbs submodule's nested .git directory" '
693 git reset --hard &&
694 git submodule update --recursive &&
696 cd submod/subsubmod &&
697 rm .git &&
698 mv ../../.git/modules/sub/modules/sub .git &&
699 GIT_WORK_TREE=. git config --unset core.worktree
700 ) &&
701 git rm submod 2>output.err &&
702 test_path_is_missing submod &&
703 test_path_is_missing submod/subsubmod/.git &&
704 git status -s -uno --ignore-submodules=none >actual &&
705 test_file_not_empty actual &&
706 test_i18ngrep Migrating output.err
709 test_expect_success 'checking out a commit after submodule removal needs manual updates' '
710 git commit -m "submodule removal" submod .gitmodules &&
711 git checkout HEAD^ &&
712 git submodule update &&
713 git checkout -q HEAD^ &&
714 git checkout -q master 2>actual &&
715 test_i18ngrep "^warning: unable to rmdir '\''submod'\'':" actual &&
716 git status -s submod >actual &&
717 echo "?? submod/" >expected &&
718 test_cmp expected actual &&
719 rm -rf submod &&
720 git status -s -uno --ignore-submodules=none >actual &&
721 test_must_be_empty actual
724 test_expect_success 'rm of d/f when d has become a non-directory' '
725 rm -rf d &&
726 mkdir d &&
727 >d/f &&
728 git add d &&
729 rm -rf d &&
730 >d &&
731 git rm d/f &&
732 test_must_fail git rev-parse --verify :d/f &&
733 test_path_is_file d
736 test_expect_success SYMLINKS 'rm of d/f when d has become a dangling symlink' '
737 rm -rf d &&
738 mkdir d &&
739 >d/f &&
740 git add d &&
741 rm -rf d &&
742 ln -s nonexistent d &&
743 git rm d/f &&
744 test_must_fail git rev-parse --verify :d/f &&
745 test -h d &&
746 test_path_is_missing d
749 test_expect_success 'rm of file when it has become a directory' '
750 rm -rf d &&
751 >d &&
752 git add d &&
753 rm -f d &&
754 mkdir d &&
755 >d/f &&
756 test_must_fail git rm d &&
757 git rev-parse --verify :d &&
758 test_path_is_file d/f
761 test_expect_success SYMLINKS 'rm across a symlinked leading path (no index)' '
762 rm -rf d e &&
763 mkdir e &&
764 echo content >e/f &&
765 ln -s e d &&
766 git add -A e d &&
767 git commit -m "symlink d to e, e/f exists" &&
768 test_must_fail git rm d/f &&
769 git rev-parse --verify :d &&
770 git rev-parse --verify :e/f &&
771 test -h d &&
772 test_path_is_file e/f
775 test_expect_failure SYMLINKS 'rm across a symlinked leading path (w/ index)' '
776 rm -rf d e &&
777 mkdir d &&
778 echo content >d/f &&
779 git add -A e d &&
780 git commit -m "d/f exists" &&
781 mv d e &&
782 ln -s e d &&
783 test_must_fail git rm d/f &&
784 git rev-parse --verify :d/f &&
785 test -h d &&
786 test_path_is_file e/f
789 test_expect_success 'setup for testing rm messages' '
790 >bar.txt &&
791 >foo.txt &&
792 git add bar.txt foo.txt
795 test_expect_success 'rm files with different staged content' '
796 cat >expect <<-\EOF &&
797 error: the following files have staged content different from both the
798 file and the HEAD:
799 bar.txt
800 foo.txt
801 (use -f to force removal)
803 echo content1 >foo.txt &&
804 echo content1 >bar.txt &&
805 test_must_fail git rm foo.txt bar.txt 2>actual &&
806 test_i18ncmp expect actual
809 test_expect_success 'rm files with different staged content without hints' '
810 cat >expect <<-\EOF &&
811 error: the following files have staged content different from both the
812 file and the HEAD:
813 bar.txt
814 foo.txt
816 echo content2 >foo.txt &&
817 echo content2 >bar.txt &&
818 test_must_fail git -c advice.rmhints=false rm foo.txt bar.txt 2>actual &&
819 test_i18ncmp expect actual
822 test_expect_success 'rm file with local modification' '
823 cat >expect <<-\EOF &&
824 error: the following file has local modifications:
825 foo.txt
826 (use --cached to keep the file, or -f to force removal)
828 git commit -m "testing rm 3" &&
829 echo content3 >foo.txt &&
830 test_must_fail git rm foo.txt 2>actual &&
831 test_i18ncmp expect actual
834 test_expect_success 'rm file with local modification without hints' '
835 cat >expect <<-\EOF &&
836 error: the following file has local modifications:
837 bar.txt
839 echo content4 >bar.txt &&
840 test_must_fail git -c advice.rmhints=false rm bar.txt 2>actual &&
841 test_i18ncmp expect actual
844 test_expect_success 'rm file with changes in the index' '
845 cat >expect <<-\EOF &&
846 error: the following file has changes staged in the index:
847 foo.txt
848 (use --cached to keep the file, or -f to force removal)
850 git reset --hard &&
851 echo content5 >foo.txt &&
852 git add foo.txt &&
853 test_must_fail git rm foo.txt 2>actual &&
854 test_i18ncmp expect actual
857 test_expect_success 'rm file with changes in the index without hints' '
858 cat >expect <<-\EOF &&
859 error: the following file has changes staged in the index:
860 foo.txt
862 test_must_fail git -c advice.rmhints=false rm foo.txt 2>actual &&
863 test_i18ncmp expect actual
866 test_expect_success 'rm files with two different errors' '
867 cat >expect <<-\EOF &&
868 error: the following file has staged content different from both the
869 file and the HEAD:
870 foo1.txt
871 (use -f to force removal)
872 error: the following file has changes staged in the index:
873 bar1.txt
874 (use --cached to keep the file, or -f to force removal)
876 echo content >foo1.txt &&
877 git add foo1.txt &&
878 echo content6 >foo1.txt &&
879 echo content6 >bar1.txt &&
880 git add bar1.txt &&
881 test_must_fail git rm bar1.txt foo1.txt 2>actual &&
882 test_i18ncmp expect actual
885 test_expect_success 'rm empty string should fail' '
886 test_must_fail git rm -rf ""
889 test_done