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