Re: [PATCH v7 2/8] config: add new way to pass config via `--config-env`
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 11, 2021, 22:34 UTC
- Message-ID
- <xmqq1rer6r2g.fsf@gitster.c.googlers.com>
- In-Reply-To
- <b9cf47afe896f8a6a76ba2e8aa87155e147ff31d.1610353895.git.ps@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 12 quoted lines
> +void git_config_push_env(const char *spec)
> +{
> + struct strbuf buf = STRBUF_INIT;
> + const char *env_name;
> + const char *env_value;
> +
> + env_name = strrchr(spec, '=');
> + if (!env_name)
> + die(_("invalid config format: %s"), spec);
> + env_name++;
> + if (!*env_name)
> + die(_("missing value for --config-env"));If reporting the name of the configuration variable, for which we checked an environment variable, is worth doing in the !env_value case below, shouldn't we be doing the same here, too? I.e.
die(_("missing environment variable name in %s", spec));;or something to complain against "git --config-env foo="?
> + env_value = getenv(env_name);
> + if (!env_value)
> + die(_("missing environment variable '%s' for configuration '%.*s'"),
> + env_name, (int)(env_name - spec - 1), spec);Show 10 quoted lines
> +test_expect_success 'git --config-env=key=envvar support' '
> + cat >expect <<-\EOF &&
> + value
> + value
> + false
> + EOF
> + {
> + env ENVVAR=value git --config-env=core.name=ENVVAR config core.name &&
> + env ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config foo.camelcase &&
> + env ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flagThese "env " prefixes are not wrong per-se but are unnecessary. The same for the rest of this patch.
Show 10 quoted lines
> + } >actual && > + test_cmp expect actual > +' > + > +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" error && > + test_must_fail git --config-env=foo.flag= config --bool foo.flag 2>error && > + test_i18ngrep "missing value for --config-env" error && > + test_must_fail git --config-env=foo.flag=NONEXISTENT config --bool foo.flag 2>error &&
How are we making sure
$ NONEXISTENT=True make test
is not what the end-user is running?
sane_unset X && test_must_fail git --config-env foo.flag=X config --bool foo.flag
or something along that line, perhaps?