Thread (1 message) 1 message, 1 author, 2016-06-15

Re: git config --get-regexp exit status

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:43:58

David Kågedal [off-list ref] writes:
David Kågedal [off-list ref] 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...
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help