Skip to contentSkip to conversation

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

PATCH New Timur Tabi 2 participants 3 messages Jun 15, 2016 Documentation

lore
Share & tools
lore

Timur Tabi

author
#0 lore raw

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

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#1 lore raw
Quoted 8 lines · Timur Tabi

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.

#2 lore raw

PATCH 1/1 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.

---
 Documentation/git-config.txt | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Documentation/git-config.txt +3 -2
index eaea079..273239d 100644
@@ -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