ident: say whose identity is missing when giving user.name hint
If `user.name` and `user.email` have not been configured and the user invokes: git commit --author=... without specifying the committer identity, then Git errors out with a message asking the user to configure `user.name` and `user.email` but doesn't tell the user which attribution was missing. This can be confusing for a user new to Git who isn't aware of the distinction between user, author, and committer. Give such users a bit more help by extending the error message to also say which attribution is expected. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Aug 21, 2020 at 13:36 UTC
9ed104e5cacdc44f2fe7c2b1fdeada94622ca4e9
2 files changed
+43
-18
ident.c
+31
-17
@@ -345,18 +345,32 @@ person_only:
345
return 0;
346
}
347
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 \"you@example.com\"\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 \"you@example.com\"\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
+}
374
375
const char *fmt_ident(const char *name, const char *email,
376
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,
389
if (!email) {
390
if (strict && ident_use_config_only
391
&& !(ident_config_given & IDENT_MAIL_GIVEN)) {
378
- fputs(_(env_hint), stderr);
392
+ ident_env_hint(whose_ident);
393
die(_("no email was given and auto-detection is disabled"));
394
}
395
email = ident_default_email();
396
if (strict && default_email_is_bogus) {
383
- fputs(_(env_hint), stderr);
397
+ ident_env_hint(whose_ident);
398
die(_("unable to auto-detect email address (got '%s')"), email);
399
}
400
}
@@ -397,13 +411,13 @@ const char *fmt_ident(const char *name, const char *email,
411
if (!name) {
412
if (strict && ident_use_config_only
413
&& !(ident_config_given & IDENT_NAME_GIVEN)) {
400
- fputs(_(env_hint), stderr);
414
+ ident_env_hint(whose_ident);
415
die(_("no name was given and auto-detection is disabled"));
416
}
417
name = ident_default_name();
418
using_default = 1;
419
if (strict && default_name_is_bogus) {
406
- fputs(_(env_hint), stderr);
420
+ ident_env_hint(whose_ident);
421
die(_("unable to auto-detect name (got '%s')"), name);
422
}
423
}
@@ -411,7 +425,7 @@ const char *fmt_ident(const char *name, const char *email,
425
struct passwd *pw;
426
if (strict) {
427
if (using_default)
414
- fputs(_(env_hint), stderr);
428
+ ident_env_hint(whose_ident);
429
die(_("empty ident name (for <%s>) not allowed"), email);
430
}
431
pw = xgetpwuid_self(NULL);
t/t7518-ident-corner-cases.sh
+12
-1
@@ -29,7 +29,18 @@ test_expect_success 'empty configured name does not auto-detect' '
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
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
44
)
45
'
46