From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Jeff King" <peff@peff.net>
Subject: [PATCH v2 2/2] git: support separate arg for `--config-env`'s value
Date: Thu, 29 Apr 2021 14:55:34 +0200 [thread overview]
Message-ID: <5264fb6fa7e05b55ab48d02265d8611536dc93f1.1619700731.git.ps@pks.im> (raw)
In-Reply-To: <cover.1619700731.git.ps@pks.im>
[-- Attachment #1: Type: text/plain, Size: 2675 bytes --]
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 <ps@pks.im>
---
git.c | 8 ++++++++
t/t1300-config.sh | 15 ++++++++++++++-
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/git.c b/git.c
index b53e665671..ad365c05c7 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 e0dd5d65ce..ad4e6d0cfc 100755
--- a/t/t1300-config.sh
+++ b/t/t1300-config.sh
@@ -1374,16 +1374,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 &&
--
2.31.1
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2021-04-29 12:53 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-19 15:56 [PATCH 0/2] git: support separate arg for `--config-env`'s value Patrick Steinhardt
2021-04-19 15:56 ` [PATCH 1/2] git.txt: fix synopsis of `--config-env` missing the equals sign Patrick Steinhardt
2021-04-19 15:56 ` [PATCH 2/2] git: support separate arg for `--config-env`'s value Patrick Steinhardt
2021-04-20 10:52 ` Ævar Arnfjörð Bjarmason
2021-04-23 10:07 ` Jeff King
2021-04-20 11:24 ` Ævar Arnfjörð Bjarmason
2021-04-29 12:55 ` [PATCH v2 0/2] " Patrick Steinhardt
2021-04-29 12:55 ` [PATCH v2 1/2] git.txt: fix synopsis of `--config-env` missing the equals sign Patrick Steinhardt
2021-04-29 12:55 ` Patrick Steinhardt [this message]
2021-04-29 20:04 ` [PATCH v2 0/2] git: support separate arg for `--config-env`'s value Jeff King
2021-04-30 0:47 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5264fb6fa7e05b55ab48d02265d8611536dc93f1.1619700731.git.ps@pks.im \
--to=ps@pks.im \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).