]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/lib-submodule-update.sh
Merge branch 'dl/test-must-fail-fixes-5'
[thirdparty/git.git] / t / lib-submodule-update.sh
old mode 100755 (executable)
new mode 100644 (file)
index 8e9f310..07c822c
@@ -297,7 +297,7 @@ test_submodule_content () {
 # - Directory containing tracked files replaced by submodule
 # - Submodule replaced by tracked files in directory
 # - Submodule replaced by tracked file with the same name
-# - tracked file replaced by submodule
+# - Tracked file replaced by submodule
 #
 # The default is that submodule contents aren't changed until "git submodule
 # update" is run. And even then that command doesn't delete the work tree of
@@ -654,11 +654,13 @@ test_submodule_forced_switch () {
 # - Directory containing tracked files replaced by submodule
 # - Submodule replaced by tracked files in directory
 # - Submodule replaced by tracked file with the same name
-# - tracked file replaced by submodule
+# - Tracked file replaced by submodule
 #
 # New test cases
 # - Removing a submodule with a git directory absorbs the submodules
 #   git directory first into the superproject.
+# - Switching from no submodule to nested submodules
+# - Switching from nested submodules to no submodule
 
 # Internal function; use test_submodule_switch_recursing_with_args() or
 # test_submodule_forced_switch_recursing_with_args() instead.
@@ -691,22 +693,6 @@ test_submodule_recursing_with_args_common () {
                        test_submodule_content sub1 origin/add_sub1
                )
        '
-       test_expect_success "$command: submodule branch is not changed, detach HEAD instead" '
-               prolog &&
-               reset_work_tree_to_interested add_sub1 &&
-               (
-                       cd submodule_update &&
-                       git -C sub1 checkout -b keep_branch &&
-                       git -C sub1 rev-parse HEAD >expect &&
-                       git branch -t modify_sub1 origin/modify_sub1 &&
-                       $command modify_sub1 &&
-                       test_superproject_content origin/modify_sub1 &&
-                       test_submodule_content sub1 origin/modify_sub1 &&
-                       git -C sub1 rev-parse keep_branch >actual &&
-                       test_cmp expect actual &&
-                       test_must_fail git -C sub1 symbolic-ref HEAD
-               )
-       '
 
        # Replacing a tracked file with a submodule produces a checked out submodule
        test_expect_success "$command: replace tracked file with submodule checks out submodule" '
@@ -732,6 +718,19 @@ test_submodule_recursing_with_args_common () {
                        test_submodule_content sub1 origin/replace_directory_with_sub1
                )
        '
+       # Switching to a commit with nested submodules recursively checks them out
+       test_expect_success "$command: nested submodules are checked out" '
+               prolog &&
+               reset_work_tree_to_interested no_submodule &&
+               (
+                       cd submodule_update &&
+                       git branch -t modify_sub1_recursively origin/modify_sub1_recursively &&
+                       $command modify_sub1_recursively &&
+                       test_superproject_content origin/modify_sub1_recursively &&
+                       test_submodule_content sub1 origin/modify_sub1_recursively &&
+                       test_submodule_content -C sub1 sub2 origin/modify_sub1_recursively
+               )
+       '
 
        ######################## Disappearing submodule #######################
        # Removing a submodule removes its work tree ...
@@ -795,6 +794,21 @@ test_submodule_recursing_with_args_common () {
                )
        '
 
+       # Switching to a commit without nested submodules removes their worktrees
+       test_expect_success "$command: worktrees of nested submodules are removed" '
+               prolog &&
+               reset_work_tree_to_interested add_nested_sub &&
+               (
+                       cd submodule_update &&
+                       git branch -t no_submodule origin/no_submodule &&
+                       $command no_submodule &&
+                       test_superproject_content origin/no_submodule &&
+                       ! test_path_is_dir sub1 &&
+                       test_must_fail git config -f .git/modules/sub1/config core.worktree &&
+                       test_must_fail git config -f .git/modules/sub1/modules/sub2/config core.worktree
+               )
+       '
+
        ########################## Modified submodule #########################
        # Updating a submodule sha1 updates the submodule's work tree
        test_expect_success "$command: modified submodule updates submodule work tree" '
@@ -822,6 +836,23 @@ test_submodule_recursing_with_args_common () {
                        test_submodule_content sub1 origin/add_sub1
                )
        '
+       # Updating a submodule does not touch the currently checked out branch in the submodule
+       test_expect_success "$command: submodule branch is not changed, detach HEAD instead" '
+               prolog &&
+               reset_work_tree_to_interested add_sub1 &&
+               (
+                       cd submodule_update &&
+                       git -C sub1 checkout -b keep_branch &&
+                       git -C sub1 rev-parse HEAD >expect &&
+                       git branch -t modify_sub1 origin/modify_sub1 &&
+                       $command modify_sub1 &&
+                       test_superproject_content origin/modify_sub1 &&
+                       test_submodule_content sub1 origin/modify_sub1 &&
+                       git -C sub1 rev-parse keep_branch >actual &&
+                       test_cmp expect actual &&
+                       test_must_fail git -C sub1 symbolic-ref HEAD
+               )
+       '
 }
 
 # Declares and invokes several tests that, in various situations, checks that
@@ -941,7 +972,6 @@ test_submodule_switch_recursing_with_args () {
                )
        '
 
-       # recursing deeper than one level doesn't work yet.
        test_expect_success "$command: modified submodule updates submodule recursively" '
                prolog &&
                reset_work_tree_to_interested add_nested_sub &&