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 <redneb@gmx.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Marios Titas committed
Mar 30, 2016 at 22:29 UTC
734c7789aa1055d465e336f618889cc6df478535
1 file changed
+6
-6
ident.c
+6
-6
@@ -351,15 +351,15 @@ const char *fmt_ident(const char *name, const char *email,
351
if (want_name) {
352
int using_default = 0;
353
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");
357
name = ident_default_name();
358
using_default = 1;
359
if (strict && default_name_is_bogus) {
360
fputs(env_hint, stderr);
361
die("unable to auto-detect name (got '%s')", name);
362
}
360
- if (strict && ident_use_config_only
361
- && !(ident_config_given & IDENT_NAME_GIVEN))
362
- die("user.useConfigOnly set but no name given");
363
}
364
if (!*name) {
365
struct passwd *pw;
@@ -374,14 +374,14 @@ const char *fmt_ident(const char *name, const char *email,
374
}
375
376
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");
380
email = ident_default_email();
381
if (strict && default_email_is_bogus) {
382
fputs(env_hint, stderr);
383
die("unable to auto-detect email address (got '%s')", email);
384
}
382
- if (strict && ident_use_config_only
383
- && !(ident_config_given & IDENT_MAIL_GIVEN))
384
- die("user.useConfigOnly set but no mail given");
385
}
386
387
strbuf_reset(&ident);