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

Re: git config --get-regexp exit status

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 13, 2007, 18:06 UTC
Message-ID
<7vfxy631w6.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<871w9qsoc8.fsf@lysator.liu.se>
David Kågedal <davidk@lysator.liu.se> writes:
Show 11 quoted lines
> David Kågedal <davidk@lysator.liu.se> writes:
> ...
> One thing that annoyed me what that "git config --get-regexp" will
> return zero, one, or more matches, which are all valid reponses. But
> it treats the zero-match special and return an exit status of 1.
>
> Is that a conscious choice, or just an effect of how "git config
> --get" works?
>
> Since zero matches isn't really an error, I would like the exit status
> to be 0. At least for this use case :-)

I would imagine "matching variant" may want to signal "I did not match anything" as a special event, just like grep does. As long as the caller can distinguish "no match" from real failure cases (say, not in a git repository and hence no configuration file), that is one valid use of status code.

I haven't been annoyed by that myself, but I see what you mean. "give me all the matching ones" callers would want to consider zero match and seven matches both the same way as non errors. And similarity to "grep" does not extend very far because there is no "--get-regexp" variant that is quiet (i.e. "no output, just checking if there is a match").

So I do not mind if --get-regexp considered zero matches as non-error myself. If an existing script did something like:

	if list=$(git config --get-regexp '$pattern')
        then
        	# use list, without verifying if it is empty
                ...
	fi

such a change would break it, though. But the script should have been doing:

	LF='
	'
	if list=$(git config --get-regexp '$pattern')
        then
		IFS="$LF"
		for $list
                do
                	...
		done
	fi
anyway, so...
Previous: David KågedalNext: Catalin Marinas
Message 3 of 13 in “[StGit RFC] Make "stg branch -l" faster by getting all git config information in one call”
  1. David KågedalDec 13, 2007
  2. git config --get-regexp exit statusDavid Kågedal, Dec 13, 2007
  3. Junio C HamanoDec 13, 2007
  4. Catalin MarinasDec 13, 2007
  5. David KågedalDec 13, 2007
  6. David KågedalDec 13, 2007
  7. Catalin MarinasDec 13, 2007
  8. David KågedalDec 13, 2007
  9. Karl HasselströmDec 13, 2007
  10. Karl HasselströmDec 13, 2007
  11. Catalin MarinasDec 13, 2007
  12. David KågedalDec 13, 2007
  13. Karl HasselströmDec 13, 2007

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.