threads / discuss / 32148

git config --git-all can return non-zero error code

Subject: git config --git-all can return non-zero error code

## tl;dr

3 messages between Nov 19, 2012 and Nov 20, 2012.

replies: 2people: 2as markdown or json

Timur Tabi· Nov 19, 2012, 23:02 UTC · lore

According to the man page for git-config, the --git-all option is not supposed to return an error code:

--get-all
	Like get, but does not fail if the number of values for the key is
	not exactly one.

IMHO, zero is also "not exactly one", but I still get a 1 exit code if the key does not exist.

My .git/config says this:
[user "cq.branch"]
	mastr = upstream/master
git-config --get-all does this:

$ git config --get-all user.cq.branch.master $ echo $? 1 $ git config --get-all user.cq.branch.mastr upstream/master $ echo $? 0

I just want git to return nothing if the key doesn't exist. I don't want it to return an exit code. Is there a way to do this? I think either the code is broken or the documentation needs to be changed.

I'm running git version 1.7.3.4
-- 
Timur Tabi
Linux kernel developer at Freescale
Junio C Hamano· Nov 20, 2012, 00:10 UTC · re: Timur Tabi · lore

Re: git config --git-all can return non-zero error code

Timur Tabi <timur@freescale.com> writes:
Show 8 quoted lines
> According to the man page for git-config, the --git-all option is not
> supposed to return an error code:
>
> --get-all
> 	Like get, but does not fail if the number of values for the key is
> 	not exactly one.
>
> IMHO, zero is also "not exactly one",...

It should have stated "like get, but unlike get, it does not fail when there are multiple values for the key", but the documentation was written with that specific knowledge that "--get" has a logic to make it fail when there are ambiguities, and wanted to stress that difference. It forgot to mention their similarity explicitly and relied on "Like get" part to mean (1) shows the value(s) given to the key, and (2) it is an error if there is no such key defined.

Junio C Hamano· Nov 20, 2012, 00:24 UTC · re: Junio C Hamano · lore

[PATCH] config --get-all: it is an error not to see any value

The wording "... is not exactly one." incorrectly hinted as if having no value is not an error, but that was not what was intended. Clarify what similarity it wants to mention by elaborating the "Like get" part of the description.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/git-config.txt | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git i/Documentation/git-config.txt w/Documentation/git-config.txt
index eaea079..273239d 100644
--- i/Documentation/git-config.txt
+++ w/Documentation/git-config.txt
@@ -85,8 +85,9 @@ OPTIONS
 	found and error code 2 if multiple key values were found.
 
 --get-all::
-	Like get, but does not fail if the number of values for the key
-	is not exactly one.
+	Like `--get`, shows the value(s) given to the key, and signals an
+	error if there is no such key.  Unlike `--get`, does not
+	fail if there are multiple values defined for the key.
 
 --get-regexp::
 	Like --get-all, but interprets the name as a regular expression and

← back to recent threads