git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/2] git: support separate arg for `--config-env`'s value

From
Patrick Steinhardt <ps@pks.im>
Date
Apr 29, 2021, 12:55 UTC
Message-ID
<5264fb6fa7e05b55ab48d02265d8611536dc93f1.1619700731.git.ps@pks.im>
In-Reply-To
<cover.1619700731.git.ps@pks.im>

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
Previous: Patrick SteinhardtNext: Jeff King
Message 9 of 11 in “git: support separate arg for `--config-env`'s value”
  1. 0/2 git: support separate arg for `--config-env`'s valuePatrick Steinhardt, Apr 19, 2021
  2. 1/2 git.txt: fix synopsis of `--config-env` missing the equals signPatrick Steinhardt, Apr 19, 2021
  3. 2/2 git: support separate arg for `--config-env`'s valuePatrick Steinhardt, Apr 19, 2021
  4. Ævar Arnfjörð BjarmasonApr 20, 2021
  5. Jeff KingApr 23, 2021
  6. Ævar Arnfjörð BjarmasonApr 20, 2021
  7. 0/2 git: support separate arg for `--config-env`'s valuePatrick Steinhardt, Apr 29, 2021
  8. 1/2 git.txt: fix synopsis of `--config-env` missing the equals signPatrick Steinhardt, Apr 29, 2021
  9. 2/2 git: support separate arg for `--config-env`'s valuePatrick Steinhardt, Apr 29, 2021
  10. Jeff KingApr 29, 2021
  11. Junio C HamanoApr 30, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.