submodule--helper: move "config" to a test-tool

As with other moves to "test-tool" in f322e9f51b (Merge branch
'ab/submodule-helper-prep', 2022-09-13) the "config" sub-command was
only used by our own tests.

It was last used by "git submodule" itself in code that went away with
a6226fd772 (submodule--helper: convert the bulk of cmd_add() to C,
2021-08-10).

Let's move it over, and while doing so make it easier to reason about
by splitting up the various uses for it into separate sub-commands, so
that we don't need to count arguments to see what it does.

This also has the advantage that we stop wasting future translator
time on this command, currently the usage information for this
internal-only tool has been translated into several languages. The use
of the "_" function has also been removed from the "please make
sure..." message.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
This commit is contained in:
Ævar Arnfjörð Bjarmason
2022-11-08 15:10:32 +01:00
committed by Taylor Blau
parent c03801e19c
commit cc74a4ac72
4 changed files with 104 additions and 66 deletions

View File

@ -111,10 +111,94 @@ static int cmd__submodule_resolve_relative_url(int argc, const char **argv)
return 0;
}
static int cmd__submodule_config_list(int argc, const char **argv)
{
struct option options[] = {
OPT_END()
};
const char *const usage[] = {
"test-tool submodule config-list <key>",
NULL
};
argc = parse_options(argc, argv, "test-tools", options, usage,
PARSE_OPT_KEEP_ARGV0);
setup_git_directory();
if (argc == 2)
return print_config_from_gitmodules(the_repository, argv[1]);
usage_with_options(usage, options);
}
static int cmd__submodule_config_set(int argc, const char **argv)
{
struct option options[] = {
OPT_END()
};
const char *const usage[] = {
"test-tool submodule config-set <key> <value>",
NULL
};
argc = parse_options(argc, argv, "test-tools", options, usage,
PARSE_OPT_KEEP_ARGV0);
setup_git_directory();
/* Equivalent to ACTION_SET in builtin/config.c */
if (argc == 3) {
if (!is_writing_gitmodules_ok())
die("please make sure that the .gitmodules file is in the working tree");
return config_set_in_gitmodules_file_gently(argv[1], argv[2]);
}
usage_with_options(usage, options);
}
static int cmd__submodule_config_unset(int argc, const char **argv)
{
struct option options[] = {
OPT_END()
};
const char *const usage[] = {
"test-tool submodule config-unset <key>",
NULL
};
setup_git_directory();
if (argc == 2) {
if (!is_writing_gitmodules_ok())
die("please make sure that the .gitmodules file is in the working tree");
return config_set_in_gitmodules_file_gently(argv[1], NULL);
}
usage_with_options(usage, options);
}
static int cmd__submodule_config_writeable(int argc, const char **argv)
{
struct option options[] = {
OPT_END()
};
const char *const usage[] = {
"test-tool submodule config-writeable",
NULL
};
setup_git_directory();
if (argc == 1)
return is_writing_gitmodules_ok() ? 0 : -1;
usage_with_options(usage, options);
}
static struct test_cmd cmds[] = {
{ "check-name", cmd__submodule_check_name },
{ "is-active", cmd__submodule_is_active },
{ "resolve-relative-url", cmd__submodule_resolve_relative_url},
{ "config-list", cmd__submodule_config_list },
{ "config-set", cmd__submodule_config_set },
{ "config-unset", cmd__submodule_config_unset },
{ "config-writeable", cmd__submodule_config_writeable },
};
int cmd__submodule(int argc, const char **argv)