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

[PATCH 2/2] t1300: test mixed-case variable retrieval

From
Jeff King <peff@peff.net>
Date
Oct 12, 2011, 18:30 UTC
Message-ID
<20111012183002.GB18948@sigill.intra.peff.net>
In-Reply-To
<20111012182742.GA14543@sigill.intra.peff.net>

We should be able to ask for a config value both by its canonical all-lowercase name (as git does internally), as well as by random mixed-case (which will be canonicalized by git-config for us).

Subsections are a tricky point, though. Since we have both
  [section "Foo"]
and
  [section.Foo]

you might want git-config to canonicalize the subsection or not, depending on which you are expecting. But there's no way to communicate this; git-config sees only the key, and doesn't know which type of section name will be in the config file.

So it must leave the subsection intact, and it is up to the caller to provide a canonical version of the subsection if they want to match the latter form.

Signed-off-by: Jeff King <peff@peff.net>
---
I was surprised this wasn't tested anywhere, but I couldn't find any
such place. I think it makes sense to document the desired behavior in
the form of a few tests.
 t/t1300-repo-config.sh |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
index cf508af..8a37f96 100755
--- a/t/t1300-repo-config.sh
+++ b/t/t1300-repo-config.sh
@@ -73,6 +73,33 @@ EOF
 
 test_expect_success 'non-match result' 'test_cmp expect .git/config'
 
+test_expect_success 'find mixed-case key by canonical name' '
+	echo Second >expect &&
+	git config cores.whatever >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'find mixed-case key by non-canonical name' '
+	echo Second >expect &&
+	git config CoReS.WhAtEvEr >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'subsections are not canonicalized by git-config' '
+	cat >>.git/config <<-\EOF &&
+	[section.SubSection]
+	key = one
+	[section "SubSection"]
+	key = two
+	EOF
+	echo one >expect &&
+	git config section.subsection.key >actual &&
+	test_cmp expect actual &&
+	echo two >expect &&
+	git config section.SubSection.key >actual &&
+	test_cmp expect actual
+'
+
 cat > .git/config <<\EOF
 [alpha]
 bar = foo
-- 
1.7.7.rc2.21.gb9948
Previous: Jeff KingNext: Junio C Hamano
Message 10 of 13 in “Documentation: update [section.subsection] to reflect what git does”
  1. Documentation: update [section.subsection] to reflect what git doesCarlos Martín Nieto, Oct 12, 2011
  2. Jeff KingOct 12, 2011
  3. Jeff KingOct 12, 2011
  4. Jeff KingOct 12, 2011
  5. 1/2 t1300: put git invocations inside test functionJeff King, Oct 12, 2011
  6. Johannes SixtOct 19, 2011
  7. Junio C HamanoOct 19, 2011
  8. t1300: attempting to remove a non-existent .git/config is not an errorJohannes Sixt, Oct 19, 2011
  9. Jeff KingOct 19, 2011
  10. 2/2 t1300: test mixed-case variable retrievalJeff King, Oct 12, 2011
  11. Junio C HamanoOct 12, 2011
  12. Junio C HamanoOct 12, 2011
  13. Jeff KingOct 12, 2011

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.