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 <ps@pks.im> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Apr 29, 2021 at 14:55 UTC c331551ccf9a4c8922ff5d2987eed9e218479000
2 files changed +22 -1
git.c
+8
@@ -255,6 +255,14 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
255 git_config_push_parameter((*argv)[1]);
256 (*argv)++;
257 (*argc)--;
258 + } else if (!strcmp(cmd, "--config-env")) {
259 + if (*argc < 2) {
260 + fprintf(stderr, _("no config key given for --config-env\n" ));
261 + usage(git_usage_string);
262 + }
263 + git_config_push_env((*argv)[1]);
264 + (*argv)++;
265 + (*argc)--;
266 } else if (skip_prefix(cmd, "--config-env=", &cmd)) {
267 git_config_push_env(cmd);
268 } else if (!strcmp(cmd, "--literal-pathspecs")) {
t/t1300-config.sh
+14 -1
@@ -1372,16 +1372,29 @@ test_expect_success 'git --config-env=key=envvar support' '
1372 cat >expect <<-\EOF &&
1373 value
1374 value
1375 + value
1376 + value
1377 + false
1378 false
1379 EOF
1380 {
1381 ENVVAR=value git --config-env=core.name=ENVVAR config core.name &&
1382 + ENVVAR=value git --config-env core.name=ENVVAR config core.name &&
1383 ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config foo.camelcase &&
1380 - ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag
1384 + ENVVAR=value git --config-env foo.CamelCase=ENVVAR config foo.camelcase &&
1385 + ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag &&
1386 + ENVVAR= git --config-env foo.flag=ENVVAR config --bool foo.flag
1387 } >actual &&
1388 test_cmp expect actual
1389 '
1390
1391 +test_expect_success 'git --config-env with missing value' '
1392 + test_must_fail env ENVVAR=value git --config-env 2>error &&
1393 + grep "no config key given for --config-env" error &&
1394 + test_must_fail env ENVVAR=value git --config-env config core.name 2>error &&
1395 + grep "invalid config format: config" error
1396 +'
1397 +
1398 test_expect_success 'git --config-env fails with invalid parameters' '
1399 test_must_fail git --config-env=foo.flag config --bool foo.flag 2>error &&
1400 test_i18ngrep "invalid config format: foo.flag" error &&