From 734c7789aa1055d465e336f618889cc6df478535 Mon Sep 17 00:00:00 2001 From: Marios Titas Date: Wed, 30 Mar 2016 22:29:42 +0300 Subject: 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 Signed-off-by: Junio C Hamano diff --git a/ident.c b/ident.c index 4bd8084..b2521ff 100644 --- a/ident.c +++ b/ident.c @@ -351,15 +351,15 @@ const char *fmt_ident(const char *name, const char *email, if (want_name) { int using_default = 0; if (!name) { + if (strict && ident_use_config_only + && !(ident_config_given & IDENT_NAME_GIVEN)) + die("user.useConfigOnly set but no name given"); name = ident_default_name(); using_default = 1; if (strict && default_name_is_bogus) { fputs(env_hint, stderr); die("unable to auto-detect name (got '%s')", name); } - if (strict && ident_use_config_only - && !(ident_config_given & IDENT_NAME_GIVEN)) - die("user.useConfigOnly set but no name given"); } if (!*name) { struct passwd *pw; @@ -374,14 +374,14 @@ const char *fmt_ident(const char *name, const char *email, } if (!email) { + if (strict && ident_use_config_only + && !(ident_config_given & IDENT_MAIL_GIVEN)) + die("user.useConfigOnly set but no mail given"); email = ident_default_email(); if (strict && default_email_is_bogus) { fputs(env_hint, stderr); die("unable to auto-detect email address (got '%s')", email); } - if (strict && ident_use_config_only - && !(ident_config_given & IDENT_MAIL_GIVEN)) - die("user.useConfigOnly set but no mail given"); } strbuf_reset(&ident); -- cgit v0.10.2-6-g49f6 From d3c06c196964c02f7343b53301e0e85679fad51f Mon Sep 17 00:00:00 2001 From: Marios Titas Date: Wed, 30 Mar 2016 22:29:43 +0300 Subject: ident: give "please tell me" message upon useConfigOnly error The env_hint message applies perfectly to the case when user.useConfigOnly is set and at least one of the user.name and the user.email are not provided. Additionally, use a less descriptive error message to discourage users from disabling user.useConfigOnly configuration variable to work around this error condition. We want to encourage them to set user.name or user.email instead. Signed-off-by: Marios Titas Signed-off-by: Junio C Hamano diff --git a/ident.c b/ident.c index b2521ff..c766127 100644 --- a/ident.c +++ b/ident.c @@ -352,8 +352,10 @@ const char *fmt_ident(const char *name, const char *email, int using_default = 0; if (!name) { if (strict && ident_use_config_only - && !(ident_config_given & IDENT_NAME_GIVEN)) - die("user.useConfigOnly set but no name given"); + && !(ident_config_given & IDENT_NAME_GIVEN)) { + fputs(env_hint, stderr); + die("no name was given and auto-detection is disabled"); + } name = ident_default_name(); using_default = 1; if (strict && default_name_is_bogus) { @@ -375,8 +377,10 @@ const char *fmt_ident(const char *name, const char *email, if (!email) { if (strict && ident_use_config_only - && !(ident_config_given & IDENT_MAIL_GIVEN)) - die("user.useConfigOnly set but no mail given"); + && !(ident_config_given & IDENT_MAIL_GIVEN)) { + fputs(env_hint, stderr); + die("no email was given and auto-detection is disabled"); + } email = ident_default_email(); if (strict && default_email_is_bogus) { fputs(env_hint, stderr); -- cgit v0.10.2-6-g49f6