]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3600-rm.sh
hashmap: provide deallocation function names
[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" &&
0d913dfa
DL
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 &&
b48caa20
SG
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 &&
59a06e94
RA
142 test_path_is_file foo &&
143 test_path_is_file baz &&
467e1b53
JH
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 &&
59a06e94
RA
149 test_path_is_missing foo &&
150 test_path_is_missing 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 &&
59a06e94
RA
164 test_path_is_file foo &&
165 test_path_is_file baz &&
467e1b53
JH
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 &&
59a06e94
RA
171 test_path_is_missing foo &&
172 test_path_is_missing 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 &&
59a06e94
RA
199 test_path_is_dir frotz &&
200 test_path_is_file frotz/nitfol
467e1b53
JH
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 &&
59a06e94
RA
206 test_path_is_dir frotz &&
207 test_path_is_file frotz/nitfol
467e1b53
JH
208'
209
210test_expect_success 'Recursive with -r -f' '
211 git rm -f -r frotz &&
59a06e94
RA
212 test_path_is_missing frotz/nitfol &&
213 test_path_is_missing frotz
467e1b53
JH
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 &&
b5368c23
RA
222 (
223 cd repo &&
224 git init &&
225 echo something >somefile &&
226 git add somefile &&
227 git commit -m "add a file" &&
228 (
229 cd .. &&
230 git --git-dir=repo/.git --work-tree=repo rm somefile
231 ) &&
232 test_must_fail git ls-files --error-unmatch somefile
233 )
cced48a8
JS
234'
235
236test_expect_success 'refresh index before checking if it is up-to-date' '
cced48a8 237 git reset --hard &&
0e496492 238 test-tool chmtime -86400 frotz/nitfol &&
cced48a8 239 git rm frotz/nitfol &&
59a06e94 240 test_path_is_missing frotz/nitfol
4d264672
OM
241'
242
0693f9dd
JH
243test_expect_success 'choking "git rm" should not let it die with cruft' '
244 git reset -q --hard &&
056f34bb 245 test_when_finished "rm -f .git/index.lock && git reset -q --hard" &&
0693f9dd 246 i=0 &&
ca6ba942 247 hash=$(test_oid deadbeef) &&
0693f9dd
JH
248 while test $i -lt 12000
249 do
ca6ba942 250 echo "100644 $hash 0 some-file-$i"
b5368c23 251 i=$(( $i + 1 ))
0693f9dd 252 done | git update-index --index-info &&
50cd31c6 253 # git command is intentionally placed upstream of pipe to induce SIGPIPE
056f34bb
SG
254 git rm -n "some-file-*" | : &&
255 test_path_is_missing .git/index.lock
0693f9dd
JH
256'
257
b2b1f615
JH
258test_expect_success 'Resolving by removal is not a warning-worthy event' '
259 git reset -q --hard &&
260 test_when_finished "rm -f .git/index.lock msg && git reset -q --hard" &&
261 blob=$(echo blob | git hash-object -w --stdin) &&
262 for stage in 1 2 3
263 do
264 echo "100644 $blob $stage blob"
265 done | git update-index --index-info &&
266 git rm blob >msg 2>&1 &&
267 test_i18ngrep ! "needs merge" msg &&
268 test_must_fail git ls-files -s --error-unmatch blob
269'
270
3fc0d131
JK
271test_expect_success 'rm removes subdirectories recursively' '
272 mkdir -p dir/subdir/subsubdir &&
273 echo content >dir/subdir/subsubdir/file &&
274 git add dir/subdir/subsubdir/file &&
275 git rm -f dir/subdir/subsubdir/file &&
59a06e94 276 test_path_is_missing dir
3fc0d131
JK
277'
278
293ab15e 279cat >expect <<EOF
95c16418 280M .gitmodules
293ab15e
JL
281D submod
282EOF
283
284cat >expect.modified <<EOF
285 M submod
286EOF
287
dd6962dd
SB
288cat >expect.modified_inside <<EOF
289 m submod
290EOF
291
292cat >expect.modified_untracked <<EOF
293 ? submod
294EOF
295
95c16418
JL
296cat >expect.cached <<EOF
297D submod
298EOF
299
300cat >expect.both_deleted<<EOF
301D .gitmodules
302D submod
303EOF
304
293ab15e
JL
305test_expect_success 'rm removes empty submodules from work tree' '
306 mkdir submod &&
3b737381
DL
307 hash=$(git rev-parse HEAD) &&
308 git update-index --add --cacheinfo 160000 "$hash" submod &&
293ab15e
JL
309 git config -f .gitmodules submodule.sub.url ./. &&
310 git config -f .gitmodules submodule.sub.path submod &&
311 git submodule init &&
312 git add .gitmodules &&
313 git commit -m "add submodule" &&
314 git rm submod &&
59a06e94 315 test_path_is_missing submod &&
9e189f1a 316 git status -s -uno --ignore-submodules=none >actual &&
95c16418
JL
317 test_cmp expect actual &&
318 test_must_fail git config -f .gitmodules submodule.sub.url &&
319 test_must_fail git config -f .gitmodules submodule.sub.path
293ab15e
JL
320'
321
95c16418 322test_expect_success 'rm removes removed submodule from index and .gitmodules' '
293ab15e
JL
323 git reset --hard &&
324 git submodule update &&
325 rm -rf submod &&
326 git rm submod &&
9e189f1a 327 git status -s -uno --ignore-submodules=none >actual &&
95c16418
JL
328 test_cmp expect actual &&
329 test_must_fail git config -f .gitmodules submodule.sub.url &&
330 test_must_fail git config -f .gitmodules submodule.sub.path
293ab15e
JL
331'
332
333test_expect_success 'rm removes work tree of unmodified submodules' '
334 git reset --hard &&
335 git submodule update &&
336 git rm submod &&
59a06e94 337 test_path_is_missing submod &&
9e189f1a 338 git status -s -uno --ignore-submodules=none >actual &&
95c16418
JL
339 test_cmp expect actual &&
340 test_must_fail git config -f .gitmodules submodule.sub.url &&
341 test_must_fail git config -f .gitmodules submodule.sub.path
293ab15e
JL
342'
343
53e4c5dc
JL
344test_expect_success 'rm removes a submodule with a trailing /' '
345 git reset --hard &&
346 git submodule update &&
347 git rm submod/ &&
59a06e94 348 test_path_is_missing submod &&
9e189f1a 349 git status -s -uno --ignore-submodules=none >actual &&
53e4c5dc
JL
350 test_cmp expect actual
351'
352
353test_expect_success 'rm fails when given a file with a trailing /' '
354 test_must_fail git rm empty/
355'
356
357test_expect_success 'rm succeeds when given a directory with a trailing /' '
358 git rm -r frotz/
359'
360
293ab15e
JL
361test_expect_success 'rm of a populated submodule with different HEAD fails unless forced' '
362 git reset --hard &&
363 git submodule update &&
9e189f1a 364 git -C submod checkout HEAD^ &&
293ab15e 365 test_must_fail git rm submod &&
59a06e94
RA
366 test_path_is_dir submod &&
367 test_path_is_file submod/.git &&
9e189f1a 368 git status -s -uno --ignore-submodules=none >actual &&
293ab15e
JL
369 test_cmp expect.modified actual &&
370 git rm -f submod &&
59a06e94 371 test_path_is_missing submod &&
9e189f1a 372 git status -s -uno --ignore-submodules=none >actual &&
95c16418
JL
373 test_cmp expect actual &&
374 test_must_fail git config -f .gitmodules submodule.sub.url &&
375 test_must_fail git config -f .gitmodules submodule.sub.path
376'
377
378test_expect_success 'rm --cached leaves work tree of populated submodules and .gitmodules alone' '
379 git reset --hard &&
380 git submodule update &&
381 git rm --cached submod &&
59a06e94
RA
382 test_path_is_dir submod &&
383 test_path_is_file submod/.git &&
95c16418
JL
384 git status -s -uno >actual &&
385 test_cmp expect.cached actual &&
386 git config -f .gitmodules submodule.sub.url &&
387 git config -f .gitmodules submodule.sub.path
388'
389
390test_expect_success 'rm --dry-run does not touch the submodule or .gitmodules' '
391 git reset --hard &&
392 git submodule update &&
393 git rm -n submod &&
59a06e94 394 test_path_is_file submod/.git &&
95c16418
JL
395 git diff-index --exit-code HEAD
396'
397
398test_expect_success 'rm does not complain when no .gitmodules file is found' '
399 git reset --hard &&
400 git submodule update &&
401 git rm .gitmodules &&
402 git rm submod >actual 2>actual.err &&
ec10b018 403 test_must_be_empty actual.err &&
59a06e94
RA
404 test_path_is_missing submod &&
405 test_path_is_missing submod/.git &&
95c16418
JL
406 git status -s -uno >actual &&
407 test_cmp expect.both_deleted actual
408'
409
410test_expect_success 'rm will error out on a modified .gitmodules file unless staged' '
411 git reset --hard &&
412 git submodule update &&
413 git config -f .gitmodules foo.bar true &&
414 test_must_fail git rm submod >actual 2>actual.err &&
59a06e94
RA
415 test_file_not_empty actual.err &&
416 test_path_is_dir submod &&
417 test_path_is_file submod/.git &&
95c16418
JL
418 git diff-files --quiet -- submod &&
419 git add .gitmodules &&
420 git rm submod >actual 2>actual.err &&
ec10b018 421 test_must_be_empty actual.err &&
59a06e94
RA
422 test_path_is_missing submod &&
423 test_path_is_missing submod/.git &&
95c16418
JL
424 git status -s -uno >actual &&
425 test_cmp expect actual
426'
7edee329
DT
427test_expect_success 'rm will not error out on .gitmodules file with zero stat data' '
428 git reset --hard &&
429 git submodule update &&
430 git read-tree HEAD &&
431 git rm submod &&
432 test_path_is_missing submod
433'
95c16418
JL
434
435test_expect_success 'rm issues a warning when section is not found in .gitmodules' '
436 git reset --hard &&
437 git submodule update &&
438 git config -f .gitmodules --remove-section submodule.sub &&
439 git add .gitmodules &&
440 echo "warning: Could not find section in .gitmodules where path=submod" >expect.err &&
441 git rm submod >actual 2>actual.err &&
442 test_i18ncmp expect.err actual.err &&
59a06e94
RA
443 test_path_is_missing submod &&
444 test_path_is_missing submod/.git &&
95c16418 445 git status -s -uno >actual &&
293ab15e
JL
446 test_cmp expect actual
447'
448
449test_expect_success 'rm of a populated submodule with modifications fails unless forced' '
450 git reset --hard &&
451 git submodule update &&
9e189f1a 452 echo X >submod/empty &&
293ab15e 453 test_must_fail git rm submod &&
59a06e94
RA
454 test_path_is_dir submod &&
455 test_path_is_file submod/.git &&
9e189f1a 456 git status -s -uno --ignore-submodules=none >actual &&
dd6962dd 457 test_cmp expect.modified_inside actual &&
293ab15e 458 git rm -f submod &&
59a06e94 459 test_path_is_missing submod &&
9e189f1a 460 git status -s -uno --ignore-submodules=none >actual &&
293ab15e
JL
461 test_cmp expect actual
462'
463
464test_expect_success 'rm of a populated submodule with untracked files fails unless forced' '
465 git reset --hard &&
466 git submodule update &&
9e189f1a 467 echo X >submod/untracked &&
293ab15e 468 test_must_fail git rm submod &&
59a06e94
RA
469 test_path_is_dir submod &&
470 test_path_is_file submod/.git &&
9e189f1a 471 git status -s -uno --ignore-submodules=none >actual &&
dd6962dd 472 test_cmp expect.modified_untracked actual &&
293ab15e 473 git rm -f submod &&
59a06e94 474 test_path_is_missing submod &&
9e189f1a 475 git status -s -uno --ignore-submodules=none >actual &&
293ab15e
JL
476 test_cmp expect actual
477'
478
479test_expect_success 'setup submodule conflict' '
480 git reset --hard &&
481 git submodule update &&
482 git checkout -b branch1 &&
483 echo 1 >nitfol &&
484 git add nitfol &&
485 git commit -m "added nitfol 1" &&
486 git checkout -b branch2 master &&
487 echo 2 >nitfol &&
488 git add nitfol &&
489 git commit -m "added nitfol 2" &&
490 git checkout -b conflict1 master &&
9e189f1a
SB
491 git -C submod fetch &&
492 git -C submod checkout branch1 &&
293ab15e
JL
493 git add submod &&
494 git commit -m "submod 1" &&
495 git checkout -b conflict2 master &&
9e189f1a 496 git -C submod checkout branch2 &&
293ab15e
JL
497 git add submod &&
498 git commit -m "submod 2"
499'
500
501cat >expect.conflict <<EOF
502UU submod
503EOF
504
505test_expect_success 'rm removes work tree of unmodified conflicted submodule' '
506 git checkout conflict1 &&
507 git reset --hard &&
508 git submodule update &&
509 test_must_fail git merge conflict2 &&
510 git rm submod &&
59a06e94 511 test_path_is_missing submod &&
9e189f1a 512 git status -s -uno --ignore-submodules=none >actual &&
293ab15e
JL
513 test_cmp expect actual
514'
515
516test_expect_success 'rm of a conflicted populated submodule with different HEAD fails unless forced' '
517 git checkout conflict1 &&
518 git reset --hard &&
519 git submodule update &&
9e189f1a 520 git -C submod checkout HEAD^ &&
293ab15e
JL
521 test_must_fail git merge conflict2 &&
522 test_must_fail git rm submod &&
59a06e94
RA
523 test_path_is_dir submod &&
524 test_path_is_file submod/.git &&
9e189f1a 525 git status -s -uno --ignore-submodules=none >actual &&
293ab15e
JL
526 test_cmp expect.conflict actual &&
527 git rm -f submod &&
59a06e94 528 test_path_is_missing submod &&
9e189f1a 529 git status -s -uno --ignore-submodules=none >actual &&
95c16418
JL
530 test_cmp expect actual &&
531 test_must_fail git config -f .gitmodules submodule.sub.url &&
532 test_must_fail git config -f .gitmodules submodule.sub.path
293ab15e
JL
533'
534
535test_expect_success 'rm of a conflicted populated submodule with modifications fails unless forced' '
536 git checkout conflict1 &&
537 git reset --hard &&
538 git submodule update &&
9e189f1a 539 echo X >submod/empty &&
293ab15e
JL
540 test_must_fail git merge conflict2 &&
541 test_must_fail git rm submod &&
59a06e94
RA
542 test_path_is_dir submod &&
543 test_path_is_file submod/.git &&
9e189f1a 544 git status -s -uno --ignore-submodules=none >actual &&
293ab15e
JL
545 test_cmp expect.conflict actual &&
546 git rm -f submod &&
59a06e94 547 test_path_is_missing submod &&
9e189f1a 548 git status -s -uno --ignore-submodules=none >actual &&
95c16418
JL
549 test_cmp expect actual &&
550 test_must_fail git config -f .gitmodules submodule.sub.url &&
551 test_must_fail git config -f .gitmodules submodule.sub.path
293ab15e
JL
552'
553
554test_expect_success 'rm of a conflicted populated submodule with untracked files fails unless forced' '
555 git checkout conflict1 &&
556 git reset --hard &&
557 git submodule update &&
9e189f1a 558 echo X >submod/untracked &&
293ab15e
JL
559 test_must_fail git merge conflict2 &&
560 test_must_fail git rm submod &&
59a06e94
RA
561 test_path_is_dir submod &&
562 test_path_is_file submod/.git &&
9e189f1a 563 git status -s -uno --ignore-submodules=none >actual &&
293ab15e
JL
564 test_cmp expect.conflict actual &&
565 git rm -f submod &&
59a06e94 566 test_path_is_missing submod &&
9e189f1a 567 git status -s -uno --ignore-submodules=none >actual &&
293ab15e
JL
568 test_cmp expect actual
569'
570
571test_expect_success 'rm of a conflicted populated submodule with a .git directory fails even when forced' '
572 git checkout conflict1 &&
573 git reset --hard &&
574 git submodule update &&
b5368c23
RA
575 (
576 cd submod &&
293ab15e 577 rm .git &&
2d3ac9ad 578 cp -R ../.git/modules/sub .git &&
293ab15e
JL
579 GIT_WORK_TREE=. git config --unset core.worktree
580 ) &&
581 test_must_fail git merge conflict2 &&
582 test_must_fail git rm submod &&
59a06e94
RA
583 test_path_is_dir submod &&
584 test_path_is_dir submod/.git &&
9e189f1a 585 git status -s -uno --ignore-submodules=none >actual &&
293ab15e
JL
586 test_cmp expect.conflict actual &&
587 test_must_fail git rm -f submod &&
59a06e94
RA
588 test_path_is_dir submod &&
589 test_path_is_dir submod/.git &&
9e189f1a 590 git status -s -uno --ignore-submodules=none >actual &&
293ab15e
JL
591 test_cmp expect.conflict actual &&
592 git merge --abort &&
593 rm -rf submod
594'
595
596test_expect_success 'rm of a conflicted unpopulated submodule succeeds' '
597 git checkout conflict1 &&
598 git reset --hard &&
599 test_must_fail git merge conflict2 &&
600 git rm submod &&
59a06e94 601 test_path_is_missing submod &&
9e189f1a 602 git status -s -uno --ignore-submodules=none >actual &&
293ab15e
JL
603 test_cmp expect actual
604'
605
55856a35 606test_expect_success 'rm of a populated submodule with a .git directory migrates git dir' '
293ab15e
JL
607 git checkout -f master &&
608 git reset --hard &&
609 git submodule update &&
b5368c23
RA
610 (
611 cd submod &&
293ab15e 612 rm .git &&
2d3ac9ad 613 cp -R ../.git/modules/sub .git &&
55856a35
SB
614 GIT_WORK_TREE=. git config --unset core.worktree &&
615 rm -r ../.git/modules/sub
293ab15e 616 ) &&
55856a35 617 git rm submod 2>output.err &&
59a06e94
RA
618 test_path_is_missing submod &&
619 test_path_is_missing submod/.git &&
9e189f1a 620 git status -s -uno --ignore-submodules=none >actual &&
59a06e94 621 test_file_not_empty actual &&
55856a35 622 test_i18ngrep Migrating output.err
293ab15e
JL
623'
624
625cat >expect.deepmodified <<EOF
626 M submod/subsubmod
627EOF
628
629test_expect_success 'setup subsubmodule' '
630 git reset --hard &&
631 git submodule update &&
b5368c23
RA
632 (
633 cd submod &&
3b737381
DL
634 hash=$(git rev-parse HEAD) &&
635 git update-index --add --cacheinfo 160000 "$hash" subsubmod &&
293ab15e
JL
636 git config -f .gitmodules submodule.sub.url ../. &&
637 git config -f .gitmodules submodule.sub.path subsubmod &&
638 git submodule init &&
639 git add .gitmodules &&
640 git commit -m "add subsubmodule" &&
641 git submodule update subsubmod
642 ) &&
643 git commit -a -m "added deep submodule"
644'
645
646test_expect_success 'rm recursively removes work tree of unmodified submodules' '
647 git rm submod &&
59a06e94 648 test_path_is_missing submod &&
9e189f1a 649 git status -s -uno --ignore-submodules=none >actual &&
293ab15e
JL
650 test_cmp expect actual
651'
652
653test_expect_success 'rm of a populated nested submodule with different nested HEAD fails unless forced' '
654 git reset --hard &&
655 git submodule update --recursive &&
9e189f1a 656 git -C submod/subsubmod checkout HEAD^ &&
293ab15e 657 test_must_fail git rm submod &&
59a06e94
RA
658 test_path_is_dir submod &&
659 test_path_is_file submod/.git &&
9e189f1a 660 git status -s -uno --ignore-submodules=none >actual &&
dd6962dd 661 test_cmp expect.modified_inside actual &&
293ab15e 662 git rm -f submod &&
59a06e94 663 test_path_is_missing submod &&
9e189f1a 664 git status -s -uno --ignore-submodules=none >actual &&
293ab15e
JL
665 test_cmp expect actual
666'
667
668test_expect_success 'rm of a populated nested submodule with nested modifications fails unless forced' '
669 git reset --hard &&
670 git submodule update --recursive &&
9e189f1a 671 echo X >submod/subsubmod/empty &&
293ab15e 672 test_must_fail git rm submod &&
59a06e94
RA
673 test_path_is_dir submod &&
674 test_path_is_file submod/.git &&
9e189f1a 675 git status -s -uno --ignore-submodules=none >actual &&
dd6962dd 676 test_cmp expect.modified_inside actual &&
293ab15e 677 git rm -f submod &&
59a06e94 678 test_path_is_missing submod &&
9e189f1a 679 git status -s -uno --ignore-submodules=none >actual &&
293ab15e
JL
680 test_cmp expect actual
681'
682
683test_expect_success 'rm of a populated nested submodule with nested untracked files fails unless forced' '
684 git reset --hard &&
685 git submodule update --recursive &&
9e189f1a 686 echo X >submod/subsubmod/untracked &&
293ab15e 687 test_must_fail git rm submod &&
59a06e94
RA
688 test_path_is_dir submod &&
689 test_path_is_file submod/.git &&
9e189f1a 690 git status -s -uno --ignore-submodules=none >actual &&
40069d6e 691 test_cmp expect.modified_untracked actual &&
293ab15e 692 git rm -f submod &&
59a06e94 693 test_path_is_missing submod &&
9e189f1a 694 git status -s -uno --ignore-submodules=none >actual &&
293ab15e
JL
695 test_cmp expect actual
696'
697
70471ed9 698test_expect_success "rm absorbs submodule's nested .git directory" '
293ab15e
JL
699 git reset --hard &&
700 git submodule update --recursive &&
b5368c23
RA
701 (
702 cd submod/subsubmod &&
293ab15e 703 rm .git &&
55856a35 704 mv ../../.git/modules/sub/modules/sub .git &&
293ab15e
JL
705 GIT_WORK_TREE=. git config --unset core.worktree
706 ) &&
55856a35 707 git rm submod 2>output.err &&
59a06e94
RA
708 test_path_is_missing submod &&
709 test_path_is_missing submod/subsubmod/.git &&
9e189f1a 710 git status -s -uno --ignore-submodules=none >actual &&
59a06e94 711 test_file_not_empty actual &&
55856a35 712 test_i18ngrep Migrating output.err
293ab15e
JL
713'
714
bbad9f93 715test_expect_success 'checking out a commit after submodule removal needs manual updates' '
55856a35 716 git commit -m "submodule removal" submod .gitmodules &&
bbad9f93
JL
717 git checkout HEAD^ &&
718 git submodule update &&
8954bd76 719 git checkout -q HEAD^ &&
bbad9f93 720 git checkout -q master 2>actual &&
0a288d1e 721 test_i18ngrep "^warning: unable to rmdir '\''submod'\'':" actual &&
bbad9f93
JL
722 git status -s submod >actual &&
723 echo "?? submod/" >expected &&
724 test_cmp expected actual &&
725 rm -rf submod &&
9e189f1a 726 git status -s -uno --ignore-submodules=none >actual &&
ec10b018 727 test_must_be_empty actual
bbad9f93
JL
728'
729
9a6728d4
JK
730test_expect_success 'rm of d/f when d has become a non-directory' '
731 rm -rf d &&
732 mkdir d &&
733 >d/f &&
734 git add d &&
735 rm -rf d &&
736 >d &&
737 git rm d/f &&
738 test_must_fail git rev-parse --verify :d/f &&
739 test_path_is_file d
740'
741
742test_expect_success SYMLINKS 'rm of d/f when d has become a dangling symlink' '
743 rm -rf d &&
744 mkdir d &&
745 >d/f &&
746 git add d &&
747 rm -rf d &&
748 ln -s nonexistent d &&
749 git rm d/f &&
750 test_must_fail git rev-parse --verify :d/f &&
751 test -h d &&
752 test_path_is_missing d
753'
754
96ec8ee9
JK
755test_expect_success 'rm of file when it has become a directory' '
756 rm -rf d &&
757 >d &&
758 git add d &&
759 rm -f d &&
760 mkdir d &&
761 >d/f &&
762 test_must_fail git rm d &&
763 git rev-parse --verify :d &&
764 test_path_is_file d/f
765'
766
03415ca8
JK
767test_expect_success SYMLINKS 'rm across a symlinked leading path (no index)' '
768 rm -rf d e &&
769 mkdir e &&
770 echo content >e/f &&
771 ln -s e d &&
772 git add -A e d &&
773 git commit -m "symlink d to e, e/f exists" &&
774 test_must_fail git rm d/f &&
775 git rev-parse --verify :d &&
776 git rev-parse --verify :e/f &&
777 test -h d &&
778 test_path_is_file e/f
779'
780
781test_expect_failure SYMLINKS 'rm across a symlinked leading path (w/ index)' '
782 rm -rf d e &&
783 mkdir d &&
784 echo content >d/f &&
785 git add -A e d &&
786 git commit -m "d/f exists" &&
787 mv d e &&
788 ln -s e d &&
789 test_must_fail git rm d/f &&
790 git rev-parse --verify :d/f &&
791 test -h d &&
792 test_path_is_file e/f
793'
794
914dc028
MLM
795test_expect_success 'setup for testing rm messages' '
796 >bar.txt &&
797 >foo.txt &&
798 git add bar.txt foo.txt
799'
800
801test_expect_success 'rm files with different staged content' '
802 cat >expect <<-\EOF &&
803 error: the following files have staged content different from both the
804 file and the HEAD:
805 bar.txt
806 foo.txt
807 (use -f to force removal)
808 EOF
809 echo content1 >foo.txt &&
810 echo content1 >bar.txt &&
811 test_must_fail git rm foo.txt bar.txt 2>actual &&
812 test_i18ncmp expect actual
813'
814
7e309446
MLM
815test_expect_success 'rm files with different staged content without hints' '
816 cat >expect <<-\EOF &&
817 error: the following files have staged content different from both the
818 file and the HEAD:
819 bar.txt
820 foo.txt
821 EOF
822 echo content2 >foo.txt &&
823 echo content2 >bar.txt &&
824 test_must_fail git -c advice.rmhints=false rm foo.txt bar.txt 2>actual &&
825 test_i18ncmp expect actual
826'
914dc028
MLM
827
828test_expect_success 'rm file with local modification' '
829 cat >expect <<-\EOF &&
830 error: the following file has local modifications:
831 foo.txt
832 (use --cached to keep the file, or -f to force removal)
833 EOF
834 git commit -m "testing rm 3" &&
835 echo content3 >foo.txt &&
836 test_must_fail git rm foo.txt 2>actual &&
837 test_i18ncmp expect actual
838'
839
7e309446
MLM
840test_expect_success 'rm file with local modification without hints' '
841 cat >expect <<-\EOF &&
842 error: the following file has local modifications:
843 bar.txt
844 EOF
845 echo content4 >bar.txt &&
846 test_must_fail git -c advice.rmhints=false rm bar.txt 2>actual &&
847 test_i18ncmp expect actual
848'
914dc028
MLM
849
850test_expect_success 'rm file with changes in the index' '
851 cat >expect <<-\EOF &&
852 error: the following file has changes staged in the index:
853 foo.txt
854 (use --cached to keep the file, or -f to force removal)
855 EOF
856 git reset --hard &&
857 echo content5 >foo.txt &&
858 git add foo.txt &&
859 test_must_fail git rm foo.txt 2>actual &&
860 test_i18ncmp expect actual
861'
862
7e309446
MLM
863test_expect_success 'rm file with changes in the index without hints' '
864 cat >expect <<-\EOF &&
865 error: the following file has changes staged in the index:
866 foo.txt
867 EOF
868 test_must_fail git -c advice.rmhints=false rm foo.txt 2>actual &&
869 test_i18ncmp expect actual
870'
914dc028
MLM
871
872test_expect_success 'rm files with two different errors' '
873 cat >expect <<-\EOF &&
874 error: the following file has staged content different from both the
875 file and the HEAD:
876 foo1.txt
877 (use -f to force removal)
878 error: the following file has changes staged in the index:
879 bar1.txt
880 (use --cached to keep the file, or -f to force removal)
881 EOF
882 echo content >foo1.txt &&
883 git add foo1.txt &&
884 echo content6 >foo1.txt &&
885 echo content6 >bar1.txt &&
886 git add bar1.txt &&
887 test_must_fail git rm bar1.txt foo1.txt 2>actual &&
888 test_i18ncmp expect actual
889'
890
9e4e8a64
EX
891test_expect_success 'rm empty string should fail' '
892 test_must_fail git rm -rf ""
d426430e
EX
893'
894
d4a1cab5 895test_done