@@ -297,7 +297,7 @@ test_submodule_content () {
297
297
# - Directory containing tracked files replaced by submodule
298
298
# - Submodule replaced by tracked files in directory
299
299
# - Submodule replaced by tracked file with the same name
300
- # - tracked file replaced by submodule
300
+ # - Tracked file replaced by submodule
301
301
#
302
302
# The default is that submodule contents aren't changed until "git submodule
303
303
# update" is run. And even then that command doesn't delete the work tree of
@@ -621,11 +621,13 @@ test_submodule_forced_switch () {
621
621
# - Directory containing tracked files replaced by submodule
622
622
# - Submodule replaced by tracked files in directory
623
623
# - Submodule replaced by tracked file with the same name
624
- # - tracked file replaced by submodule
624
+ # - Tracked file replaced by submodule
625
625
#
626
626
# New test cases
627
627
# - Removing a submodule with a git directory absorbs the submodules
628
628
# git directory first into the superproject.
629
+ # - Switching from no submodule to nested submodules
630
+ # - Switching from nested submodules to no submodule
629
631
630
632
# Internal function; use test_submodule_switch_recursing_with_args() or
631
633
# test_submodule_forced_switch_recursing_with_args() instead.
@@ -658,22 +660,6 @@ test_submodule_recursing_with_args_common() {
658
660
test_submodule_content sub1 origin/add_sub1
659
661
)
660
662
'
661
- test_expect_success " $command : submodule branch is not changed, detach HEAD instead" '
662
- prolog &&
663
- reset_work_tree_to_interested add_sub1 &&
664
- (
665
- cd submodule_update &&
666
- git -C sub1 checkout -b keep_branch &&
667
- git -C sub1 rev-parse HEAD >expect &&
668
- git branch -t modify_sub1 origin/modify_sub1 &&
669
- $command modify_sub1 &&
670
- test_superproject_content origin/modify_sub1 &&
671
- test_submodule_content sub1 origin/modify_sub1 &&
672
- git -C sub1 rev-parse keep_branch >actual &&
673
- test_cmp expect actual &&
674
- test_must_fail git -C sub1 symbolic-ref HEAD
675
- )
676
- '
677
663
678
664
# Replacing a tracked file with a submodule produces a checked out submodule
679
665
test_expect_success " $command : replace tracked file with submodule checks out submodule" '
@@ -699,6 +685,19 @@ test_submodule_recursing_with_args_common() {
699
685
test_submodule_content sub1 origin/replace_directory_with_sub1
700
686
)
701
687
'
688
+ # Switching to a commit with nested submodules recursively checks them out
689
+ test_expect_success " $command : nested submodules are checked out" '
690
+ prolog &&
691
+ reset_work_tree_to_interested no_submodule &&
692
+ (
693
+ cd submodule_update &&
694
+ git branch -t modify_sub1_recursively origin/modify_sub1_recursively &&
695
+ $command modify_sub1_recursively &&
696
+ test_superproject_content origin/modify_sub1_recursively &&
697
+ test_submodule_content sub1 origin/modify_sub1_recursively &&
698
+ test_submodule_content -C sub1 sub2 origin/modify_sub1_recursively
699
+ )
700
+ '
702
701
703
702
# ####################### Disappearing submodule #######################
704
703
# Removing a submodule removes its work tree ...
@@ -762,6 +761,21 @@ test_submodule_recursing_with_args_common() {
762
761
)
763
762
'
764
763
764
+ # Switching to a commit without nested submodules removes their worktrees
765
+ test_expect_success " $command : worktrees of nested submodules are removed" '
766
+ prolog &&
767
+ reset_work_tree_to_interested add_nested_sub &&
768
+ (
769
+ cd submodule_update &&
770
+ git branch -t no_submodule origin/no_submodule &&
771
+ $command no_submodule &&
772
+ test_superproject_content origin/no_submodule &&
773
+ ! test_path_is_dir sub1 &&
774
+ test_must_fail git config -f .git/modules/sub1/config core.worktree &&
775
+ test_must_fail git config -f .git/modules/sub1/modules/sub2/config core.worktree
776
+ )
777
+ '
778
+
765
779
# ######################### Modified submodule #########################
766
780
# Updating a submodule sha1 updates the submodule's work tree
767
781
test_expect_success " $command : modified submodule updates submodule work tree" '
@@ -789,6 +803,23 @@ test_submodule_recursing_with_args_common() {
789
803
test_submodule_content sub1 origin/add_sub1
790
804
)
791
805
'
806
+ # Updating a submodule does not touch the currently checked out branch in the submodule
807
+ test_expect_success " $command : submodule branch is not changed, detach HEAD instead" '
808
+ prolog &&
809
+ reset_work_tree_to_interested add_sub1 &&
810
+ (
811
+ cd submodule_update &&
812
+ git -C sub1 checkout -b keep_branch &&
813
+ git -C sub1 rev-parse HEAD >expect &&
814
+ git branch -t modify_sub1 origin/modify_sub1 &&
815
+ $command modify_sub1 &&
816
+ test_superproject_content origin/modify_sub1 &&
817
+ test_submodule_content sub1 origin/modify_sub1 &&
818
+ git -C sub1 rev-parse keep_branch >actual &&
819
+ test_cmp expect actual &&
820
+ test_must_fail git -C sub1 symbolic-ref HEAD
821
+ )
822
+ '
792
823
}
793
824
794
825
# Declares and invokes several tests that, in various situations, checks that
@@ -908,7 +939,6 @@ test_submodule_switch_recursing_with_args () {
908
939
)
909
940
'
910
941
911
- # recursing deeper than one level doesn't work yet.
912
942
test_expect_success " $command : modified submodule updates submodule recursively" '
913
943
prolog &&
914
944
reset_work_tree_to_interested add_nested_sub &&
0 commit comments