mirror of
https://github.com/git/git
synced 2024-10-31 01:43:41 +00:00
9fb2a970e9
Create a new "test-tool submodule" and move the "is-active" subcommand over to it. It was added in5c2bd8b77a
(submodule--helper: add is-active subcommand, 2017-03-16), sincea452128a36
(submodule--helper: introduce add-config subcommand, 2021-08-06) it hasn't been used by git-submodule.sh. Since we're creating a command dispatch similar to test-tool.c itself let's split out the "struct test_cmd" into a new test-tool-utils.h, which both this new code and test-tool.c itself can use. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Reviewed-by: Glen Choo <chooglen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
58 lines
1.3 KiB
C
58 lines
1.3 KiB
C
#include "test-tool.h"
|
|
#include "test-tool-utils.h"
|
|
#include "cache.h"
|
|
#include "parse-options.h"
|
|
#include "submodule.h"
|
|
|
|
#define TEST_TOOL_IS_ACTIVE_USAGE \
|
|
"test-tool submodule is-active <name>"
|
|
static const char *submodule_is_active_usage[] = {
|
|
TEST_TOOL_IS_ACTIVE_USAGE,
|
|
NULL
|
|
};
|
|
|
|
static const char *submodule_usage[] = {
|
|
TEST_TOOL_IS_ACTIVE_USAGE,
|
|
NULL
|
|
};
|
|
|
|
static int cmd__submodule_is_active(int argc, const char **argv)
|
|
{
|
|
struct option options[] = {
|
|
OPT_END()
|
|
};
|
|
argc = parse_options(argc, argv, "test-tools", options,
|
|
submodule_is_active_usage, 0);
|
|
if (argc != 1)
|
|
usage_with_options(submodule_is_active_usage, options);
|
|
|
|
setup_git_directory();
|
|
|
|
return !is_submodule_active(the_repository, argv[0]);
|
|
}
|
|
|
|
static struct test_cmd cmds[] = {
|
|
{ "is-active", cmd__submodule_is_active },
|
|
};
|
|
|
|
int cmd__submodule(int argc, const char **argv)
|
|
{
|
|
struct option options[] = {
|
|
OPT_END()
|
|
};
|
|
size_t i;
|
|
|
|
argc = parse_options(argc, argv, "test-tools", options, submodule_usage,
|
|
PARSE_OPT_STOP_AT_NON_OPTION);
|
|
if (argc < 1)
|
|
usage_with_options(submodule_usage, options);
|
|
|
|
for (i = 0; i < ARRAY_SIZE(cmds); i++)
|
|
if (!strcmp(cmds[i].name, argv[0]))
|
|
return cmds[i].fn(argc, argv);
|
|
|
|
usage_msg_optf("unknown subcommand '%s'", submodule_usage, options,
|
|
argv[0]);
|
|
|
|
return 0;
|
|
}
|