262
! test -d dir
263
'
264
265
+cat >expect <<EOF
266
+D submod
267
+EOF
268
+
269
+cat >expect.modified <<EOF
270
+ M submod
271
+EOF
272
+
273
+test_expect_success 'rm removes empty submodules from work tree' '
274
+ mkdir submod &&
275
+ git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) submod &&
276
+ git config -f .gitmodules submodule.sub.url ./. &&
277
+ git config -f .gitmodules submodule.sub.path submod &&
278
+ git submodule init &&
279
+ git add .gitmodules &&
280
+ git commit -m "add submodule" &&
281
+ git rm submod &&
282
+ test ! -e submod &&
283
+ git status -s -uno --ignore-submodules=none > actual &&
284
+ test_cmp expect actual
285
+'
286
+
287
+test_expect_success 'rm removes removed submodule from index' '
288
+ git reset --hard &&
289
+ git submodule update &&
290
+ rm -rf submod &&
291
+ git rm submod &&
292
+ git status -s -uno --ignore-submodules=none > actual &&
293
+ test_cmp expect actual
294
+'
295
+
296
+test_expect_success 'rm removes work tree of unmodified submodules' '
297
+ git reset --hard &&
298
+ git submodule update &&
299
+ git rm submod &&
300
+ test ! -d submod &&
301
+ git status -s -uno --ignore-submodules=none > actual &&
302
+ test_cmp expect actual
303
+'
304
+
305
+test_expect_success 'rm of a populated submodule with different HEAD fails unless forced' '
306
+ git reset --hard &&
307
+ git submodule update &&
308
+ (cd submod &&
309
+ git checkout HEAD^
310
+ ) &&
311
+ test_must_fail git rm submod &&
312
+ test -d submod &&
313
+ test -f submod/.git &&
314
+ git status -s -uno --ignore-submodules=none > actual &&
315
+ test_cmp expect.modified actual &&
316
+ git rm -f submod &&
317
+ test ! -d submod &&
318
+ git status -s -uno --ignore-submodules=none > actual &&
319
+ test_cmp expect actual
320
+'
321
+
322
+test_expect_success 'rm of a populated submodule with modifications fails unless forced' '
323
+ git reset --hard &&
324
+ git submodule update &&
325
+ (cd submod &&
326
+ echo X >empty
327
+ ) &&
328
+ test_must_fail git rm submod &&
329
+ test -d submod &&
330
+ test -f submod/.git &&
331
+ git status -s -uno --ignore-submodules=none > actual &&
332
+ test_cmp expect.modified actual &&
333
+ git rm -f submod &&
334
+ test ! -d submod &&
335
+ git status -s -uno --ignore-submodules=none > actual &&
336
+ test_cmp expect actual
337
+'
338
+
339
+test_expect_success 'rm of a populated submodule with untracked files fails unless forced' '
340
+ git reset --hard &&
341
+ git submodule update &&
342
+ (cd submod &&
343
+ echo X >untracked
344
+ ) &&
345
+ test_must_fail git rm submod &&
346
+ test -d submod &&
347
+ test -f submod/.git &&
348
+ git status -s -uno --ignore-submodules=none > actual &&
349
+ test_cmp expect.modified actual &&
350
+ git rm -f submod &&
351
+ test ! -d submod &&
352
+ git status -s -uno --ignore-submodules=none > actual &&
353
+ test_cmp expect actual
354
+'
355
+
356
+test_expect_success 'setup submodule conflict' '
357
+ git reset --hard &&
358
+ git submodule update &&
359
+ git checkout -b branch1 &&
360
+ echo 1 >nitfol &&
361
+ git add nitfol &&
362
+ git commit -m "added nitfol 1" &&
363
+ git checkout -b branch2 master &&
364
+ echo 2 >nitfol &&
365
+ git add nitfol &&
366
+ git commit -m "added nitfol 2" &&
367
+ git checkout -b conflict1 master &&
368
+ (cd submod &&
369
+ git fetch &&
370
+ git checkout branch1
371
+ ) &&
372
+ git add submod &&
373
+ git commit -m "submod 1" &&
374
+ git checkout -b conflict2 master &&
375
+ (cd submod &&
376
+ git checkout branch2
377
+ ) &&
378
+ git add submod &&
379
+ git commit -m "submod 2"
380
+'
381
+
382
+cat >expect.conflict <<EOF
383
+UU submod
384
+EOF
385
+
386
+test_expect_success 'rm removes work tree of unmodified conflicted submodule' '
387
+ git checkout conflict1 &&
388
+ git reset --hard &&
389
+ git submodule update &&
390
+ test_must_fail git merge conflict2 &&
391
+ git rm submod &&
392
+ test ! -d submod &&
393
+ git status -s -uno --ignore-submodules=none > actual &&
394
+ test_cmp expect actual
395
+'
396
+
397
+test_expect_success 'rm of a conflicted populated submodule with different HEAD fails unless forced' '
398
+ git checkout conflict1 &&
399
+ git reset --hard &&
400
+ git submodule update &&
401
+ (cd submod &&
402
+ git checkout HEAD^
403
+ ) &&
404
+ test_must_fail git merge conflict2 &&
405
+ test_must_fail git rm submod &&
406
+ test -d submod &&
407
+ test -f submod/.git &&
408
+ git status -s -uno --ignore-submodules=none > actual &&
409
+ test_cmp expect.conflict actual &&
410
+ git rm -f submod &&
411
+ test ! -d submod &&
412
+ git status -s -uno --ignore-submodules=none > actual &&
413
+ test_cmp expect actual
414
+'
415
+
416
+test_expect_success 'rm of a conflicted populated submodule with modifications fails unless forced' '
417
+ git checkout conflict1 &&
418
+ git reset --hard &&
419
+ git submodule update &&
420
+ (cd submod &&
421
+ echo X >empty
422
+ ) &&
423
+ test_must_fail git merge conflict2 &&
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.conflict 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 conflicted populated submodule with untracked files fails unless forced' '
436
+ git checkout conflict1 &&
437
+ git reset --hard &&
438
+ git submodule update &&
439
+ (cd submod &&
440
+ echo X >untracked
441
+ ) &&
442
+ test_must_fail git merge conflict2 &&
443
+ test_must_fail git rm submod &&
444
+ test -d submod &&
445
+ test -f submod/.git &&
446
+ git status -s -uno --ignore-submodules=none > actual &&
447
+ test_cmp expect.conflict actual &&
448
+ git rm -f submod &&
449
+ test ! -d submod &&
450
+ git status -s -uno --ignore-submodules=none > actual &&
451
+ test_cmp expect actual
452
+'
453
+
454
+test_expect_success 'rm of a conflicted populated submodule with a .git directory fails even when forced' '
455
+ git checkout conflict1 &&
456
+ git reset --hard &&
457
+ git submodule update &&
458
+ (cd submod &&
459
+ rm .git &&
460
+ cp -a ../.git/modules/sub .git &&
461
+ GIT_WORK_TREE=. git config --unset core.worktree
462
+ ) &&
463
+ test_must_fail git merge conflict2 &&
464
+ test_must_fail git rm submod &&
465
+ test -d submod &&
466
+ test -d submod/.git &&
467
+ git status -s -uno --ignore-submodules=none > actual &&
468
+ test_cmp expect.conflict actual &&
469
+ test_must_fail git rm -f submod &&
470
+ test -d submod &&
471
+ test -d submod/.git &&
472
+ git status -s -uno --ignore-submodules=none > actual &&
473
+ test_cmp expect.conflict actual &&
474
+ git merge --abort &&
475
+ rm -rf submod
476
+'
477
+
478
+test_expect_success 'rm of a conflicted unpopulated submodule succeeds' '
479
+ git checkout conflict1 &&
480
+ git reset --hard &&
481
+ test_must_fail git merge conflict2 &&
482
+ git rm submod &&
483
+ test ! -d submod &&
484
+ git status -s -uno --ignore-submodules=none > actual &&
485
+ test_cmp expect actual
486
+'
487
+
488
+test_expect_success 'rm of a populated submodule with a .git directory fails even when forced' '
489
+ git checkout -f master &&
490
+ git reset --hard &&
491
+ git submodule update &&
492
+ (cd submod &&
493
+ rm .git &&
494
+ cp -a ../.git/modules/sub .git &&
495
+ GIT_WORK_TREE=. git config --unset core.worktree
496
+ ) &&
497
+ test_must_fail git rm submod &&
498
+ test -d submod &&
499
+ test -d submod/.git &&
500
+ git status -s -uno --ignore-submodules=none > actual &&
501
+ ! test -s actual &&
502
+ test_must_fail git rm -f submod &&
503
+ test -d submod &&
504
+ test -d submod/.git &&
505
+ git status -s -uno --ignore-submodules=none > actual &&
506
+ ! test -s actual &&
507
+ rm -rf submod
508
+'
509
+
510
+cat >expect.deepmodified <<EOF
511
+ M submod/subsubmod
512
+EOF
513
+
514
+test_expect_success 'setup subsubmodule' '
515
+ git reset --hard &&
516
+ git submodule update &&
517
+ (cd submod &&
518
+ git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) subsubmod &&
519
+ git config -f .gitmodules submodule.sub.url ../. &&
520
+ git config -f .gitmodules submodule.sub.path subsubmod &&
521
+ git submodule init &&
522
+ git add .gitmodules &&
523
+ git commit -m "add subsubmodule" &&
524
+ git submodule update subsubmod
525
+ ) &&
526
+ git commit -a -m "added deep submodule"
527
+'
528
+
529
+test_expect_success 'rm recursively removes work tree of unmodified submodules' '
530
+ git rm submod &&
531
+ test ! -d submod &&
532
+ git status -s -uno --ignore-submodules=none > actual &&
533
+ test_cmp expect actual
534
+'
535
+
536
+test_expect_success 'rm of a populated nested submodule with different nested HEAD fails unless forced' '
537
+ git reset --hard &&
538
+ git submodule update --recursive &&
539
+ (cd submod/subsubmod &&
540
+ git checkout HEAD^
541
+ ) &&
542
+ test_must_fail git rm submod &&
543
+ test -d submod &&
544
+ test -f submod/.git &&
545
+ git status -s -uno --ignore-submodules=none > actual &&
546
+ test_cmp expect.modified actual &&
547
+ git rm -f submod &&
548
+ test ! -d submod &&
549
+ git status -s -uno --ignore-submodules=none > actual &&
550
+ test_cmp expect actual
551
+'
552
+
553
+test_expect_success 'rm of a populated nested submodule with nested modifications fails unless forced' '
554
+ git reset --hard &&
555
+ git submodule update --recursive &&
556
+ (cd submod/subsubmod &&
557
+ echo X >empty
558
+ ) &&
559
+ test_must_fail git rm submod &&
560
+ test -d submod &&
561
+ test -f submod/.git &&
562
+ git status -s -uno --ignore-submodules=none > actual &&
563
+ test_cmp expect.modified actual &&
564
+ git rm -f submod &&
565
+ test ! -d submod &&
566
+ git status -s -uno --ignore-submodules=none > actual &&
567
+ test_cmp expect actual
568
+'
569
+
570
+test_expect_success 'rm of a populated nested submodule with nested untracked files fails unless forced' '
571
+ git reset --hard &&
572
+ git submodule update --recursive &&
573
+ (cd submod/subsubmod &&
574
+ echo X >untracked
575
+ ) &&
576
+ test_must_fail git rm submod &&
577
+ test -d submod &&
578
+ test -f submod/.git &&
579
+ git status -s -uno --ignore-submodules=none > actual &&
580
+ test_cmp expect.modified actual &&
581
+ git rm -f submod &&
582
+ test ! -d submod &&
583
+ git status -s -uno --ignore-submodules=none > actual &&
584
+ test_cmp expect actual
585
+'
586
+
587
+test_expect_success 'rm of a populated nested submodule with a nested .git directory fails even when forced' '
588
+ git reset --hard &&
589
+ git submodule update --recursive &&
590
+ (cd submod/subsubmod &&
591
+ rm .git &&
592
+ cp -a ../../.git/modules/sub/modules/sub .git &&
593
+ GIT_WORK_TREE=. git config --unset core.worktree
594
+ ) &&
595
+ test_must_fail git rm submod &&
596
+ test -d submod &&
597
+ test -d submod/subsubmod/.git &&
598
+ git status -s -uno --ignore-submodules=none > actual &&
599
+ ! test -s actual &&
600
+ test_must_fail git rm -f submod &&
601
+ test -d submod &&
602
+ test -d submod/subsubmod/.git &&
603
+ git status -s -uno --ignore-submodules=none > actual &&
604
+ ! test -s actual &&
605
+ rm -rf submod
606
+'
607
+
608
test_done