]> git.ipfire.org Git - thirdparty/git.git/commit - ident.c
ident: loosen getpwuid error in non-strict mode
authorJeff King <peff@peff.net>
Thu, 10 Dec 2015 21:41:29 +0000 (16:41 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 14 Dec 2015 19:44:38 +0000 (11:44 -0800)
commit92bcbb9b338dd27f0fd4245525093c4bce867f3d
tree5056694013c8a91b2618f4e05a1e681417c75acc
parent19ce497cf594a3c01af33a65b27b19e7459212d6
ident: loosen getpwuid error in non-strict mode

If the user has not specified an identity and we have to
turn to getpwuid() to find the username or gecos field, we
die immediately when getpwuid fails (e.g., because the user
does not exist). This is OK for making a commit, where we
have set IDENT_STRICT and would want to bail on bogus input.

But for something like a reflog, where the ident is "best
effort", it can be pain. For instance, even running "git
clone" with a UID that is not in /etc/passwd will result in
git barfing, just because we can't find an ident to put in
the reflog.

Instead of dying in xgetpwuid_self, we can instead return a
fallback value, and set a "bogus" flag. For the username in
an email, we already have a "default_email_is_bogus" flag.
For the name field, we introduce (and check) a matching
"default_name_is_bogus" flag. As a bonus, this means you now
get the usual "tell me who you are" advice instead of just a
"no such user" error.

No tests, as this is dependent on configuration outside of
git's control. However, I did confirm that it behaves
sensibly when I delete myself from the local /etc/passwd
(reflogs get written, and commits complain).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
ident.c