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

Re: [PATCH 2/2] config: allow specifying config entries via envvar pairs

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Nov 13, 2020, 13:04 UTC
Message-ID
<87mtzlflw7.fsf@evledraar.gmail.com>
In-Reply-To
<44e8dd50c6ea7cbcc5e4fc35c9b9057c0a52038c.1605269465.git.ps@pks.im>
On Fri, Nov 13 2020, Patrick Steinhardt wrote:
> While not document, it is currently possible to specify config entries
"While not documented..."
> +		strbuf_addf(&envvar, "GIT_CONFIG_KEY_%d", i);
> +		if ((key = getenv(envvar.buf)) == NULL)
> +			break;

The convention in git.git is to avoid explicit NULL checks. So maybe something like this, which also avoids the assignment inside an "if"

    key = getenv(envvar.buf);
    if (!key)
        break;
Show 26 quoted lines
> +test_expect_success 'git config handles environment config pairs' '
> +	GIT_CONFIG_KEY_1="pair.one" GIT_CONFIG_VALUE_1="foo" \
> +		GIT_CONFIG_KEY_2="pair.two" GIT_CONFIG_VALUE_2="bar" \
> +		GIT_CONFIG_KEY_4="pair.four" GIT_CONFIG_VALUE_4="not-parsed" \
> +		git config --get-regexp "pair.*" >actual &&
> +	cat >expect <<-EOF &&
> +	pair.one foo
> +	pair.two bar
> +	EOF
> +	test_cmp expect actual
> +'
> +
> +test_expect_success 'git config copes with missing config pair value' '
> +	GIT_CONFIG_KEY_1="pair.one" git config --get-regexp "pair.*" >actual &&
> +	echo pair.one >expect &&
> +	test_cmp expect actual
> +'
> +
> +test_expect_success 'git config fails with invalid config pair key' '
> +	test_must_fail env GIT_CONFIG_KEY_1= git config --list &&
> +	test_must_fail env GIT_CONFIG_KEY_1=missing-section git config --list
> +'
> +
>  test_expect_success 'git config --edit works' '
>  	git config -f tmp test.value no &&
>  	echo test.value=yes >expect &&

I think we should have a bit more complete tests of what happens if you clobber existing config keys, and testing that this is set last after system/global/local config.

Previous: Patrick SteinhardtNext: Junio C Hamano
Message 4 of 27 in “config: allow specifying config entries via envvar pairs”
  1. 0/2 config: allow specifying config entries via envvar pairsPatrick Steinhardt, Nov 13, 2020
  2. 1/2 config: extract function to parse config pairsPatrick Steinhardt, Nov 13, 2020
  3. 2/2 config: allow specifying config entries via envvar pairsPatrick Steinhardt, Nov 13, 2020
  4. Ævar Arnfjörð BjarmasonNov 13, 2020
  5. Junio C HamanoNov 16, 2020
  6. Jeff KingNov 17, 2020
  7. Patrick SteinhardtNov 17, 2020
  8. Jeff KingNov 17, 2020
  9. Ævar Arnfjörð BjarmasonNov 17, 2020
  10. Jeff KingNov 17, 2020
  11. Ævar Arnfjörð BjarmasonNov 18, 2020
  12. brian m. carlsonNov 18, 2020
  13. Jeff KingNov 18, 2020
  14. brian m. carlsonNov 18, 2020
  15. Patrick SteinhardtNov 18, 2020
  16. brian m. carlsonNov 19, 2020
  17. Patrick SteinhardtNov 19, 2020
  18. Junio C HamanoNov 18, 2020
  19. Patrick SteinhardtNov 17, 2020
  20. Junio C HamanoNov 17, 2020
  21. Ævar Arnfjörð BjarmasonNov 18, 2020
  22. Patrick SteinhardtNov 18, 2020
  23. Junio C HamanoNov 18, 2020
  24. Ævar Arnfjörð BjarmasonNov 17, 2020
  25. Philip OakleyNov 13, 2020
  26. Patrick SteinhardtNov 17, 2020
  27. Ævar Arnfjörð BjarmasonNov 13, 2020

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.