Skip to content

Commit

Permalink
t/helper: add test-submodule-nested-repo-config
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ao2 authored and gitster committed Oct 31, 2018
1 parent 76e9bdc commit 2b1257e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions t/helper/test-submodule-nested-repo-config.c
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions t/helper/test-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
1 change: 1 addition & 0 deletions t/helper/test-tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
34 changes: 34 additions & 0 deletions t/t7411-submodule-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2b1257e

Please sign in to comment.