t/helper: add test-submodule-nested-repo-config
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>
Antonio Ospite committed
Oct 25, 2018 at 18:18 UTC
2b1257e463fe97b3f657bbf30fafdea0c4847cd7
5 files changed
+67
Makefile
+1
@@ -735,6 +735,7 @@ TEST_BUILTINS_OBJS += test-sigchain.o
735
TEST_BUILTINS_OBJS += test-strcmp-offset.o
736
TEST_BUILTINS_OBJS += test-string-list.o
737
TEST_BUILTINS_OBJS += test-submodule-config.o
738
+TEST_BUILTINS_OBJS += test-submodule-nested-repo-config.o
739
TEST_BUILTINS_OBJS += test-subprocess.o
740
TEST_BUILTINS_OBJS += test-urlmatch-normalization.o
741
TEST_BUILTINS_OBJS += test-wildmatch.o
t/helper/test-submodule-nested-repo-config.c
new
+30
@@ -0,0 +1,30 @@
1
+#include "test-tool.h"
2
+#include "submodule-config.h"
3
+
4
+static void die_usage(int argc, const char **argv, const char *msg)
5
+{
6
+ fprintf(stderr, "%s\n", msg);
7
+ fprintf(stderr, "Usage: %s <submodulepath> <config name>\n", argv[0]);
8
+ exit(1);
9
+}
10
+
11
+int cmd__submodule_nested_repo_config(int argc, const char **argv)
12
+{
13
+ struct repository submodule;
14
+
15
+ if (argc < 3)
16
+ die_usage(argc, argv, "Wrong number of arguments.");
17
+
18
+ setup_git_directory();
19
+
20
+ if (repo_submodule_init(&submodule, the_repository, argv[1])) {
21
+ die_usage(argc, argv, "Submodule not found.");
22
+ }
23
+
24
+ /* Read the config of _child_ submodules. */
25
+ print_config_from_gitmodules(&submodule, argv[2]);
26
+
27
+ submodule_free(the_repository);
28
+
29
+ return 0;
30
+}
t/helper/test-tool.c
+1
@@ -40,6 +40,7 @@ static struct test_cmd cmds[] = {
40
{ "strcmp-offset", cmd__strcmp_offset },
41
{ "string-list", cmd__string_list },
42
{ "submodule-config", cmd__submodule_config },
43
+ { "submodule-nested-repo-config", cmd__submodule_nested_repo_config },
44
{ "subprocess", cmd__subprocess },
45
{ "urlmatch-normalization", cmd__urlmatch_normalization },
46
{ "wildmatch", cmd__wildmatch },
t/helper/test-tool.h
+1
@@ -36,6 +36,7 @@ int cmd__sigchain(int argc, const char **argv);
36
int cmd__strcmp_offset(int argc, const char **argv);
37
int cmd__string_list(int argc, const char **argv);
38
int cmd__submodule_config(int argc, const char **argv);
39
+int cmd__submodule_nested_repo_config(int argc, const char **argv);
40
int cmd__subprocess(int argc, const char **argv);
41
int cmd__urlmatch_normalization(int argc, const char **argv);
42
int cmd__wildmatch(int argc, const char **argv);
t/t7411-submodule-config.sh
+34
@@ -216,4 +216,38 @@ test_expect_success 'reading submodules config from the current branch when .git
216
)
217
'
218
219
+test_expect_success 'reading nested submodules config' '
220
+ (cd super &&
221
+ git init submodule/nested_submodule &&
222
+ echo "a" >submodule/nested_submodule/a &&
223
+ git -C submodule/nested_submodule add a &&
224
+ git -C submodule/nested_submodule commit -m "add a" &&
225
+ git -C submodule submodule add ./nested_submodule &&
226
+ git -C submodule add nested_submodule &&
227
+ git -C submodule commit -m "added nested_submodule" &&
228
+ git add submodule &&
229
+ git commit -m "updated submodule" &&
230
+ echo "./nested_submodule" >expect &&
231
+ test-tool submodule-nested-repo-config \
232
+ submodule submodule.nested_submodule.url >actual &&
233
+ test_cmp expect actual
234
+ )
235
+'
236
+
237
+# When this test eventually passes, before turning it into
238
+# test_expect_success, remember to replace the test_i18ngrep below with
239
+# a "test_must_be_empty warning" to be sure that the warning is actually
240
+# removed from the code.
241
+test_expect_failure 'reading nested submodules config when .gitmodules is not in the working tree' '
242
+ test_when_finished "git -C super/submodule checkout .gitmodules" &&
243
+ (cd super &&
244
+ echo "./nested_submodule" >expect &&
245
+ rm submodule/.gitmodules &&
246
+ test-tool submodule-nested-repo-config \
247
+ submodule submodule.nested_submodule.url >actual 2>warning &&
248
+ test_i18ngrep "nested submodules without %s in the working tree are not supported yet" warning &&
249
+ test_cmp expect actual
250
+ )
251
+'
252
+
253
test_done