]>
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' ' |
56e78bfb JS |
100 | chmod a-w . && |
101 | test_must_fail git rm -f baz && | |
102 | chmod 775 . | |
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 SG |
113 | test_expect_success '"rm" command printed' ' |
114 | echo frotz > test-file && | |
115 | git add test-file && | |
116 | git commit -m "add file for rm test" && | |
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' ' | |
124 | echo frotz > test-file && | |
125 | git add test-file && | |
126 | git commit -m "add file for rm --quiet test" && | |
127 | git rm --quiet test-file > rm-output && | |
e3ab3bc2 | 128 | test $(wc -l < rm-output) = 0 && |
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 && | |
224 | echo something > somefile && | |
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 | ||
95c16418 JL |
271 | cat >expect.cached <<EOF |
272 | D submod | |
273 | EOF | |
274 | ||
275 | cat >expect.both_deleted<<EOF | |
276 | D .gitmodules | |
277 | D submod | |
278 | EOF | |
279 | ||
293ab15e JL |
280 | test_expect_success 'rm removes empty submodules from work tree' ' |
281 | mkdir submod && | |
282 | git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) submod && | |
283 | git config -f .gitmodules submodule.sub.url ./. && | |
284 | git config -f .gitmodules submodule.sub.path submod && | |
285 | git submodule init && | |
286 | git add .gitmodules && | |
287 | git commit -m "add submodule" && | |
288 | git rm submod && | |
289 | test ! -e submod && | |
290 | git status -s -uno --ignore-submodules=none > actual && | |
95c16418 JL |
291 | test_cmp expect actual && |
292 | test_must_fail git config -f .gitmodules submodule.sub.url && | |
293 | test_must_fail git config -f .gitmodules submodule.sub.path | |
293ab15e JL |
294 | ' |
295 | ||
95c16418 | 296 | test_expect_success 'rm removes removed submodule from index and .gitmodules' ' |
293ab15e JL |
297 | git reset --hard && |
298 | git submodule update && | |
299 | rm -rf submod && | |
300 | git rm submod && | |
301 | git status -s -uno --ignore-submodules=none > actual && | |
95c16418 JL |
302 | test_cmp expect actual && |
303 | test_must_fail git config -f .gitmodules submodule.sub.url && | |
304 | test_must_fail git config -f .gitmodules submodule.sub.path | |
293ab15e JL |
305 | ' |
306 | ||
307 | test_expect_success 'rm removes work tree of unmodified submodules' ' | |
308 | git reset --hard && | |
309 | git submodule update && | |
310 | git rm submod && | |
311 | test ! -d submod && | |
312 | git status -s -uno --ignore-submodules=none > actual && | |
95c16418 JL |
313 | test_cmp expect actual && |
314 | test_must_fail git config -f .gitmodules submodule.sub.url && | |
315 | test_must_fail git config -f .gitmodules submodule.sub.path | |
293ab15e JL |
316 | ' |
317 | ||
53e4c5dc JL |
318 | test_expect_success 'rm removes a submodule with a trailing /' ' |
319 | git reset --hard && | |
320 | git submodule update && | |
321 | git rm submod/ && | |
322 | test ! -d submod && | |
323 | git status -s -uno --ignore-submodules=none > actual && | |
324 | test_cmp expect actual | |
325 | ' | |
326 | ||
327 | test_expect_success 'rm fails when given a file with a trailing /' ' | |
328 | test_must_fail git rm empty/ | |
329 | ' | |
330 | ||
331 | test_expect_success 'rm succeeds when given a directory with a trailing /' ' | |
332 | git rm -r frotz/ | |
333 | ' | |
334 | ||
293ab15e JL |
335 | test_expect_success 'rm of a populated submodule with different HEAD fails unless forced' ' |
336 | git reset --hard && | |
337 | git submodule update && | |
338 | (cd submod && | |
339 | git checkout HEAD^ | |
340 | ) && | |
341 | test_must_fail git rm submod && | |
342 | test -d submod && | |
343 | test -f submod/.git && | |
344 | git status -s -uno --ignore-submodules=none > actual && | |
345 | test_cmp expect.modified actual && | |
346 | git rm -f submod && | |
347 | test ! -d submod && | |
348 | git status -s -uno --ignore-submodules=none > actual && | |
95c16418 JL |
349 | test_cmp expect actual && |
350 | test_must_fail git config -f .gitmodules submodule.sub.url && | |
351 | test_must_fail git config -f .gitmodules submodule.sub.path | |
352 | ' | |
353 | ||
354 | test_expect_success 'rm --cached leaves work tree of populated submodules and .gitmodules alone' ' | |
355 | git reset --hard && | |
356 | git submodule update && | |
357 | git rm --cached submod && | |
358 | test -d submod && | |
359 | test -f submod/.git && | |
360 | git status -s -uno >actual && | |
361 | test_cmp expect.cached actual && | |
362 | git config -f .gitmodules submodule.sub.url && | |
363 | git config -f .gitmodules submodule.sub.path | |
364 | ' | |
365 | ||
366 | test_expect_success 'rm --dry-run does not touch the submodule or .gitmodules' ' | |
367 | git reset --hard && | |
368 | git submodule update && | |
369 | git rm -n submod && | |
370 | test -f submod/.git && | |
371 | git diff-index --exit-code HEAD | |
372 | ' | |
373 | ||
374 | test_expect_success 'rm does not complain when no .gitmodules file is found' ' | |
375 | git reset --hard && | |
376 | git submodule update && | |
377 | git rm .gitmodules && | |
378 | git rm submod >actual 2>actual.err && | |
379 | ! test -s actual.err && | |
380 | ! test -d submod && | |
381 | ! test -f submod/.git && | |
382 | git status -s -uno >actual && | |
383 | test_cmp expect.both_deleted actual | |
384 | ' | |
385 | ||
386 | test_expect_success 'rm will error out on a modified .gitmodules file unless staged' ' | |
387 | git reset --hard && | |
388 | git submodule update && | |
389 | git config -f .gitmodules foo.bar true && | |
390 | test_must_fail git rm submod >actual 2>actual.err && | |
391 | test -s actual.err && | |
392 | test -d submod && | |
393 | test -f submod/.git && | |
394 | git diff-files --quiet -- submod && | |
395 | git add .gitmodules && | |
396 | git rm submod >actual 2>actual.err && | |
397 | ! test -s actual.err && | |
398 | ! test -d submod && | |
399 | ! test -f submod/.git && | |
400 | git status -s -uno >actual && | |
401 | test_cmp expect actual | |
402 | ' | |
403 | ||
404 | test_expect_success 'rm issues a warning when section is not found in .gitmodules' ' | |
405 | git reset --hard && | |
406 | git submodule update && | |
407 | git config -f .gitmodules --remove-section submodule.sub && | |
408 | git add .gitmodules && | |
409 | echo "warning: Could not find section in .gitmodules where path=submod" >expect.err && | |
410 | git rm submod >actual 2>actual.err && | |
411 | test_i18ncmp expect.err actual.err && | |
412 | ! test -d submod && | |
413 | ! test -f submod/.git && | |
414 | git status -s -uno >actual && | |
293ab15e JL |
415 | test_cmp expect actual |
416 | ' | |
417 | ||
418 | test_expect_success 'rm of a populated submodule with modifications fails unless forced' ' | |
419 | git reset --hard && | |
420 | git submodule update && | |
421 | (cd submod && | |
422 | echo X >empty | |
423 | ) && | |
424 | test_must_fail git rm submod && | |
425 | test -d submod && | |
426 | test -f submod/.git && | |
427 | git status -s -uno --ignore-submodules=none > actual && | |
428 | test_cmp expect.modified actual && | |
429 | git rm -f submod && | |
430 | test ! -d submod && | |
431 | git status -s -uno --ignore-submodules=none > actual && | |
432 | test_cmp expect actual | |
433 | ' | |
434 | ||
435 | test_expect_success 'rm of a populated submodule with untracked files fails unless forced' ' | |
436 | git reset --hard && | |
437 | git submodule update && | |
438 | (cd submod && | |
439 | echo X >untracked | |
440 | ) && | |
441 | test_must_fail git rm submod && | |
442 | test -d submod && | |
443 | test -f submod/.git && | |
444 | git status -s -uno --ignore-submodules=none > actual && | |
445 | test_cmp expect.modified actual && | |
446 | git rm -f submod && | |
447 | test ! -d submod && | |
448 | git status -s -uno --ignore-submodules=none > actual && | |
449 | test_cmp expect actual | |
450 | ' | |
451 | ||
452 | test_expect_success 'setup submodule conflict' ' | |
453 | git reset --hard && | |
454 | git submodule update && | |
455 | git checkout -b branch1 && | |
456 | echo 1 >nitfol && | |
457 | git add nitfol && | |
458 | git commit -m "added nitfol 1" && | |
459 | git checkout -b branch2 master && | |
460 | echo 2 >nitfol && | |
461 | git add nitfol && | |
462 | git commit -m "added nitfol 2" && | |
463 | git checkout -b conflict1 master && | |
464 | (cd submod && | |
465 | git fetch && | |
466 | git checkout branch1 | |
467 | ) && | |
468 | git add submod && | |
469 | git commit -m "submod 1" && | |
470 | git checkout -b conflict2 master && | |
471 | (cd submod && | |
472 | git checkout branch2 | |
473 | ) && | |
474 | git add submod && | |
475 | git commit -m "submod 2" | |
476 | ' | |
477 | ||
478 | cat >expect.conflict <<EOF | |
479 | UU submod | |
480 | EOF | |
481 | ||
482 | test_expect_success 'rm removes work tree of unmodified conflicted submodule' ' | |
483 | git checkout conflict1 && | |
484 | git reset --hard && | |
485 | git submodule update && | |
486 | test_must_fail git merge conflict2 && | |
487 | git rm submod && | |
488 | test ! -d submod && | |
489 | git status -s -uno --ignore-submodules=none > actual && | |
490 | test_cmp expect actual | |
491 | ' | |
492 | ||
493 | test_expect_success 'rm of a conflicted populated submodule with different HEAD fails unless forced' ' | |
494 | git checkout conflict1 && | |
495 | git reset --hard && | |
496 | git submodule update && | |
497 | (cd submod && | |
498 | git checkout HEAD^ | |
499 | ) && | |
500 | test_must_fail git merge conflict2 && | |
501 | test_must_fail git rm submod && | |
502 | test -d submod && | |
503 | test -f submod/.git && | |
504 | git status -s -uno --ignore-submodules=none > actual && | |
505 | test_cmp expect.conflict actual && | |
506 | git rm -f submod && | |
507 | test ! -d submod && | |
508 | git status -s -uno --ignore-submodules=none > actual && | |
95c16418 JL |
509 | test_cmp expect actual && |
510 | test_must_fail git config -f .gitmodules submodule.sub.url && | |
511 | test_must_fail git config -f .gitmodules submodule.sub.path | |
293ab15e JL |
512 | ' |
513 | ||
514 | test_expect_success 'rm of a conflicted populated submodule with modifications fails unless forced' ' | |
515 | git checkout conflict1 && | |
516 | git reset --hard && | |
517 | git submodule update && | |
518 | (cd submod && | |
519 | echo X >empty | |
520 | ) && | |
521 | test_must_fail git merge conflict2 && | |
522 | test_must_fail git rm submod && | |
523 | test -d submod && | |
524 | test -f submod/.git && | |
525 | git status -s -uno --ignore-submodules=none > actual && | |
526 | test_cmp expect.conflict actual && | |
527 | git rm -f submod && | |
528 | test ! -d submod && | |
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 | ||
535 | test_expect_success 'rm of a conflicted populated submodule with untracked files fails unless forced' ' | |
536 | git checkout conflict1 && | |
537 | git reset --hard && | |
538 | git submodule update && | |
539 | (cd submod && | |
540 | echo X >untracked | |
541 | ) && | |
542 | test_must_fail git merge conflict2 && | |
543 | test_must_fail git rm submod && | |
544 | test -d submod && | |
545 | test -f submod/.git && | |
546 | git status -s -uno --ignore-submodules=none > actual && | |
547 | test_cmp expect.conflict actual && | |
548 | git rm -f submod && | |
549 | test ! -d submod && | |
550 | git status -s -uno --ignore-submodules=none > actual && | |
551 | test_cmp expect actual | |
552 | ' | |
553 | ||
554 | test_expect_success 'rm of a conflicted populated submodule with a .git directory fails even when forced' ' | |
555 | git checkout conflict1 && | |
556 | git reset --hard && | |
557 | git submodule update && | |
558 | (cd submod && | |
559 | rm .git && | |
2d3ac9ad | 560 | cp -R ../.git/modules/sub .git && |
293ab15e JL |
561 | GIT_WORK_TREE=. git config --unset core.worktree |
562 | ) && | |
563 | test_must_fail git merge conflict2 && | |
564 | test_must_fail git rm submod && | |
565 | test -d submod && | |
566 | test -d submod/.git && | |
567 | git status -s -uno --ignore-submodules=none > actual && | |
568 | test_cmp expect.conflict actual && | |
569 | test_must_fail git rm -f submod && | |
570 | test -d submod && | |
571 | test -d submod/.git && | |
572 | git status -s -uno --ignore-submodules=none > actual && | |
573 | test_cmp expect.conflict actual && | |
574 | git merge --abort && | |
575 | rm -rf submod | |
576 | ' | |
577 | ||
578 | test_expect_success 'rm of a conflicted unpopulated submodule succeeds' ' | |
579 | git checkout conflict1 && | |
580 | git reset --hard && | |
581 | test_must_fail git merge conflict2 && | |
582 | git rm submod && | |
583 | test ! -d submod && | |
584 | git status -s -uno --ignore-submodules=none > actual && | |
585 | test_cmp expect actual | |
586 | ' | |
587 | ||
588 | test_expect_success 'rm of a populated submodule with a .git directory fails even when forced' ' | |
589 | git checkout -f master && | |
590 | git reset --hard && | |
591 | git submodule update && | |
592 | (cd submod && | |
593 | rm .git && | |
2d3ac9ad | 594 | cp -R ../.git/modules/sub .git && |
293ab15e JL |
595 | GIT_WORK_TREE=. git config --unset core.worktree |
596 | ) && | |
597 | test_must_fail git rm submod && | |
598 | test -d submod && | |
599 | test -d submod/.git && | |
600 | git status -s -uno --ignore-submodules=none > actual && | |
601 | ! test -s actual && | |
602 | test_must_fail git rm -f submod && | |
603 | test -d submod && | |
604 | test -d submod/.git && | |
605 | git status -s -uno --ignore-submodules=none > actual && | |
606 | ! test -s actual && | |
607 | rm -rf submod | |
608 | ' | |
609 | ||
610 | cat >expect.deepmodified <<EOF | |
611 | M submod/subsubmod | |
612 | EOF | |
613 | ||
614 | test_expect_success 'setup subsubmodule' ' | |
615 | git reset --hard && | |
616 | git submodule update && | |
617 | (cd submod && | |
618 | git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) subsubmod && | |
619 | git config -f .gitmodules submodule.sub.url ../. && | |
620 | git config -f .gitmodules submodule.sub.path subsubmod && | |
621 | git submodule init && | |
622 | git add .gitmodules && | |
623 | git commit -m "add subsubmodule" && | |
624 | git submodule update subsubmod | |
625 | ) && | |
626 | git commit -a -m "added deep submodule" | |
627 | ' | |
628 | ||
629 | test_expect_success 'rm recursively removes work tree of unmodified submodules' ' | |
630 | git rm submod && | |
631 | test ! -d submod && | |
632 | git status -s -uno --ignore-submodules=none > actual && | |
633 | test_cmp expect actual | |
634 | ' | |
635 | ||
636 | test_expect_success 'rm of a populated nested submodule with different nested HEAD fails unless forced' ' | |
637 | git reset --hard && | |
638 | git submodule update --recursive && | |
639 | (cd submod/subsubmod && | |
640 | git checkout HEAD^ | |
641 | ) && | |
642 | test_must_fail git rm submod && | |
643 | test -d submod && | |
644 | test -f submod/.git && | |
645 | git status -s -uno --ignore-submodules=none > actual && | |
646 | test_cmp expect.modified actual && | |
647 | git rm -f submod && | |
648 | test ! -d submod && | |
649 | git status -s -uno --ignore-submodules=none > actual && | |
650 | test_cmp expect actual | |
651 | ' | |
652 | ||
653 | test_expect_success 'rm of a populated nested submodule with nested modifications fails unless forced' ' | |
654 | git reset --hard && | |
655 | git submodule update --recursive && | |
656 | (cd submod/subsubmod && | |
657 | echo X >empty | |
658 | ) && | |
659 | test_must_fail git rm submod && | |
660 | test -d submod && | |
661 | test -f submod/.git && | |
662 | git status -s -uno --ignore-submodules=none > actual && | |
663 | test_cmp expect.modified actual && | |
664 | git rm -f submod && | |
665 | test ! -d submod && | |
666 | git status -s -uno --ignore-submodules=none > actual && | |
667 | test_cmp expect actual | |
668 | ' | |
669 | ||
670 | test_expect_success 'rm of a populated nested submodule with nested untracked files fails unless forced' ' | |
671 | git reset --hard && | |
672 | git submodule update --recursive && | |
673 | (cd submod/subsubmod && | |
674 | echo X >untracked | |
675 | ) && | |
676 | test_must_fail git rm submod && | |
677 | test -d submod && | |
678 | test -f submod/.git && | |
679 | git status -s -uno --ignore-submodules=none > actual && | |
680 | test_cmp expect.modified actual && | |
681 | git rm -f submod && | |
682 | test ! -d submod && | |
683 | git status -s -uno --ignore-submodules=none > actual && | |
684 | test_cmp expect actual | |
685 | ' | |
686 | ||
687 | test_expect_success 'rm of a populated nested submodule with a nested .git directory fails even when forced' ' | |
688 | git reset --hard && | |
689 | git submodule update --recursive && | |
690 | (cd submod/subsubmod && | |
691 | rm .git && | |
2d3ac9ad | 692 | cp -R ../../.git/modules/sub/modules/sub .git && |
293ab15e JL |
693 | GIT_WORK_TREE=. git config --unset core.worktree |
694 | ) && | |
695 | test_must_fail git rm submod && | |
696 | test -d submod && | |
697 | test -d submod/subsubmod/.git && | |
698 | git status -s -uno --ignore-submodules=none > actual && | |
699 | ! test -s actual && | |
700 | test_must_fail git rm -f submod && | |
701 | test -d submod && | |
702 | test -d submod/subsubmod/.git && | |
703 | git status -s -uno --ignore-submodules=none > actual && | |
704 | ! test -s actual && | |
705 | rm -rf submod | |
706 | ' | |
707 | ||
bbad9f93 JL |
708 | test_expect_success 'checking out a commit after submodule removal needs manual updates' ' |
709 | git commit -m "submodule removal" submod && | |
710 | git checkout HEAD^ && | |
711 | git submodule update && | |
712 | git checkout -q HEAD^ 2>actual && | |
713 | git checkout -q master 2>actual && | |
11b53902 | 714 | test_i18ngrep "^warning: unable to rmdir submod:" actual && |
bbad9f93 JL |
715 | git status -s submod >actual && |
716 | echo "?? submod/" >expected && | |
717 | test_cmp expected actual && | |
718 | rm -rf submod && | |
719 | git status -s -uno --ignore-submodules=none > actual && | |
720 | ! test -s actual | |
721 | ' | |
722 | ||
9a6728d4 JK |
723 | test_expect_success 'rm of d/f when d has become a non-directory' ' |
724 | rm -rf d && | |
725 | mkdir d && | |
726 | >d/f && | |
727 | git add d && | |
728 | rm -rf d && | |
729 | >d && | |
730 | git rm d/f && | |
731 | test_must_fail git rev-parse --verify :d/f && | |
732 | test_path_is_file d | |
733 | ' | |
734 | ||
735 | test_expect_success SYMLINKS 'rm of d/f when d has become a dangling symlink' ' | |
736 | rm -rf d && | |
737 | mkdir d && | |
738 | >d/f && | |
739 | git add d && | |
740 | rm -rf d && | |
741 | ln -s nonexistent d && | |
742 | git rm d/f && | |
743 | test_must_fail git rev-parse --verify :d/f && | |
744 | test -h d && | |
745 | test_path_is_missing d | |
746 | ' | |
747 | ||
96ec8ee9 JK |
748 | test_expect_success 'rm of file when it has become a directory' ' |
749 | rm -rf d && | |
750 | >d && | |
751 | git add d && | |
752 | rm -f d && | |
753 | mkdir d && | |
754 | >d/f && | |
755 | test_must_fail git rm d && | |
756 | git rev-parse --verify :d && | |
757 | test_path_is_file d/f | |
758 | ' | |
759 | ||
03415ca8 JK |
760 | test_expect_success SYMLINKS 'rm across a symlinked leading path (no index)' ' |
761 | rm -rf d e && | |
762 | mkdir e && | |
763 | echo content >e/f && | |
764 | ln -s e d && | |
765 | git add -A e d && | |
766 | git commit -m "symlink d to e, e/f exists" && | |
767 | test_must_fail git rm d/f && | |
768 | git rev-parse --verify :d && | |
769 | git rev-parse --verify :e/f && | |
770 | test -h d && | |
771 | test_path_is_file e/f | |
772 | ' | |
773 | ||
774 | test_expect_failure SYMLINKS 'rm across a symlinked leading path (w/ index)' ' | |
775 | rm -rf d e && | |
776 | mkdir d && | |
777 | echo content >d/f && | |
778 | git add -A e d && | |
779 | git commit -m "d/f exists" && | |
780 | mv d e && | |
781 | ln -s e d && | |
782 | test_must_fail git rm d/f && | |
783 | git rev-parse --verify :d/f && | |
784 | test -h d && | |
785 | test_path_is_file e/f | |
786 | ' | |
787 | ||
914dc028 MLM |
788 | test_expect_success 'setup for testing rm messages' ' |
789 | >bar.txt && | |
790 | >foo.txt && | |
791 | git add bar.txt foo.txt | |
792 | ' | |
793 | ||
794 | test_expect_success 'rm files with different staged content' ' | |
795 | cat >expect <<-\EOF && | |
796 | error: the following files have staged content different from both the | |
797 | file and the HEAD: | |
798 | bar.txt | |
799 | foo.txt | |
800 | (use -f to force removal) | |
801 | EOF | |
802 | echo content1 >foo.txt && | |
803 | echo content1 >bar.txt && | |
804 | test_must_fail git rm foo.txt bar.txt 2>actual && | |
805 | test_i18ncmp expect actual | |
806 | ' | |
807 | ||
7e309446 MLM |
808 | test_expect_success 'rm files with different staged content without hints' ' |
809 | cat >expect <<-\EOF && | |
810 | error: the following files have staged content different from both the | |
811 | file and the HEAD: | |
812 | bar.txt | |
813 | foo.txt | |
814 | EOF | |
815 | echo content2 >foo.txt && | |
816 | echo content2 >bar.txt && | |
817 | test_must_fail git -c advice.rmhints=false rm foo.txt bar.txt 2>actual && | |
818 | test_i18ncmp expect actual | |
819 | ' | |
914dc028 MLM |
820 | |
821 | test_expect_success 'rm file with local modification' ' | |
822 | cat >expect <<-\EOF && | |
823 | error: the following file has local modifications: | |
824 | foo.txt | |
825 | (use --cached to keep the file, or -f to force removal) | |
826 | EOF | |
827 | git commit -m "testing rm 3" && | |
828 | echo content3 >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 local modification without hints' ' |
834 | cat >expect <<-\EOF && | |
835 | error: the following file has local modifications: | |
836 | bar.txt | |
837 | EOF | |
838 | echo content4 >bar.txt && | |
839 | test_must_fail git -c advice.rmhints=false rm bar.txt 2>actual && | |
840 | test_i18ncmp expect actual | |
841 | ' | |
914dc028 MLM |
842 | |
843 | test_expect_success 'rm file with changes in the index' ' | |
844 | cat >expect <<-\EOF && | |
845 | error: the following file has changes staged in the index: | |
846 | foo.txt | |
847 | (use --cached to keep the file, or -f to force removal) | |
848 | EOF | |
849 | git reset --hard && | |
850 | echo content5 >foo.txt && | |
851 | git add foo.txt && | |
852 | test_must_fail git rm foo.txt 2>actual && | |
853 | test_i18ncmp expect actual | |
854 | ' | |
855 | ||
7e309446 MLM |
856 | test_expect_success 'rm file with changes in the index without hints' ' |
857 | cat >expect <<-\EOF && | |
858 | error: the following file has changes staged in the index: | |
859 | foo.txt | |
860 | EOF | |
861 | test_must_fail git -c advice.rmhints=false rm foo.txt 2>actual && | |
862 | test_i18ncmp expect actual | |
863 | ' | |
914dc028 MLM |
864 | |
865 | test_expect_success 'rm files with two different errors' ' | |
866 | cat >expect <<-\EOF && | |
867 | error: the following file has staged content different from both the | |
868 | file and the HEAD: | |
869 | foo1.txt | |
870 | (use -f to force removal) | |
871 | error: the following file has changes staged in the index: | |
872 | bar1.txt | |
873 | (use --cached to keep the file, or -f to force removal) | |
874 | EOF | |
875 | echo content >foo1.txt && | |
876 | git add foo1.txt && | |
877 | echo content6 >foo1.txt && | |
878 | echo content6 >bar1.txt && | |
879 | git add bar1.txt && | |
880 | test_must_fail git rm bar1.txt foo1.txt 2>actual && | |
881 | test_i18ncmp expect actual | |
882 | ' | |
883 | ||
d426430e EX |
884 | test_expect_success 'rm empty string should invoke warning' ' |
885 | git rm -rf "" 2>output && | |
886 | test_i18ngrep "warning: empty strings" output | |
887 | ' | |
888 | ||
d4a1cab5 | 889 | test_done |