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