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