Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected `git config --get core.commentChar` exit code

Tags:

git

TL;DR: Why do

git config --get core.commentChar
echo $?

prints 1?


More context:

With either git 2.14.2.windows.3 on Windows 7 and git 2.7.4 on Ubuntu 16.04, when I run git config --get core.commentChar I get the exit error code 1.

I don't understand this behavior because according to the documentation of git config:

  • The exit code 1 means that The section or key is invalid
  • but core.commentChar is a config documented on this same page

(Also, when I run git config --get core.editor, it correctly prints vim and has exit code 0).

like image 451
gturri Avatar asked Mar 12 '26 06:03

gturri


1 Answers

The documentation really should say "invalid or not set/missing". In fact, it does say that:

--get

     Get the value for a given key (optionally filtered by a regex matching the value). Returns error code 1 if the key was not found and the last value if multiple key values were found.

Hence, if you have not specifically set core.commentChar to something, git config --get core.commentChar (a) prints nothing and (b) exits nonzero. This is distinct from the case where you set it to an empty string, in which case git config --get would print nothing but exit with status zero.

like image 91
torek Avatar answered Mar 14 '26 21:03

torek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!