Skip to content

Commit 9442555

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 13b9a24 commit 9442555

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

ident.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static void copy_email(const struct passwd *pw, struct strbuf *email,
153153

154154
const char *ident_default_name(void)
155155
{
156-
if (!git_default_name.len) {
156+
if (!(ident_config_given & IDENT_NAME_GIVEN) && !git_default_name.len) {
157157
copy_gecos(xgetpwuid_self(&default_name_is_bogus), &git_default_name);
158158
strbuf_trim(&git_default_name);
159159
}
@@ -162,7 +162,7 @@ const char *ident_default_name(void)
162162

163163
const char *ident_default_email(void)
164164
{
165-
if (!git_default_email.len) {
165+
if (!(ident_config_given & IDENT_MAIL_GIVEN) && !git_default_email.len) {
166166
const char *email = getenv("EMAIL");
167167

168168
if (email && email[0]) {

t/t7518-ident-corner-cases.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,15 @@ test_expect_success 'commit rejects all-crud name' '
2222
git commit --allow-empty -m foo
2323
'
2424

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+
2536
test_done

0 commit comments

Comments
 (0)