2 #include "test-tool-utils.h"
4 #include "parse-options.h"
6 #include "submodule-config.h"
9 #define TEST_TOOL_CHECK_NAME_USAGE \
10 "test-tool submodule check-name <name>"
11 static const char *submodule_check_name_usage
[] = {
12 TEST_TOOL_CHECK_NAME_USAGE
,
16 #define TEST_TOOL_IS_ACTIVE_USAGE \
17 "test-tool submodule is-active <name>"
18 static const char *submodule_is_active_usage
[] = {
19 TEST_TOOL_IS_ACTIVE_USAGE
,
23 #define TEST_TOOL_RESOLVE_RELATIVE_URL_USAGE \
24 "test-tool submodule resolve-relative-url <up_path> <remoteurl> <url>"
25 static const char *submodule_resolve_relative_url_usage
[] = {
26 TEST_TOOL_RESOLVE_RELATIVE_URL_USAGE
,
30 static const char *submodule_usage
[] = {
31 TEST_TOOL_CHECK_NAME_USAGE
,
32 TEST_TOOL_IS_ACTIVE_USAGE
,
33 TEST_TOOL_RESOLVE_RELATIVE_URL_USAGE
,
38 * Exit non-zero if any of the submodule names given on the command line is
39 * invalid. If no names are given, filter stdin to print only valid names
40 * (which is primarily intended for testing).
42 static int check_name(int argc
, const char **argv
)
46 if (check_submodule_name(*argv
) < 0)
50 struct strbuf buf
= STRBUF_INIT
;
51 while (strbuf_getline(&buf
, stdin
) != EOF
) {
52 if (!check_submodule_name(buf
.buf
))
53 printf("%s\n", buf
.buf
);
60 static int cmd__submodule_check_name(int argc
, const char **argv
)
62 struct option options
[] = {
65 argc
= parse_options(argc
, argv
, "test-tools", options
,
66 submodule_check_name_usage
, 0);
68 usage_with_options(submodule_check_name_usage
, options
);
70 return check_name(argc
, argv
);
73 static int cmd__submodule_is_active(int argc
, const char **argv
)
75 struct option options
[] = {
78 argc
= parse_options(argc
, argv
, "test-tools", options
,
79 submodule_is_active_usage
, 0);
81 usage_with_options(submodule_is_active_usage
, options
);
83 setup_git_directory();
85 return !is_submodule_active(the_repository
, argv
[0]);
88 static int resolve_relative_url(int argc
, const char **argv
)
90 char *remoteurl
, *res
;
91 const char *up_path
, *url
;
94 remoteurl
= xstrdup(argv
[1]);
97 if (!strcmp(up_path
, "(null)"))
100 res
= relative_url(remoteurl
, url
, up_path
);
107 static int cmd__submodule_resolve_relative_url(int argc
, const char **argv
)
109 struct option options
[] = {
112 argc
= parse_options(argc
, argv
, "test-tools", options
,
113 submodule_resolve_relative_url_usage
, 0);
115 usage_with_options(submodule_resolve_relative_url_usage
, options
);
117 return resolve_relative_url(argc
, argv
);
120 static struct test_cmd cmds
[] = {
121 { "check-name", cmd__submodule_check_name
},
122 { "is-active", cmd__submodule_is_active
},
123 { "resolve-relative-url", cmd__submodule_resolve_relative_url
},
126 int cmd__submodule(int argc
, const char **argv
)
128 struct option options
[] = {
133 argc
= parse_options(argc
, argv
, "test-tools", options
, submodule_usage
,
134 PARSE_OPT_STOP_AT_NON_OPTION
);
136 usage_with_options(submodule_usage
, options
);
138 for (i
= 0; i
< ARRAY_SIZE(cmds
); i
++)
139 if (!strcmp(cmds
[i
].name
, argv
[0]))
140 return cmds
[i
].fn(argc
, argv
);
142 usage_msg_optf("unknown subcommand '%s'", submodule_usage
, options
,