ident: do not ignore empty config name/email

When we read user.name and user.email from a config file, they go into strbufs. When a caller asks ident_default_name() for the value, we fallback to auto-detecting if the strbuf is empty. That means that explicitly setting an empty string in the config is identical to not setting it at all. This is potentially confusing, as we usually accept a configured value as the final value. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Feb 23, 2017 at 03:17 UTC 94425552f308946456bb7823d0a1dd72ebd30bdd
2 files changed +13 -2
ident.c
+2 -2
@@ -153,7 +153,7 @@ static void copy_email(const struct passwd *pw, struct strbuf *email,
153
154 const char *ident_default_name(void)
155 {
156 - if (!git_default_name.len) {
156 + if (!(ident_config_given & IDENT_NAME_GIVEN) && !git_default_name.len) {
157 copy_gecos(xgetpwuid_self(&default_name_is_bogus), &git_default_name);
158 strbuf_trim(&git_default_name);
159 }
@@ -162,7 +162,7 @@ const char *ident_default_name(void)
162
163 const char *ident_default_email(void)
164 {
165 - if (!git_default_email.len) {
165 + if (!(ident_config_given & IDENT_MAIL_GIVEN) && !git_default_email.len) {
166 const char *email = getenv("EMAIL");
167
168 if (email && email[0]) {
t/t7518-ident-corner-cases.sh
+11
@@ -22,4 +22,15 @@ test_expect_success 'commit rejects all-crud name' '
22 git commit --allow-empty -m foo
23 '
24
25 +# We must test the actual error message here, as an unwanted
26 +# auto-detection could fail for other reasons.
27 +test_expect_success 'empty configured name does not auto-detect' '
28 + (
29 + sane_unset GIT_AUTHOR_NAME &&
30 + test_must_fail \
31 + git -c user.name= commit --allow-empty -m foo 2>err &&
32 + test_i18ngrep "empty ident name" err
33 + )
34 +'
35 +
36 test_done