263
'
264
265
cat >expect <<EOF
266
+M .gitmodules
267
D submod
268
EOF
269
271
M submod
272
EOF
273
274
+cat >expect.cached <<EOF
275
+D submod
276
+EOF
277
+
278
+cat >expect.both_deleted<<EOF
279
+D .gitmodules
280
+D submod
281
+EOF
282
+
283
test_expect_success 'rm removes empty submodules from work tree' '
284
mkdir submod &&
285
git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) submod &&
291
git rm submod &&
292
test ! -e submod &&
293
git status -s -uno --ignore-submodules=none > actual &&
284
- test_cmp expect actual
294
+ test_cmp expect actual &&
295
+ test_must_fail git config -f .gitmodules submodule.sub.url &&
296
+ test_must_fail git config -f .gitmodules submodule.sub.path
297
'
298
287
-test_expect_success 'rm removes removed submodule from index' '
299
+test_expect_success 'rm removes removed submodule from index and .gitmodules' '
300
git reset --hard &&
301
git submodule update &&
302
rm -rf submod &&
303
git rm submod &&
304
git status -s -uno --ignore-submodules=none > actual &&
293
- test_cmp expect actual
305
+ test_cmp expect actual &&
306
+ test_must_fail git config -f .gitmodules submodule.sub.url &&
307
+ test_must_fail git config -f .gitmodules submodule.sub.path
308
'
309
310
test_expect_success 'rm removes work tree of unmodified submodules' '
313
git rm submod &&
314
test ! -d submod &&
315
git status -s -uno --ignore-submodules=none > actual &&
302
- test_cmp expect actual
316
+ test_cmp expect actual &&
317
+ test_must_fail git config -f .gitmodules submodule.sub.url &&
318
+ test_must_fail git config -f .gitmodules submodule.sub.path
319
'
320
321
test_expect_success 'rm removes a submodule with a trailing /' '
349
git rm -f submod &&
350
test ! -d submod &&
351
git status -s -uno --ignore-submodules=none > actual &&
352
+ test_cmp expect actual &&
353
+ test_must_fail git config -f .gitmodules submodule.sub.url &&
354
+ test_must_fail git config -f .gitmodules submodule.sub.path
355
+'
356
+
357
+test_expect_success 'rm --cached leaves work tree of populated submodules and .gitmodules alone' '
358
+ git reset --hard &&
359
+ git submodule update &&
360
+ git rm --cached submod &&
361
+ test -d submod &&
362
+ test -f submod/.git &&
363
+ git status -s -uno >actual &&
364
+ test_cmp expect.cached actual &&
365
+ git config -f .gitmodules submodule.sub.url &&
366
+ git config -f .gitmodules submodule.sub.path
367
+'
368
+
369
+test_expect_success 'rm --dry-run does not touch the submodule or .gitmodules' '
370
+ git reset --hard &&
371
+ git submodule update &&
372
+ git rm -n submod &&
373
+ test -f submod/.git &&
374
+ git diff-index --exit-code HEAD
375
+'
376
+
377
+test_expect_success 'rm does not complain when no .gitmodules file is found' '
378
+ git reset --hard &&
379
+ git submodule update &&
380
+ git rm .gitmodules &&
381
+ git rm submod >actual 2>actual.err &&
382
+ ! test -s actual.err &&
383
+ ! test -d submod &&
384
+ ! test -f submod/.git &&
385
+ git status -s -uno >actual &&
386
+ test_cmp expect.both_deleted actual
387
+'
388
+
389
+test_expect_success 'rm will error out on a modified .gitmodules file unless staged' '
390
+ git reset --hard &&
391
+ git submodule update &&
392
+ git config -f .gitmodules foo.bar true &&
393
+ test_must_fail git rm submod >actual 2>actual.err &&
394
+ test -s actual.err &&
395
+ test -d submod &&
396
+ test -f submod/.git &&
397
+ git diff-files --quiet -- submod &&
398
+ git add .gitmodules &&
399
+ git rm submod >actual 2>actual.err &&
400
+ ! test -s actual.err &&
401
+ ! test -d submod &&
402
+ ! test -f submod/.git &&
403
+ git status -s -uno >actual &&
404
+ test_cmp expect actual
405
+'
406
+
407
+test_expect_success 'rm issues a warning when section is not found in .gitmodules' '
408
+ git reset --hard &&
409
+ git submodule update &&
410
+ git config -f .gitmodules --remove-section submodule.sub &&
411
+ git add .gitmodules &&
412
+ echo "warning: Could not find section in .gitmodules where path=submod" >expect.err &&
413
+ git rm submod >actual 2>actual.err &&
414
+ test_i18ncmp expect.err actual.err &&
415
+ ! test -d submod &&
416
+ ! test -f submod/.git &&
417
+ git status -s -uno >actual &&
418
test_cmp expect actual
419
'
420
509
git rm -f submod &&
510
test ! -d submod &&
511
git status -s -uno --ignore-submodules=none > actual &&
430
- test_cmp expect actual
512
+ test_cmp expect actual &&
513
+ test_must_fail git config -f .gitmodules submodule.sub.url &&
514
+ test_must_fail git config -f .gitmodules submodule.sub.path
515
'
516
517
test_expect_success 'rm of a conflicted populated submodule with modifications fails unless forced' '
530
git rm -f submod &&
531
test ! -d submod &&
532
git status -s -uno --ignore-submodules=none > actual &&
449
- test_cmp expect actual
533
+ test_cmp expect actual &&
534
+ test_must_fail git config -f .gitmodules submodule.sub.url &&
535
+ test_must_fail git config -f .gitmodules submodule.sub.path
536
'
537
538
test_expect_success 'rm of a conflicted populated submodule with untracked files fails unless forced' '