@@ -297,7 +297,7 @@ test_submodule_content () {
297297# - Directory containing tracked files replaced by submodule
298298# - Submodule replaced by tracked files in directory
299299# - Submodule replaced by tracked file with the same name
300- # - tracked file replaced by submodule
300+ # - Tracked file replaced by submodule
301301#
302302# The default is that submodule contents aren't changed until "git submodule
303303# update" is run. And even then that command doesn't delete the work tree of
@@ -621,11 +621,13 @@ test_submodule_forced_switch () {
621621# - Directory containing tracked files replaced by submodule
622622# - Submodule replaced by tracked files in directory
623623# - Submodule replaced by tracked file with the same name
624- # - tracked file replaced by submodule
624+ # - Tracked file replaced by submodule
625625#
626626# New test cases
627627# - Removing a submodule with a git directory absorbs the submodules
628628# git directory first into the superproject.
629+ # - Switching from no submodule to nested submodules
630+ # - Switching from nested submodules to no submodule
629631
630632# Internal function; use test_submodule_switch_recursing_with_args() or
631633# test_submodule_forced_switch_recursing_with_args() instead.
@@ -658,22 +660,6 @@ test_submodule_recursing_with_args_common() {
658660 test_submodule_content sub1 origin/add_sub1
659661 )
660662 '
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- '
677663
678664 # Replacing a tracked file with a submodule produces a checked out submodule
679665 test_expect_success " $command : replace tracked file with submodule checks out submodule" '
@@ -699,6 +685,19 @@ test_submodule_recursing_with_args_common() {
699685 test_submodule_content sub1 origin/replace_directory_with_sub1
700686 )
701687 '
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+ '
702701
703702 # ####################### Disappearing submodule #######################
704703 # Removing a submodule removes its work tree ...
@@ -762,6 +761,21 @@ test_submodule_recursing_with_args_common() {
762761 )
763762 '
764763
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+
765779 # ######################### Modified submodule #########################
766780 # Updating a submodule sha1 updates the submodule's work tree
767781 test_expect_success " $command : modified submodule updates submodule work tree" '
@@ -789,6 +803,23 @@ test_submodule_recursing_with_args_common() {
789803 test_submodule_content sub1 origin/add_sub1
790804 )
791805 '
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+ '
792823}
793824
794825# Declares and invokes several tests that, in various situations, checks that
@@ -908,7 +939,6 @@ test_submodule_switch_recursing_with_args () {
908939 )
909940 '
910941
911- # recursing deeper than one level doesn't work yet.
912942 test_expect_success " $command : modified submodule updates submodule recursively" '
913943 prolog &&
914944 reset_work_tree_to_interested add_nested_sub &&
0 commit comments