submodule--helper: move "check-name" to a test-tool
Move the "check-name" helper to a test-tool, since a6226fd772b (submodule--helper: convert the bulk of cmd_add() to C, 2021-08-10) it has only been used by this test, not git-submodule.sh. As noted with its introduction in 0383bbb9015 (submodule-config: verify submodule names as paths, 2018-04-30) the intent of t7450-bad-git-dotfiles.sh has always been to unit test the check_submodule_name() function. 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>
Ævar Arnfjörð Bjarmason committed
Sep 1, 2022 at 01:17 UTC
85321a346b5889f5602603a300d643493901ba44
3 files changed
+47
-25
builtin/submodule--helper.c
-24
@@ -2728,29 +2728,6 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
2728
return 0;
2729
}
2730
2731
-/*
2732
- * Exit non-zero if any of the submodule names given on the command line is
2733
- * invalid. If no names are given, filter stdin to print only valid names
2734
- * (which is primarily intended for testing).
2735
- */
2736
-static int check_name(int argc, const char **argv, const char *prefix)
2737
-{
2738
- if (argc > 1) {
2739
- while (*++argv) {
2740
- if (check_submodule_name(*argv) < 0)
2741
- return 1;
2742
- }
2743
- } else {
2744
- struct strbuf buf = STRBUF_INIT;
2745
- while (strbuf_getline(&buf, stdin) != EOF) {
2746
- if (!check_submodule_name(buf.buf))
2747
- printf("%s\n", buf.buf);
2748
- }
2749
- strbuf_release(&buf);
2750
- }
2751
- return 0;
2752
-}
2753
-
2731
static int module_config(int argc, const char **argv, const char *prefix)
2732
{
2733
enum {
@@ -3305,7 +3282,6 @@ static struct cmd_struct commands[] = {
3282
{"summary", module_summary, 0},
3283
{"push-check", push_check, 0},
3284
{"absorbgitdirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
3308
- {"check-name", check_name, 0},
3285
{"config", module_config, 0},
3286
{"set-url", module_set_url, 0},
3287
{"set-branch", module_set_branch, 0},
t/helper/test-submodule.c
+46
@@ -2,8 +2,16 @@
2
#include "test-tool-utils.h"
3
#include "cache.h"
4
#include "parse-options.h"
5
+#include "submodule-config.h"
6
#include "submodule.h"
7
8
+#define TEST_TOOL_CHECK_NAME_USAGE \
9
+ "test-tool submodule check-name <name>"
10
+static const char *submodule_check_name_usage[] = {
11
+ TEST_TOOL_CHECK_NAME_USAGE,
12
+ NULL
13
+};
14
+
15
#define TEST_TOOL_IS_ACTIVE_USAGE \
16
"test-tool submodule is-active <name>"
17
static const char *submodule_is_active_usage[] = {
@@ -12,10 +20,47 @@ static const char *submodule_is_active_usage[] = {
20
};
21
22
static const char *submodule_usage[] = {
23
+ TEST_TOOL_CHECK_NAME_USAGE,
24
TEST_TOOL_IS_ACTIVE_USAGE,
25
NULL
26
};
27
28
+/*
29
+ * Exit non-zero if any of the submodule names given on the command line is
30
+ * invalid. If no names are given, filter stdin to print only valid names
31
+ * (which is primarily intended for testing).
32
+ */
33
+static int check_name(int argc, const char **argv)
34
+{
35
+ if (argc > 1) {
36
+ while (*++argv) {
37
+ if (check_submodule_name(*argv) < 0)
38
+ return 1;
39
+ }
40
+ } else {
41
+ struct strbuf buf = STRBUF_INIT;
42
+ while (strbuf_getline(&buf, stdin) != EOF) {
43
+ if (!check_submodule_name(buf.buf))
44
+ printf("%s\n", buf.buf);
45
+ }
46
+ strbuf_release(&buf);
47
+ }
48
+ return 0;
49
+}
50
+
51
+static int cmd__submodule_check_name(int argc, const char **argv)
52
+{
53
+ struct option options[] = {
54
+ OPT_END()
55
+ };
56
+ argc = parse_options(argc, argv, "test-tools", options,
57
+ submodule_check_name_usage, 0);
58
+ if (argc)
59
+ usage_with_options(submodule_check_name_usage, options);
60
+
61
+ return check_name(argc, argv);
62
+}
63
+
64
static int cmd__submodule_is_active(int argc, const char **argv)
65
{
66
struct option options[] = {
@@ -32,6 +77,7 @@ static int cmd__submodule_is_active(int argc, const char **argv)
77
}
78
79
static struct test_cmd cmds[] = {
80
+ { "check-name", cmd__submodule_check_name },
81
{ "is-active", cmd__submodule_is_active },
82
};
83
t/t7450-bad-git-dotfiles.sh
+1
-1
@@ -21,7 +21,7 @@ test_expect_success 'check names' '
21
valid/with/paths
22
EOF
23
24
- git submodule--helper check-name >actual <<-\EOF &&
24
+ test-tool submodule check-name >actual <<-\EOF &&
25
valid
26
valid/with/paths
27