env-helper: move this built-in to "test-tool env-helper"

Since [1] there has been no reason for keeping "git env--helper" a built-in. The reason it was a built-in to begin with was to support the GIT_TEST_GETTEXT_POISON mode removed in that commit. I.e. unlike the rest of "test-tool" it would potentially be called by the installed git via "git-sh-i18n.sh". As none of that applies since [1] we should stop carrying this technical debt, and move it to t/helper/*. As this mostly move-only change shows this has the nice bonus that we'll stop wasting time translating the internal-only strings it emits. Even though this was a built-in, it was intentionally never documented, see its introduction in [2]. It never saw use outside of the test suite, except for the "GIT_TEST_GETTEXT_POISON" use-case noted above. 1. d162b25f956 (tests: remove support for GIT_TEST_GETTEXT_POISON, 2021-01-20) 2. b4f207f3394 (env--helper: new undocumented builtin wrapping git_env_*(), 2019-06-21) Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jan 12, 2023 at 17:03 UTC 4a1baacd4680e27226892706c7a3fd1e22504572
9 files changed +50 -50
.gitignore
-1
@@ -60,7 +60,6 @@
60 /git-difftool
61 /git-difftool--helper
62 /git-describe
63 -/git-env--helper
63 /git-fast-export
64 /git-fast-import
65 /git-fetch
Makefile
+1 -1
@@ -801,6 +801,7 @@ TEST_BUILTINS_OBJS += test-dump-cache-tree.o
801 TEST_BUILTINS_OBJS += test-dump-fsmonitor.o
802 TEST_BUILTINS_OBJS += test-dump-split-index.o
803 TEST_BUILTINS_OBJS += test-dump-untracked-cache.o
804 +TEST_BUILTINS_OBJS += test-env-helper.o
805 TEST_BUILTINS_OBJS += test-example-decorate.o
806 TEST_BUILTINS_OBJS += test-fast-rebase.o
807 TEST_BUILTINS_OBJS += test-fsmonitor-client.o
@@ -1234,7 +1235,6 @@ BUILTIN_OBJS += builtin/diff-index.o
1235 BUILTIN_OBJS += builtin/diff-tree.o
1236 BUILTIN_OBJS += builtin/diff.o
1237 BUILTIN_OBJS += builtin/difftool.o
1237 -BUILTIN_OBJS += builtin/env--helper.o
1238 BUILTIN_OBJS += builtin/fast-export.o
1239 BUILTIN_OBJS += builtin/fast-import.o
1240 BUILTIN_OBJS += builtin/fetch-pack.o
git.c
-1
@@ -528,7 +528,6 @@ static struct cmd_struct commands[] = {
528 { "diff-index", cmd_diff_index, RUN_SETUP | NO_PARSEOPT },
529 { "diff-tree", cmd_diff_tree, RUN_SETUP | NO_PARSEOPT },
530 { "difftool", cmd_difftool, RUN_SETUP_GENTLY },
531 - { "env--helper", cmd_env__helper },
531 { "fast-export", cmd_fast_export, RUN_SETUP },
532 { "fast-import", cmd_fast_import, RUN_SETUP | NO_PARSEOPT },
533 { "fetch", cmd_fetch, RUN_SETUP },
t/helper/test-env-helper.c renamed
+12 -12
@@ -1,9 +1,9 @@
1 -#include "builtin.h"
1 +#include "test-tool.h"
2 #include "config.h"
3 #include "parse-options.h"
4
5 static char const * const env__helper_usage[] = {
6 - N_("git env--helper --type=[bool|ulong] <options> <env-var>"),
6 + "test-tool env-helper --type=[bool|ulong] <options> <env-var>",
7 NULL
8 };
9
@@ -24,12 +24,12 @@ static int option_parse_type(const struct option *opt, const char *arg,
24 else if (!strcmp(arg, "ulong"))
25 *cmdmode = ENV_HELPER_TYPE_ULONG;
26 else
27 - die(_("unrecognized --type argument, %s"), arg);
27 + die("unrecognized --type argument, %s", arg);
28
29 return 0;
30 }
31
32 -int cmd_env__helper(int argc, const char **argv, const char *prefix)
32 +int cmd__env_helper(int argc, const char **argv)
33 {
34 int exit_code = 0;
35 const char *env_variable = NULL;
@@ -39,17 +39,17 @@ int cmd_env__helper(int argc, const char **argv, const char *prefix)
39 unsigned long ret_ulong, default_ulong;
40 enum cmdmode cmdmode = 0;
41 struct option opts[] = {
42 - OPT_CALLBACK_F(0, "type", &cmdmode, N_("type"),
43 - N_("value is given this type"), PARSE_OPT_NONEG,
42 + OPT_CALLBACK_F(0, "type", &cmdmode, "type",
43 + "value is given this type", PARSE_OPT_NONEG,
44 option_parse_type),
45 - OPT_STRING(0, "default", &env_default, N_("value"),
46 - N_("default for git_env_*(...) to fall back on")),
45 + OPT_STRING(0, "default", &env_default, "value",
46 + "default for git_env_*(...) to fall back on"),
47 OPT_BOOL(0, "exit-code", &exit_code,
48 - N_("be quiet only use git_env_*() value as exit code")),
48 + "be quiet only use git_env_*() value as exit code"),
49 OPT_END(),
50 };
51
52 - argc = parse_options(argc, argv, prefix, opts, env__helper_usage,
52 + argc = parse_options(argc, argv, NULL, opts, env__helper_usage,
53 PARSE_OPT_KEEP_UNKNOWN_OPT);
54 if (env_default && !*env_default)
55 usage_with_options(env__helper_usage, opts);
@@ -64,7 +64,7 @@ int cmd_env__helper(int argc, const char **argv, const char *prefix)
64 if (env_default) {
65 default_int = git_parse_maybe_bool(env_default);
66 if (default_int == -1) {
67 - error(_("option `--default' expects a boolean value with `--type=bool`, not `%s`"),
67 + error("option `--default' expects a boolean value with `--type=bool`, not `%s`",
68 env_default);
69 usage_with_options(env__helper_usage, opts);
70 }
@@ -79,7 +79,7 @@ int cmd_env__helper(int argc, const char **argv, const char *prefix)
79 case ENV_HELPER_TYPE_ULONG:
80 if (env_default) {
81 if (!git_parse_ulong(env_default, &default_ulong)) {
82 - error(_("option `--default' expects an unsigned long value with `--type=ulong`, not `%s`"),
82 + error("option `--default' expects an unsigned long value with `--type=ulong`, not `%s`",
83 env_default);
84 usage_with_options(env__helper_usage, opts);
85 }
t/helper/test-tool.c
+1
@@ -28,6 +28,7 @@ static struct test_cmd cmds[] = {
28 { "dump-fsmonitor", cmd__dump_fsmonitor },
29 { "dump-split-index", cmd__dump_split_index },
30 { "dump-untracked-cache", cmd__dump_untracked_cache },
31 + { "env-helper", cmd__env_helper },
32 { "example-decorate", cmd__example_decorate },
33 { "fast-rebase", cmd__fast_rebase },
34 { "fsmonitor-client", cmd__fsmonitor_client },
t/helper/test-tool.h
+1
@@ -22,6 +22,7 @@ int cmd__dump_fsmonitor(int argc, const char **argv);
22 int cmd__dump_split_index(int argc, const char **argv);
23 int cmd__dump_untracked_cache(int argc, const char **argv);
24 int cmd__dump_reftable(int argc, const char **argv);
25 +int cmd__env_helper(int argc, const char **argv);
26 int cmd__example_decorate(int argc, const char **argv);
27 int cmd__fast_rebase(int argc, const char **argv);
28 int cmd__fsmonitor_client(int argc, const char **argv);
t/t0017-env-helper.sh
+31 -31
@@ -1,87 +1,87 @@
1 #!/bin/sh
2
3 -test_description='test env--helper'
3 +test_description='test test-tool env-helper'
4
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8
9 -test_expect_success 'env--helper usage' '
10 - test_must_fail git env--helper &&
11 - test_must_fail git env--helper --type=bool &&
12 - test_must_fail git env--helper --type=ulong &&
13 - test_must_fail git env--helper --type=bool &&
14 - test_must_fail git env--helper --type=bool --default &&
15 - test_must_fail git env--helper --type=bool --default= &&
16 - test_must_fail git env--helper --defaultxyz
9 +test_expect_success 'test-tool env-helper usage' '
10 + test_must_fail test-tool env-helper &&
11 + test_must_fail test-tool env-helper --type=bool &&
12 + test_must_fail test-tool env-helper --type=ulong &&
13 + test_must_fail test-tool env-helper --type=bool &&
14 + test_must_fail test-tool env-helper --type=bool --default &&
15 + test_must_fail test-tool env-helper --type=bool --default= &&
16 + test_must_fail test-tool env-helper --defaultxyz
17 '
18
19 -test_expect_success 'env--helper bad default values' '
20 - test_must_fail git env--helper --type=bool --default=1xyz MISSING &&
21 - test_must_fail git env--helper --type=ulong --default=1xyz MISSING
19 +test_expect_success 'test-tool env-helper bad default values' '
20 + test_must_fail test-tool env-helper --type=bool --default=1xyz MISSING &&
21 + test_must_fail test-tool env-helper --type=ulong --default=1xyz MISSING
22 '
23
24 -test_expect_success 'env--helper --type=bool' '
24 +test_expect_success 'test-tool env-helper --type=bool' '
25 # Test various --default bool values
26 echo true >expected &&
27 - git env--helper --type=bool --default=1 MISSING >actual &&
27 + test-tool env-helper --type=bool --default=1 MISSING >actual &&
28 test_cmp expected actual &&
29 - git env--helper --type=bool --default=yes MISSING >actual &&
29 + test-tool env-helper --type=bool --default=yes MISSING >actual &&
30 test_cmp expected actual &&
31 - git env--helper --type=bool --default=true MISSING >actual &&
31 + test-tool env-helper --type=bool --default=true MISSING >actual &&
32 test_cmp expected actual &&
33 echo false >expected &&
34 - test_must_fail git env--helper --type=bool --default=0 MISSING >actual &&
34 + test_must_fail test-tool env-helper --type=bool --default=0 MISSING >actual &&
35 test_cmp expected actual &&
36 - test_must_fail git env--helper --type=bool --default=no MISSING >actual &&
36 + test_must_fail test-tool env-helper --type=bool --default=no MISSING >actual &&
37 test_cmp expected actual &&
38 - test_must_fail git env--helper --type=bool --default=false MISSING >actual &&
38 + test_must_fail test-tool env-helper --type=bool --default=false MISSING >actual &&
39 test_cmp expected actual &&
40
41 # No output with --exit-code
42 - git env--helper --type=bool --default=true --exit-code MISSING >actual.out 2>actual.err &&
42 + test-tool env-helper --type=bool --default=true --exit-code MISSING >actual.out 2>actual.err &&
43 test_must_be_empty actual.out &&
44 test_must_be_empty actual.err &&
45 - test_must_fail git env--helper --type=bool --default=false --exit-code MISSING >actual.out 2>actual.err &&
45 + test_must_fail test-tool env-helper --type=bool --default=false --exit-code MISSING >actual.out 2>actual.err &&
46 test_must_be_empty actual.out &&
47 test_must_be_empty actual.err &&
48
49 # Existing variable
50 - EXISTS=true git env--helper --type=bool --default=false --exit-code EXISTS >actual.out 2>actual.err &&
50 + EXISTS=true test-tool env-helper --type=bool --default=false --exit-code EXISTS >actual.out 2>actual.err &&
51 test_must_be_empty actual.out &&
52 test_must_be_empty actual.err &&
53 test_must_fail \
54 env EXISTS=false \
55 - git env--helper --type=bool --default=true --exit-code EXISTS >actual.out 2>actual.err &&
55 + test-tool env-helper --type=bool --default=true --exit-code EXISTS >actual.out 2>actual.err &&
56 test_must_be_empty actual.out &&
57 test_must_be_empty actual.err
58 '
59
60 -test_expect_success 'env--helper --type=ulong' '
60 +test_expect_success 'test-tool env-helper --type=ulong' '
61 echo 1234567890 >expected &&
62 - git env--helper --type=ulong --default=1234567890 MISSING >actual.out 2>actual.err &&
62 + test-tool env-helper --type=ulong --default=1234567890 MISSING >actual.out 2>actual.err &&
63 test_cmp expected actual.out &&
64 test_must_be_empty actual.err &&
65
66 echo 0 >expected &&
67 - test_must_fail git env--helper --type=ulong --default=0 MISSING >actual &&
67 + test_must_fail test-tool env-helper --type=ulong --default=0 MISSING >actual &&
68 test_cmp expected actual &&
69
70 - git env--helper --type=ulong --default=1234567890 --exit-code MISSING >actual.out 2>actual.err &&
70 + test-tool env-helper --type=ulong --default=1234567890 --exit-code MISSING >actual.out 2>actual.err &&
71 test_must_be_empty actual.out &&
72 test_must_be_empty actual.err &&
73
74 - EXISTS=1234567890 git env--helper --type=ulong --default=0 EXISTS --exit-code >actual.out 2>actual.err &&
74 + EXISTS=1234567890 test-tool env-helper --type=ulong --default=0 EXISTS --exit-code >actual.out 2>actual.err &&
75 test_must_be_empty actual.out &&
76 test_must_be_empty actual.err &&
77
78 echo 1234567890 >expected &&
79 - EXISTS=1234567890 git env--helper --type=ulong --default=0 EXISTS >actual.out 2>actual.err &&
79 + EXISTS=1234567890 test-tool env-helper --type=ulong --default=0 EXISTS >actual.out 2>actual.err &&
80 test_cmp expected actual.out &&
81 test_must_be_empty actual.err
82 '
83
84 -test_expect_success 'env--helper reads config thanks to trace2' '
84 +test_expect_success 'test-tool env-helper reads config thanks to trace2' '
85 mkdir home &&
86 git config -f home/.gitconfig include.path cycle &&
87 git config -f home/cycle include.path .gitconfig &&
@@ -93,7 +93,7 @@ test_expect_success 'env--helper reads config thanks to trace2' '
93
94 test_must_fail \
95 env HOME="$(pwd)/home" GIT_TEST_ENV_HELPER=true \
96 - git -C cycle env--helper --type=bool --default=0 --exit-code GIT_TEST_ENV_HELPER 2>err &&
96 + test-tool -C cycle env-helper --type=bool --default=0 --exit-code GIT_TEST_ENV_HELPER 2>err &&
97 grep "exceeded maximum include depth" err
98 '
99
t/test-lib-functions.sh
+1 -1
@@ -1422,7 +1422,7 @@ test_bool_env () {
1422 BUG "test_bool_env requires two parameters (variable name and default value)"
1423 fi
1424
1425 - git env--helper --type=bool --default="$2" --exit-code "$1"
1425 + test-tool env-helper --type=bool --default="$2" --exit-code "$1"
1426 ret=$?
1427 case $ret in
1428 0|1) # unset or valid bool value
t/test-lib.sh
+3 -3
@@ -1542,8 +1542,8 @@ then
1542 # Normalize with test_bool_env
1543 passes_sanitize_leak=
1544
1545 - # We need to see TEST_PASSES_SANITIZE_LEAK in "git
1546 - # env--helper" (via test_bool_env)
1545 + # We need to see TEST_PASSES_SANITIZE_LEAK in "test-tool
1546 + # env-helper" (via test_bool_env)
1547 export TEST_PASSES_SANITIZE_LEAK
1548 if test_bool_env TEST_PASSES_SANITIZE_LEAK false
1549 then
@@ -1682,7 +1682,7 @@ yes () {
1682 # The GIT_TEST_FAIL_PREREQS code hooks into test_set_prereq(), and
1683 # thus needs to be set up really early, and set an internal variable
1684 # for convenience so the hot test_set_prereq() codepath doesn't need
1685 -# to call "git env--helper" (via test_bool_env). Only do that work
1685 +# to call "test-tool env-helper" (via test_bool_env). Only do that work
1686 # if needed by seeing if GIT_TEST_FAIL_PREREQS is set at all.
1687 GIT_TEST_FAIL_PREREQS_INTERNAL=
1688 if test -n "$GIT_TEST_FAIL_PREREQS"