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