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

Re: git-config does not check validity of variable names

From
Jeff King <peff@peff.net>
Date
Jan 11, 2011, 05:59 UTC
Message-ID
<20110111055922.GD10094@sigill.intra.peff.net>
In-Reply-To
<20110108144644.GA11019@localhost.suse.cz>
On Sat, Jan 08, 2011 at 03:46:44PM +0100, Libor Pechacek wrote:
Show 7 quoted lines
> I've noticed that git-config accepts variable names in the form "a=b" for its
> "get" operation.  That means "git config a=b" does not write anything to its
> output and exists with status 1.
> 
> According to the man page only alphanumeric characters and - are allowed in
> variable names.  Would it make sense to spit out an error message when the user
> supplies an invalid variable name like the above?

Probably. The current behavior isn't all that terrible, in that it simply tries to look up the key, which of course doesn't exist (because it cannot syntactically), and does signal an error (with the exit code). So it is in some ways no worse than a typo like "git config color.dif.branch". And we probably don't want to start writing to stderr in such a case, as scripts assume they can call git config to find out whether the variable is defined without having to redirect stderr.

That being said, I can see how the lack of a message could be confusing for a user who mistakenly thinks "git config color.diff.branch=red" should work. So I think a patch to make that better would get a favorable response.

Note, though, that what you wrote above is not strictly true. The manpage says variable names and section names must be alphanumeric. But subsection names can contain any character except newline. So it is valid syntactically to do:

  git config color.diff=red.branch

where the subsection contains the "=". Obviously this example is nonsense, and in practice most such "a=b" forms will end up not being syntactically valid (because the = will be part of the variable name, not the subsection). But if you are going to write a patch, you need to make sure not to accidentally disallow:

  git config 'diff.my custom diff driver.command'
-Peff
Previous: Libor PechacekNext: Libor Pechacek
Message 2 of 26 in “git-config does not check validity of variable names”
  1. Libor PechacekJan 8, 2011
  2. Jeff KingJan 11, 2011
  3. Libor PechacekJan 19, 2011
  4. Sanity-ckeck config variable namesLibor Pechacek, Jan 19, 2011
  5. Jeff KingJan 20, 2011
  6. Jeff KingJan 21, 2011
  7. Libor PechacekJan 21, 2011
  8. Sanity-ckeck config variable namesLibor Pechacek, Jan 21, 2011
  9. Jeff KingJan 21, 2011
  10. Sanity-check config variable namesLibor Pechacek, Jan 27, 2011
  11. Junio C HamanoJan 27, 2011
  12. Libor PechacekJan 28, 2011
  13. Sanity-check config variable namesLibor Pechacek, Jan 30, 2011
  14. Junio C HamanoFeb 10, 2011
  15. Libor PechacekFeb 11, 2011
  16. Documentation fixes in git-configLibor Pechacek, Jan 19, 2011
  17. Jeff KingJan 21, 2011
  18. Libor PechacekJan 21, 2011
  19. Documentation fixes in git-configLibor Pechacek, Jan 21, 2011
  20. Jeff KingJan 21, 2011
  21. Libor PechacekJan 23, 2011
  22. Documentation fixes in git-configLibor Pechacek, Mar 1, 2012
  23. Jeff KingMar 1, 2012
  24. Libor PechacekMar 1, 2012
  25. Junio C HamanoMar 1, 2012
  26. Documentation fixes in git-configLibor Pechacek, Mar 1, 2012

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.