t/helper: add test-submodule-nested-repo-config
authorAntonio Ospite <ao2@ao2.it>
Thu, 25 Oct 2018 16:18:13 +0000 (18:18 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 31 Oct 2018 06:01:30 +0000 (15:01 +0900)
Add a test tool to exercise config_from_gitmodules(), in particular for
the case of nested submodules.

Add also a test to document that reading the submoudles config of nested
submodules does not work yet when the .gitmodules file is not in the
working tree but it still in the index.

This is because the git API does not always make it possible access the
object store of an arbitrary repository (see get_oid() usage in
config_from_gitmodules()).

When this git limitation gets fixed the aforementioned use case will be
supported too.

Signed-off-by: Antonio Ospite <ao2@ao2.it>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Makefile
t/helper/test-submodule-nested-repo-config.c [new file with mode: 0644]
t/helper/test-tool.c
t/helper/test-tool.h
t/t7411-submodule-config.sh
index 5a969f5830a4105d3e3e6236eaa51e19880cc873..cd67f202ba3dece0a35eb2fefa96e4f633a539ac 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -735,6 +735,7 @@ TEST_BUILTINS_OBJS += test-sigchain.o
 TEST_BUILTINS_OBJS += test-strcmp-offset.o
 TEST_BUILTINS_OBJS += test-string-list.o
 TEST_BUILTINS_OBJS += test-submodule-config.o
+TEST_BUILTINS_OBJS += test-submodule-nested-repo-config.o
 TEST_BUILTINS_OBJS += test-subprocess.o
 TEST_BUILTINS_OBJS += test-urlmatch-normalization.o
 TEST_BUILTINS_OBJS += test-wildmatch.o
diff --git a/t/helper/test-submodule-nested-repo-config.c b/t/helper/test-submodule-nested-repo-config.c
new file mode 100644 (file)
index 0000000..a31e2a9
--- /dev/null
@@ -0,0 +1,30 @@
+#include "test-tool.h"
+#include "submodule-config.h"
+
+static void die_usage(int argc, const char **argv, const char *msg)
+{
+       fprintf(stderr, "%s\n", msg);
+       fprintf(stderr, "Usage: %s <submodulepath> <config name>\n", argv[0]);
+       exit(1);
+}
+
+int cmd__submodule_nested_repo_config(int argc, const char **argv)
+{
+       struct repository submodule;
+
+       if (argc < 3)
+               die_usage(argc, argv, "Wrong number of arguments.");
+
+       setup_git_directory();
+
+       if (repo_submodule_init(&submodule, the_repository, argv[1])) {
+               die_usage(argc, argv, "Submodule not found.");
+       }
+
+       /* Read the config of _child_ submodules. */
+       print_config_from_gitmodules(&submodule, argv[2]);
+
+       submodule_free(the_repository);
+
+       return 0;
+}
index 0edafcfd65db7586bc1521d2e1afa99fbde50292..a25fa80ca2e4422330ba76d9e95650b928fa65c1 100644 (file)
@@ -40,6 +40,7 @@ static struct test_cmd cmds[] = {
        { "strcmp-offset", cmd__strcmp_offset },
        { "string-list", cmd__string_list },
        { "submodule-config", cmd__submodule_config },
+       { "submodule-nested-repo-config", cmd__submodule_nested_repo_config },
        { "subprocess", cmd__subprocess },
        { "urlmatch-normalization", cmd__urlmatch_normalization },
        { "wildmatch", cmd__wildmatch },
index e954e8c5222f77e882f577198091adde95cf2532..9462e38fb58ee478630d184e576005f61459026b 100644 (file)
@@ -36,6 +36,7 @@ int cmd__sigchain(int argc, const char **argv);
 int cmd__strcmp_offset(int argc, const char **argv);
 int cmd__string_list(int argc, const char **argv);
 int cmd__submodule_config(int argc, const char **argv);
+int cmd__submodule_nested_repo_config(int argc, const char **argv);
 int cmd__subprocess(int argc, const char **argv);
 int cmd__urlmatch_normalization(int argc, const char **argv);
 int cmd__wildmatch(int argc, const char **argv);
index 2cfabb18bc5b30896aaf81b34394d3a12f4f05d8..89690b7adb85a9dbcda4fe85c5ab672716f41de8 100755 (executable)
@@ -216,4 +216,38 @@ test_expect_success 'reading submodules config from the current branch when .git
        )
 '
 
+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
+       )
+'
+
 test_done