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