From 9152904c1162afaf9ce0305d1988d1450dc80da7 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 29 Apr 2021 14:55:29 +0200 Subject: git.txt: fix synopsis of `--config-env` missing the equals sign MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When executing `git -h`, then the `--config-env` documentation rightly lists the option as requiring an equals between the option and its argument: this is the only currently supported format. But the git(1) manpage incorrectly lists the option as taking a space in between. Fix the issue by adding the missing space. Reported-by: Ævar Arnfjörð Bjarmason Signed-of-by: Patrick Steinhardt Reviewed-by: Jeff King Signed-off-by: Junio C Hamano --- Documentation/git.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/git.txt b/Documentation/git.txt index 3b0f87a71b..4ac36a4742 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -13,7 +13,7 @@ SYNOPSIS [--exec-path[=]] [--html-path] [--man-path] [--info-path] [-p|--paginate|-P|--no-pager] [--no-replace-objects] [--bare] [--git-dir=] [--work-tree=] [--namespace=] - [--super-prefix=] [--config-env =] + [--super-prefix=] [--config-env==] [] DESCRIPTION -- cgit v1.2.3 From c331551ccf9a4c8922ff5d2987eed9e218479000 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 29 Apr 2021 14:55:34 +0200 Subject: git: support separate arg for `--config-env`'s value While not documented as such, many of the top-level options like `--git-dir` and `--work-tree` support two syntaxes: they accept both an equals sign between option and its value, and they do support option and value as two separate arguments. The recently added `--config-env` option only supports the syntax with an equals sign. Mitigate this inconsistency by accepting both syntaxes and add tests to verify both work. Signed-off-by: Patrick Steinhardt Reviewed-by: Jeff King Signed-off-by: Junio C Hamano --- git.c | 8 ++++++++ t/t1300-config.sh | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/git.c b/git.c index 2f548821d6..dd8c6ca51a 100644 --- a/git.c +++ b/git.c @@ -255,6 +255,14 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) git_config_push_parameter((*argv)[1]); (*argv)++; (*argc)--; + } else if (!strcmp(cmd, "--config-env")) { + if (*argc < 2) { + fprintf(stderr, _("no config key given for --config-env\n" )); + usage(git_usage_string); + } + git_config_push_env((*argv)[1]); + (*argv)++; + (*argc)--; } else if (skip_prefix(cmd, "--config-env=", &cmd)) { git_config_push_env(cmd); } else if (!strcmp(cmd, "--literal-pathspecs")) { diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 51a0621027..ca3fec8cfa 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -1372,16 +1372,29 @@ test_expect_success 'git --config-env=key=envvar support' ' cat >expect <<-\EOF && value value + value + value + false false EOF { ENVVAR=value git --config-env=core.name=ENVVAR config core.name && + ENVVAR=value git --config-env core.name=ENVVAR config core.name && ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config foo.camelcase && - ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag + ENVVAR=value git --config-env foo.CamelCase=ENVVAR config foo.camelcase && + ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag && + ENVVAR= git --config-env foo.flag=ENVVAR config --bool foo.flag } >actual && test_cmp expect actual ' +test_expect_success 'git --config-env with missing value' ' + test_must_fail env ENVVAR=value git --config-env 2>error && + grep "no config key given for --config-env" error && + test_must_fail env ENVVAR=value git --config-env config core.name 2>error && + grep "invalid config format: config" error +' + test_expect_success 'git --config-env fails with invalid parameters' ' test_must_fail git --config-env=foo.flag config --bool foo.flag 2>error && test_i18ngrep "invalid config format: foo.flag" error && -- cgit v1.2.3