]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t7411-submodule-config.sh
sha1-file: split OBJECT_INFO_FOR_PREFETCH
[thirdparty/git.git] / t / t7411-submodule-config.sh
index 0bde5850ac547c90dadd9e21341ebad80a1471e6..89690b7adb85a9dbcda4fe85c5ab672716f41de8 100755 (executable)
@@ -82,29 +82,23 @@ Submodule name: 'a' for path 'b'
 Submodule name: 'submodule' for path 'submodule'
 EOF
 
-test_expect_success 'error in one submodule config lets continue' '
+test_expect_success 'error in history of one submodule config lets continue, stderr message contains blob ref' '
+       ORIG=$(git -C super rev-parse HEAD) &&
+       test_when_finished "git -C super reset --hard $ORIG" &&
        (cd super &&
                cp .gitmodules .gitmodules.bak &&
                echo "  value = \"" >>.gitmodules &&
                git add .gitmodules &&
                mv .gitmodules.bak .gitmodules &&
                git commit -m "add error" &&
-               test-tool submodule-config \
-                       HEAD b \
-                       HEAD submodule \
-                               >actual &&
-               test_cmp expect_error actual
-       )
-'
-
-test_expect_success 'error message contains blob reference' '
-       (cd super &&
                sha1=$(git rev-parse HEAD) &&
                test-tool submodule-config \
                        HEAD b \
                        HEAD submodule \
-                               2>actual_err &&
-               test_i18ngrep "submodule-blob $sha1:.gitmodules" actual_err >/dev/null
+                               >actual \
+                               2>actual_stderr &&
+               test_cmp expect_error actual &&
+               test_i18ngrep "submodule-blob $sha1:.gitmodules" actual_stderr >/dev/null
        )
 '
 
@@ -123,6 +117,8 @@ test_expect_success 'using different treeishs works' '
 '
 
 test_expect_success 'error in history in fetchrecursesubmodule lets continue' '
+       ORIG=$(git -C super rev-parse HEAD) &&
+       test_when_finished "git -C super reset --hard $ORIG" &&
        (cd super &&
                git config -f .gitmodules \
                        submodule.submodule.fetchrecursesubmodules blabla &&
@@ -134,8 +130,123 @@ test_expect_success 'error in history in fetchrecursesubmodule lets continue' '
                        HEAD b \
                        HEAD submodule \
                                >actual &&
-               test_cmp expect_error actual  &&
-               git reset --hard HEAD^
+               test_cmp expect_error actual
+       )
+'
+
+test_expect_success 'reading submodules config from the working tree with "submodule--helper config"' '
+       (cd super &&
+               echo "../submodule" >expect &&
+               git submodule--helper config submodule.submodule.url >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'writing submodules config with "submodule--helper config"' '
+       (cd super &&
+               echo "new_url" >expect &&
+               git submodule--helper config submodule.submodule.url "new_url" &&
+               git submodule--helper config submodule.submodule.url >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'overwriting unstaged submodules config with "submodule--helper config"' '
+       test_when_finished "git -C super checkout .gitmodules" &&
+       (cd super &&
+               echo "newer_url" >expect &&
+               git submodule--helper config submodule.submodule.url "newer_url" &&
+               git submodule--helper config submodule.submodule.url >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'writeable .gitmodules when it is in the working tree' '
+       git -C super submodule--helper config --check-writeable
+'
+
+test_expect_success 'writeable .gitmodules when it is nowhere in the repository' '
+       ORIG=$(git -C super rev-parse HEAD) &&
+       test_when_finished "git -C super reset --hard $ORIG" &&
+       (cd super &&
+               git rm .gitmodules &&
+               git commit -m "remove .gitmodules from the current branch" &&
+               git submodule--helper config --check-writeable
+       )
+'
+
+test_expect_success 'non-writeable .gitmodules when it is in the index but not in the working tree' '
+       test_when_finished "git -C super checkout .gitmodules" &&
+       (cd super &&
+               rm -f .gitmodules &&
+               test_must_fail git submodule--helper config --check-writeable
+       )
+'
+
+test_expect_success 'non-writeable .gitmodules when it is in the current branch but not in the index' '
+       ORIG=$(git -C super rev-parse HEAD) &&
+       test_when_finished "git -C super reset --hard $ORIG" &&
+       (cd super &&
+               git rm .gitmodules &&
+               test_must_fail git submodule--helper config --check-writeable
+       )
+'
+
+test_expect_success 'reading submodules config from the index when .gitmodules is not in the working tree' '
+       ORIG=$(git -C super rev-parse HEAD) &&
+       test_when_finished "git -C super reset --hard $ORIG" &&
+       (cd super &&
+               git submodule--helper config submodule.submodule.url "staged_url" &&
+               git add .gitmodules &&
+               rm -f .gitmodules &&
+               echo "staged_url" >expect &&
+               git submodule--helper config submodule.submodule.url >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'reading submodules config from the current branch when .gitmodules is not in the index' '
+       ORIG=$(git -C super rev-parse HEAD) &&
+       test_when_finished "git -C super reset --hard $ORIG" &&
+       (cd super &&
+               git rm .gitmodules &&
+               echo "../submodule" >expect &&
+               git submodule--helper config submodule.submodule.url >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'reading nested submodules config' '
+       (cd super &&
+               git init submodule/nested_submodule &&
+               echo "a" >submodule/nested_submodule/a &&
+               git -C submodule/nested_submodule add a &&
+               git -C submodule/nested_submodule commit -m "add a" &&
+               git -C submodule submodule add ./nested_submodule &&
+               git -C submodule add nested_submodule &&
+               git -C submodule commit -m "added nested_submodule" &&
+               git add submodule &&
+               git commit -m "updated submodule" &&
+               echo "./nested_submodule" >expect &&
+               test-tool submodule-nested-repo-config \
+                       submodule submodule.nested_submodule.url >actual &&
+               test_cmp expect actual
+       )
+'
+
+# When this test eventually passes, before turning it into
+# test_expect_success, remember to replace the test_i18ngrep below with
+# a "test_must_be_empty warning" to be sure that the warning is actually
+# removed from the code.
+test_expect_failure 'reading nested submodules config when .gitmodules is not in the working tree' '
+       test_when_finished "git -C super/submodule checkout .gitmodules" &&
+       (cd super &&
+               echo "./nested_submodule" >expect &&
+               rm submodule/.gitmodules &&
+               test-tool submodule-nested-repo-config \
+                       submodule submodule.nested_submodule.url >actual 2>warning &&
+               test_i18ngrep "nested submodules without %s in the working tree are not supported yet" warning &&
+               test_cmp expect actual
        )
 '