Skip to content

Commit 2b1257e

Browse files
ao2gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 76e9bdc commit 2b1257e

File tree

5 files changed

+67
-0
lines changed

5 files changed

+67
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,7 @@ TEST_BUILTINS_OBJS += test-sigchain.o
735735
TEST_BUILTINS_OBJS += test-strcmp-offset.o
736736
TEST_BUILTINS_OBJS += test-string-list.o
737737
TEST_BUILTINS_OBJS += test-submodule-config.o
738+
TEST_BUILTINS_OBJS += test-submodule-nested-repo-config.o
738739
TEST_BUILTINS_OBJS += test-subprocess.o
739740
TEST_BUILTINS_OBJS += test-urlmatch-normalization.o
740741
TEST_BUILTINS_OBJS += test-wildmatch.o
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ static struct test_cmd cmds[] = {
4040
{ "strcmp-offset", cmd__strcmp_offset },
4141
{ "string-list", cmd__string_list },
4242
{ "submodule-config", cmd__submodule_config },
43+
{ "submodule-nested-repo-config", cmd__submodule_nested_repo_config },
4344
{ "subprocess", cmd__subprocess },
4445
{ "urlmatch-normalization", cmd__urlmatch_normalization },
4546
{ "wildmatch", cmd__wildmatch },

t/helper/test-tool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ int cmd__sigchain(int argc, const char **argv);
3636
int cmd__strcmp_offset(int argc, const char **argv);
3737
int cmd__string_list(int argc, const char **argv);
3838
int cmd__submodule_config(int argc, const char **argv);
39+
int cmd__submodule_nested_repo_config(int argc, const char **argv);
3940
int cmd__subprocess(int argc, const char **argv);
4041
int cmd__urlmatch_normalization(int argc, const char **argv);
4142
int cmd__wildmatch(int argc, const char **argv);

t/t7411-submodule-config.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,38 @@ test_expect_success 'reading submodules config from the current branch when .git
216216
)
217217
'
218218

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+
219253
test_done

0 commit comments

Comments
 (0)