1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-02 02:26:11 +02:00

Merge branch 'ab/test-env-helper'

Remove "git env--helper" and demote it to a test-tool subcommand.

* ab/test-env-helper:
  env-helper: move this built-in to "test-tool env-helper"
This commit is contained in:
Junio C Hamano 2023-01-23 13:39:51 -08:00
commit cd37c45acf
9 changed files with 50 additions and 50 deletions

1
.gitignore vendored
View File

@ -59,7 +59,6 @@
/git-difftool /git-difftool
/git-difftool--helper /git-difftool--helper
/git-describe /git-describe
/git-env--helper
/git-fast-export /git-fast-export
/git-fast-import /git-fast-import
/git-fetch /git-fetch

View File

@ -798,6 +798,7 @@ TEST_BUILTINS_OBJS += test-dump-cache-tree.o
TEST_BUILTINS_OBJS += test-dump-fsmonitor.o TEST_BUILTINS_OBJS += test-dump-fsmonitor.o
TEST_BUILTINS_OBJS += test-dump-split-index.o TEST_BUILTINS_OBJS += test-dump-split-index.o
TEST_BUILTINS_OBJS += test-dump-untracked-cache.o TEST_BUILTINS_OBJS += test-dump-untracked-cache.o
TEST_BUILTINS_OBJS += test-env-helper.o
TEST_BUILTINS_OBJS += test-example-decorate.o TEST_BUILTINS_OBJS += test-example-decorate.o
TEST_BUILTINS_OBJS += test-fast-rebase.o TEST_BUILTINS_OBJS += test-fast-rebase.o
TEST_BUILTINS_OBJS += test-fsmonitor-client.o TEST_BUILTINS_OBJS += test-fsmonitor-client.o
@ -1231,7 +1232,6 @@ BUILTIN_OBJS += builtin/diff-index.o
BUILTIN_OBJS += builtin/diff-tree.o BUILTIN_OBJS += builtin/diff-tree.o
BUILTIN_OBJS += builtin/diff.o BUILTIN_OBJS += builtin/diff.o
BUILTIN_OBJS += builtin/difftool.o BUILTIN_OBJS += builtin/difftool.o
BUILTIN_OBJS += builtin/env--helper.o
BUILTIN_OBJS += builtin/fast-export.o BUILTIN_OBJS += builtin/fast-export.o
BUILTIN_OBJS += builtin/fast-import.o BUILTIN_OBJS += builtin/fast-import.o
BUILTIN_OBJS += builtin/fetch-pack.o BUILTIN_OBJS += builtin/fetch-pack.o

1
git.c
View File

@ -507,7 +507,6 @@ static struct cmd_struct commands[] = {
{ "diff-index", cmd_diff_index, RUN_SETUP | NO_PARSEOPT }, { "diff-index", cmd_diff_index, RUN_SETUP | NO_PARSEOPT },
{ "diff-tree", cmd_diff_tree, RUN_SETUP | NO_PARSEOPT }, { "diff-tree", cmd_diff_tree, RUN_SETUP | NO_PARSEOPT },
{ "difftool", cmd_difftool, RUN_SETUP_GENTLY }, { "difftool", cmd_difftool, RUN_SETUP_GENTLY },
{ "env--helper", cmd_env__helper },
{ "fast-export", cmd_fast_export, RUN_SETUP }, { "fast-export", cmd_fast_export, RUN_SETUP },
{ "fast-import", cmd_fast_import, RUN_SETUP | NO_PARSEOPT }, { "fast-import", cmd_fast_import, RUN_SETUP | NO_PARSEOPT },
{ "fetch", cmd_fetch, RUN_SETUP }, { "fetch", cmd_fetch, RUN_SETUP },

View File

@ -1,9 +1,9 @@
#include "builtin.h" #include "test-tool.h"
#include "config.h" #include "config.h"
#include "parse-options.h" #include "parse-options.h"
static char const * const env__helper_usage[] = { static char const * const env__helper_usage[] = {
N_("git env--helper --type=[bool|ulong] <options> <env-var>"), "test-tool env-helper --type=[bool|ulong] <options> <env-var>",
NULL NULL
}; };
@ -24,12 +24,12 @@ static int option_parse_type(const struct option *opt, const char *arg,
else if (!strcmp(arg, "ulong")) else if (!strcmp(arg, "ulong"))
*cmdmode = ENV_HELPER_TYPE_ULONG; *cmdmode = ENV_HELPER_TYPE_ULONG;
else else
die(_("unrecognized --type argument, %s"), arg); die("unrecognized --type argument, %s", arg);
return 0; return 0;
} }
int cmd_env__helper(int argc, const char **argv, const char *prefix) int cmd__env_helper(int argc, const char **argv)
{ {
int exit_code = 0; int exit_code = 0;
const char *env_variable = NULL; const char *env_variable = NULL;
@ -39,17 +39,17 @@ int cmd_env__helper(int argc, const char **argv, const char *prefix)
unsigned long ret_ulong, default_ulong; unsigned long ret_ulong, default_ulong;
enum cmdmode cmdmode = 0; enum cmdmode cmdmode = 0;
struct option opts[] = { struct option opts[] = {
OPT_CALLBACK_F(0, "type", &cmdmode, N_("type"), OPT_CALLBACK_F(0, "type", &cmdmode, "type",
N_("value is given this type"), PARSE_OPT_NONEG, "value is given this type", PARSE_OPT_NONEG,
option_parse_type), option_parse_type),
OPT_STRING(0, "default", &env_default, N_("value"), OPT_STRING(0, "default", &env_default, "value",
N_("default for git_env_*(...) to fall back on")), "default for git_env_*(...) to fall back on"),
OPT_BOOL(0, "exit-code", &exit_code, OPT_BOOL(0, "exit-code", &exit_code,
N_("be quiet only use git_env_*() value as exit code")), "be quiet only use git_env_*() value as exit code"),
OPT_END(), OPT_END(),
}; };
argc = parse_options(argc, argv, prefix, opts, env__helper_usage, argc = parse_options(argc, argv, NULL, opts, env__helper_usage,
PARSE_OPT_KEEP_UNKNOWN_OPT); PARSE_OPT_KEEP_UNKNOWN_OPT);
if (env_default && !*env_default) if (env_default && !*env_default)
usage_with_options(env__helper_usage, opts); usage_with_options(env__helper_usage, opts);
@ -64,7 +64,7 @@ int cmd_env__helper(int argc, const char **argv, const char *prefix)
if (env_default) { if (env_default) {
default_int = git_parse_maybe_bool(env_default); default_int = git_parse_maybe_bool(env_default);
if (default_int == -1) { if (default_int == -1) {
error(_("option `--default' expects a boolean value with `--type=bool`, not `%s`"), error("option `--default' expects a boolean value with `--type=bool`, not `%s`",
env_default); env_default);
usage_with_options(env__helper_usage, opts); usage_with_options(env__helper_usage, opts);
} }
@ -79,7 +79,7 @@ int cmd_env__helper(int argc, const char **argv, const char *prefix)
case ENV_HELPER_TYPE_ULONG: case ENV_HELPER_TYPE_ULONG:
if (env_default) { if (env_default) {
if (!git_parse_ulong(env_default, &default_ulong)) { if (!git_parse_ulong(env_default, &default_ulong)) {
error(_("option `--default' expects an unsigned long value with `--type=ulong`, not `%s`"), error("option `--default' expects an unsigned long value with `--type=ulong`, not `%s`",
env_default); env_default);
usage_with_options(env__helper_usage, opts); usage_with_options(env__helper_usage, opts);
} }

View File

@ -28,6 +28,7 @@ static struct test_cmd cmds[] = {
{ "dump-fsmonitor", cmd__dump_fsmonitor }, { "dump-fsmonitor", cmd__dump_fsmonitor },
{ "dump-split-index", cmd__dump_split_index }, { "dump-split-index", cmd__dump_split_index },
{ "dump-untracked-cache", cmd__dump_untracked_cache }, { "dump-untracked-cache", cmd__dump_untracked_cache },
{ "env-helper", cmd__env_helper },
{ "example-decorate", cmd__example_decorate }, { "example-decorate", cmd__example_decorate },
{ "fast-rebase", cmd__fast_rebase }, { "fast-rebase", cmd__fast_rebase },
{ "fsmonitor-client", cmd__fsmonitor_client }, { "fsmonitor-client", cmd__fsmonitor_client },

View File

@ -22,6 +22,7 @@ int cmd__dump_fsmonitor(int argc, const char **argv);
int cmd__dump_split_index(int argc, const char **argv); int cmd__dump_split_index(int argc, const char **argv);
int cmd__dump_untracked_cache(int argc, const char **argv); int cmd__dump_untracked_cache(int argc, const char **argv);
int cmd__dump_reftable(int argc, const char **argv); int cmd__dump_reftable(int argc, const char **argv);
int cmd__env_helper(int argc, const char **argv);
int cmd__example_decorate(int argc, const char **argv); int cmd__example_decorate(int argc, const char **argv);
int cmd__fast_rebase(int argc, const char **argv); int cmd__fast_rebase(int argc, const char **argv);
int cmd__fsmonitor_client(int argc, const char **argv); int cmd__fsmonitor_client(int argc, const char **argv);

View File

@ -1,87 +1,87 @@
#!/bin/sh #!/bin/sh
test_description='test env--helper' test_description='test test-tool env-helper'
TEST_PASSES_SANITIZE_LEAK=true TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh . ./test-lib.sh
test_expect_success 'env--helper usage' ' test_expect_success 'test-tool env-helper usage' '
test_must_fail git env--helper && test_must_fail test-tool env-helper &&
test_must_fail git env--helper --type=bool && test_must_fail test-tool env-helper --type=bool &&
test_must_fail git env--helper --type=ulong && test_must_fail test-tool env-helper --type=ulong &&
test_must_fail git env--helper --type=bool && test_must_fail test-tool env-helper --type=bool &&
test_must_fail git env--helper --type=bool --default && test_must_fail test-tool env-helper --type=bool --default &&
test_must_fail git env--helper --type=bool --default= && test_must_fail test-tool env-helper --type=bool --default= &&
test_must_fail git env--helper --defaultxyz test_must_fail test-tool env-helper --defaultxyz
' '
test_expect_success 'env--helper bad default values' ' test_expect_success 'test-tool env-helper bad default values' '
test_must_fail git env--helper --type=bool --default=1xyz MISSING && test_must_fail test-tool env-helper --type=bool --default=1xyz MISSING &&
test_must_fail git env--helper --type=ulong --default=1xyz MISSING test_must_fail test-tool env-helper --type=ulong --default=1xyz MISSING
' '
test_expect_success 'env--helper --type=bool' ' test_expect_success 'test-tool env-helper --type=bool' '
# Test various --default bool values # Test various --default bool values
echo true >expected && echo true >expected &&
git env--helper --type=bool --default=1 MISSING >actual && test-tool env-helper --type=bool --default=1 MISSING >actual &&
test_cmp expected actual && test_cmp expected actual &&
git env--helper --type=bool --default=yes MISSING >actual && test-tool env-helper --type=bool --default=yes MISSING >actual &&
test_cmp expected actual && test_cmp expected actual &&
git env--helper --type=bool --default=true MISSING >actual && test-tool env-helper --type=bool --default=true MISSING >actual &&
test_cmp expected actual && test_cmp expected actual &&
echo false >expected && echo false >expected &&
test_must_fail git env--helper --type=bool --default=0 MISSING >actual && test_must_fail test-tool env-helper --type=bool --default=0 MISSING >actual &&
test_cmp expected actual && test_cmp expected actual &&
test_must_fail git env--helper --type=bool --default=no MISSING >actual && test_must_fail test-tool env-helper --type=bool --default=no MISSING >actual &&
test_cmp expected actual && test_cmp expected actual &&
test_must_fail git env--helper --type=bool --default=false MISSING >actual && test_must_fail test-tool env-helper --type=bool --default=false MISSING >actual &&
test_cmp expected actual && test_cmp expected actual &&
# No output with --exit-code # No output with --exit-code
git env--helper --type=bool --default=true --exit-code MISSING >actual.out 2>actual.err && test-tool env-helper --type=bool --default=true --exit-code MISSING >actual.out 2>actual.err &&
test_must_be_empty actual.out && test_must_be_empty actual.out &&
test_must_be_empty actual.err && test_must_be_empty actual.err &&
test_must_fail git env--helper --type=bool --default=false --exit-code MISSING >actual.out 2>actual.err && test_must_fail test-tool env-helper --type=bool --default=false --exit-code MISSING >actual.out 2>actual.err &&
test_must_be_empty actual.out && test_must_be_empty actual.out &&
test_must_be_empty actual.err && test_must_be_empty actual.err &&
# Existing variable # Existing variable
EXISTS=true git env--helper --type=bool --default=false --exit-code EXISTS >actual.out 2>actual.err && EXISTS=true test-tool env-helper --type=bool --default=false --exit-code EXISTS >actual.out 2>actual.err &&
test_must_be_empty actual.out && test_must_be_empty actual.out &&
test_must_be_empty actual.err && test_must_be_empty actual.err &&
test_must_fail \ test_must_fail \
env EXISTS=false \ env EXISTS=false \
git env--helper --type=bool --default=true --exit-code EXISTS >actual.out 2>actual.err && test-tool env-helper --type=bool --default=true --exit-code EXISTS >actual.out 2>actual.err &&
test_must_be_empty actual.out && test_must_be_empty actual.out &&
test_must_be_empty actual.err test_must_be_empty actual.err
' '
test_expect_success 'env--helper --type=ulong' ' test_expect_success 'test-tool env-helper --type=ulong' '
echo 1234567890 >expected && echo 1234567890 >expected &&
git env--helper --type=ulong --default=1234567890 MISSING >actual.out 2>actual.err && test-tool env-helper --type=ulong --default=1234567890 MISSING >actual.out 2>actual.err &&
test_cmp expected actual.out && test_cmp expected actual.out &&
test_must_be_empty actual.err && test_must_be_empty actual.err &&
echo 0 >expected && echo 0 >expected &&
test_must_fail git env--helper --type=ulong --default=0 MISSING >actual && test_must_fail test-tool env-helper --type=ulong --default=0 MISSING >actual &&
test_cmp expected actual && test_cmp expected actual &&
git env--helper --type=ulong --default=1234567890 --exit-code MISSING >actual.out 2>actual.err && test-tool env-helper --type=ulong --default=1234567890 --exit-code MISSING >actual.out 2>actual.err &&
test_must_be_empty actual.out && test_must_be_empty actual.out &&
test_must_be_empty actual.err && test_must_be_empty actual.err &&
EXISTS=1234567890 git env--helper --type=ulong --default=0 EXISTS --exit-code >actual.out 2>actual.err && EXISTS=1234567890 test-tool env-helper --type=ulong --default=0 EXISTS --exit-code >actual.out 2>actual.err &&
test_must_be_empty actual.out && test_must_be_empty actual.out &&
test_must_be_empty actual.err && test_must_be_empty actual.err &&
echo 1234567890 >expected && echo 1234567890 >expected &&
EXISTS=1234567890 git env--helper --type=ulong --default=0 EXISTS >actual.out 2>actual.err && EXISTS=1234567890 test-tool env-helper --type=ulong --default=0 EXISTS >actual.out 2>actual.err &&
test_cmp expected actual.out && test_cmp expected actual.out &&
test_must_be_empty actual.err test_must_be_empty actual.err
' '
test_expect_success 'env--helper reads config thanks to trace2' ' test_expect_success 'test-tool env-helper reads config thanks to trace2' '
mkdir home && mkdir home &&
git config -f home/.gitconfig include.path cycle && git config -f home/.gitconfig include.path cycle &&
git config -f home/cycle include.path .gitconfig && git config -f home/cycle include.path .gitconfig &&
@ -93,7 +93,7 @@ test_expect_success 'env--helper reads config thanks to trace2' '
test_must_fail \ test_must_fail \
env HOME="$(pwd)/home" GIT_TEST_ENV_HELPER=true \ env HOME="$(pwd)/home" GIT_TEST_ENV_HELPER=true \
git -C cycle env--helper --type=bool --default=0 --exit-code GIT_TEST_ENV_HELPER 2>err && test-tool -C cycle env-helper --type=bool --default=0 --exit-code GIT_TEST_ENV_HELPER 2>err &&
grep "exceeded maximum include depth" err grep "exceeded maximum include depth" err
' '

View File

@ -1422,7 +1422,7 @@ test_bool_env () {
BUG "test_bool_env requires two parameters (variable name and default value)" BUG "test_bool_env requires two parameters (variable name and default value)"
fi fi
git env--helper --type=bool --default="$2" --exit-code "$1" test-tool env-helper --type=bool --default="$2" --exit-code "$1"
ret=$? ret=$?
case $ret in case $ret in
0|1) # unset or valid bool value 0|1) # unset or valid bool value

View File

@ -1542,8 +1542,8 @@ then
# Normalize with test_bool_env # Normalize with test_bool_env
passes_sanitize_leak= passes_sanitize_leak=
# We need to see TEST_PASSES_SANITIZE_LEAK in "git # We need to see TEST_PASSES_SANITIZE_LEAK in "test-tool
# env--helper" (via test_bool_env) # env-helper" (via test_bool_env)
export TEST_PASSES_SANITIZE_LEAK export TEST_PASSES_SANITIZE_LEAK
if test_bool_env TEST_PASSES_SANITIZE_LEAK false if test_bool_env TEST_PASSES_SANITIZE_LEAK false
then then
@ -1682,7 +1682,7 @@ yes () {
# The GIT_TEST_FAIL_PREREQS code hooks into test_set_prereq(), and # The GIT_TEST_FAIL_PREREQS code hooks into test_set_prereq(), and
# thus needs to be set up really early, and set an internal variable # thus needs to be set up really early, and set an internal variable
# for convenience so the hot test_set_prereq() codepath doesn't need # for convenience so the hot test_set_prereq() codepath doesn't need
# to call "git env--helper" (via test_bool_env). Only do that work # to call "test-tool env-helper" (via test_bool_env). Only do that work
# if needed by seeing if GIT_TEST_FAIL_PREREQS is set at all. # if needed by seeing if GIT_TEST_FAIL_PREREQS is set at all.
GIT_TEST_FAIL_PREREQS_INTERNAL= GIT_TEST_FAIL_PREREQS_INTERNAL=
if test -n "$GIT_TEST_FAIL_PREREQS" if test -n "$GIT_TEST_FAIL_PREREQS"