Thread (1 message) 1 message, 1 author, 2016-06-15

Re: [PATCH 1/2] ident: check for useConfigOnly before auto-detection of name/email

From: Junio C Hamano <hidden>
Date: 2016-06-15 23:09:10
Subsystem: the rest · Maintainer: Linus Torvalds

Possibly related (same subject, not in this thread)

Marios Titas [off-list ref] writes:
On Thu, Mar 31, 2016 at 10:40:03AM -0400, Jeff King wrote:
quoted
On Wed, Mar 30, 2016 at 10:29:42PM +0300, Marios Titas wrote:
quoted
If user.useConfigOnly is set, it does not make sense to try to
auto-detect the name and/or the email. So it's better to do the
useConfigOnly checks first.
It might be nice to explain how it is better here. I'd guess it is
because we may fail during xgetpwuid(), giving a message that is much
less informative?
Oops sorry, my bad, I should have included an example in the commit
message. So with git 2.8.0, if you provide a name and set
useConfigOnly to true in your ~/.gitconfig file, then if try to commit
something in a new git repo, it will fail with the following message:

   *** Please tell me who you are.
    Run
      git config --global user.email "you@example.com"
     git config --global user.name "Your Name"
    to set your account's default identity.
   Omit --global to set the identity only in this repository.
    fatal: unable to auto-detect email address (got 'XXX@YYY.(none)')

(provided of course that auto-detection of email fails). This wrong,
because auto-detection is disabled anyway.
OK, let's do this, then.

-- >8 --
From: Marios Titas <redacted>
Date: Wed, 30 Mar 2016 22:29:42 +0300
Subject: [PATCH] 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 <redacted>
Signed-off-by: Junio C Hamano <redacted>
---
 ident.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
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);
-- 
2.8.0-246-g1783343
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help