Skip to content

Commit e9bd00a

Browse files
committed
Merge branch 'jc/ident-whose-ident'
Error message update. * jc/ident-whose-ident: ident: say whose identity is missing when giving user.name hint
2 parents 1393f56 + 9ed104e commit e9bd00a

File tree

2 files changed

+43
-18
lines changed

2 files changed

+43
-18
lines changed

ident.c

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -345,18 +345,32 @@ int split_ident_line(struct ident_split *split, const char *line, int len)
345345
return 0;
346346
}
347347

348-
static const char *env_hint =
349-
N_("\n"
350-
"*** Please tell me who you are.\n"
351-
"\n"
352-
"Run\n"
353-
"\n"
354-
" git config --global user.email \"[email protected]\"\n"
355-
" git config --global user.name \"Your Name\"\n"
356-
"\n"
357-
"to set your account\'s default identity.\n"
358-
"Omit --global to set the identity only in this repository.\n"
359-
"\n");
348+
349+
static void ident_env_hint(enum want_ident whose_ident)
350+
{
351+
switch (whose_ident) {
352+
case WANT_AUTHOR_IDENT:
353+
fputs(_("Author identity unknown\n"), stderr);
354+
break;
355+
case WANT_COMMITTER_IDENT:
356+
fputs(_("Committer identity unknown\n"), stderr);
357+
break;
358+
default:
359+
break;
360+
}
361+
362+
fputs(_("\n"
363+
"*** Please tell me who you are.\n"
364+
"\n"
365+
"Run\n"
366+
"\n"
367+
" git config --global user.email \"[email protected]\"\n"
368+
" git config --global user.name \"Your Name\"\n"
369+
"\n"
370+
"to set your account\'s default identity.\n"
371+
"Omit --global to set the identity only in this repository.\n"
372+
"\n"), stderr);
373+
}
360374

361375
const char *fmt_ident(const char *name, const char *email,
362376
enum want_ident whose_ident, const char *date_str, int flag)
@@ -375,12 +389,12 @@ const char *fmt_ident(const char *name, const char *email,
375389
if (!email) {
376390
if (strict && ident_use_config_only
377391
&& !(ident_config_given & IDENT_MAIL_GIVEN)) {
378-
fputs(_(env_hint), stderr);
392+
ident_env_hint(whose_ident);
379393
die(_("no email was given and auto-detection is disabled"));
380394
}
381395
email = ident_default_email();
382396
if (strict && default_email_is_bogus) {
383-
fputs(_(env_hint), stderr);
397+
ident_env_hint(whose_ident);
384398
die(_("unable to auto-detect email address (got '%s')"), email);
385399
}
386400
}
@@ -397,21 +411,21 @@ const char *fmt_ident(const char *name, const char *email,
397411
if (!name) {
398412
if (strict && ident_use_config_only
399413
&& !(ident_config_given & IDENT_NAME_GIVEN)) {
400-
fputs(_(env_hint), stderr);
414+
ident_env_hint(whose_ident);
401415
die(_("no name was given and auto-detection is disabled"));
402416
}
403417
name = ident_default_name();
404418
using_default = 1;
405419
if (strict && default_name_is_bogus) {
406-
fputs(_(env_hint), stderr);
420+
ident_env_hint(whose_ident);
407421
die(_("unable to auto-detect name (got '%s')"), name);
408422
}
409423
}
410424
if (!*name) {
411425
struct passwd *pw;
412426
if (strict) {
413427
if (using_default)
414-
fputs(_(env_hint), stderr);
428+
ident_env_hint(whose_ident);
415429
die(_("empty ident name (for <%s>) not allowed"), email);
416430
}
417431
pw = xgetpwuid_self(NULL);

t/t7518-ident-corner-cases.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,18 @@ test_expect_success 'empty configured name does not auto-detect' '
2929
sane_unset GIT_AUTHOR_NAME &&
3030
test_must_fail \
3131
git -c user.name= commit --allow-empty -m foo 2>err &&
32-
test_i18ngrep "empty ident name" err
32+
test_i18ngrep "empty ident name" err &&
33+
test_i18ngrep "Author identity unknown" err
34+
)
35+
'
36+
37+
test_expect_success 'empty configured name does not auto-detect for committer' '
38+
(
39+
sane_unset GIT_COMMITTER_NAME &&
40+
test_must_fail \
41+
git -c user.name= commit --allow-empty -m foo 2>err &&
42+
test_i18ngrep "empty ident name" err &&
43+
test_i18ngrep "Committer identity unknown" err
3344
)
3445
'
3546

0 commit comments

Comments
 (0)