git-commit-vandalism/t/helper/test-submodule-nested-repo-config.c
Antonio Ospite 2b1257e463 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>
2018-10-31 15:01:30 +09:00

31 lines
700 B
C

#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;
}