Skip to content

Commit 734c778

Browse files
rednebgitster
authored andcommitted
ident: check for useConfigOnly before auto-detection of name/email
If user.useConfigOnly is set, it does not make sense to try to auto-detect the name and/or the email. The auto-detection may even result in a bogus name and trigger an error message. Check if the use-config-only is set and die if no explicit name was given, before attempting to auto-detect, to correct this. Signed-off-by: Marios Titas <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4d5c295 commit 734c778

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

ident.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,15 +351,15 @@ const char *fmt_ident(const char *name, const char *email,
351351
if (want_name) {
352352
int using_default = 0;
353353
if (!name) {
354+
if (strict && ident_use_config_only
355+
&& !(ident_config_given & IDENT_NAME_GIVEN))
356+
die("user.useConfigOnly set but no name given");
354357
name = ident_default_name();
355358
using_default = 1;
356359
if (strict && default_name_is_bogus) {
357360
fputs(env_hint, stderr);
358361
die("unable to auto-detect name (got '%s')", name);
359362
}
360-
if (strict && ident_use_config_only
361-
&& !(ident_config_given & IDENT_NAME_GIVEN))
362-
die("user.useConfigOnly set but no name given");
363363
}
364364
if (!*name) {
365365
struct passwd *pw;
@@ -374,14 +374,14 @@ const char *fmt_ident(const char *name, const char *email,
374374
}
375375

376376
if (!email) {
377+
if (strict && ident_use_config_only
378+
&& !(ident_config_given & IDENT_MAIL_GIVEN))
379+
die("user.useConfigOnly set but no mail given");
377380
email = ident_default_email();
378381
if (strict && default_email_is_bogus) {
379382
fputs(env_hint, stderr);
380383
die("unable to auto-detect email address (got '%s')", email);
381384
}
382-
if (strict && ident_use_config_only
383-
&& !(ident_config_given & IDENT_MAIL_GIVEN))
384-
die("user.useConfigOnly set but no mail given");
385385
}
386386

387387
strbuf_reset(&ident);

0 commit comments

Comments
 (0)