ident: check for useConfigOnly before auto-detection of name/email
PATCH 1/2 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. So it's better to do the useConfigOnly checks first.
--- ident.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
ident.c +6 -6
@@ -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);
Signature · 1 line
2.8.0
PATCH 2/2 ident: make the useConfigOnly error messages more informative
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 more descriptive error message when that happens.
--- ident.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
ident.c +8 -4
@@ -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);
Signature · 1 line
2.8.0
Re: [PATCH 2/2] ident: make the useConfigOnly error messages more informative
ident.c const char *fmt_ident(const char *name, const char *email,
Quoted 5 lines · Marios Titas
ident.c +3
-2- && !(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
Hmph. I do not think that this is making the message "more informative".
When a user hits this error, the old message allowed the user to easily see how to toggle the "disable auto-detection" bit off to let the code continue by telling the name of the configuration, but the updated message hides that name, making it harder for the user to disable the disabling of auto-detection.
I can buy the argument that this change helps the user by making the message "less" informative, though. By discouraging the users from toggling the user.useConfigOnly bit off, it indirectly makes the other option to work around this error condition, i.e. giving a name more explicitly, more appetizing.
Re: [PATCH 2/2] ident: make the useConfigOnly error messages more informative
Quoted 17 lines · Junio C Hamano
ident.c const char *fmt_ident(const char *name, const char *email,
Quoted 5 lines · Marios Titas
ident.c +3
-2- && !(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 disabledHmph. I do not think that this is making the message "more informative".
When a user hits this error, the old message allowed the user to easily see how to toggle the "disable auto-detection" bit off to let the code continue by telling the name of the configuration, but the updated message hides that name, making it harder for the user to disable the disabling of auto-detection.
Quoted 5 lines
I can buy the argument that this change helps the user by making the message "less" informative, though. By discouraging the users from toggling the user.useConfigOnly bit off, it indirectly makes the other option to work around this error condition, i.e. giving a name more explicitly, more appetizing.
Yeah, maybe informative is not the right word. What I meant is that it directs the user to do the "git config user.name" thing, which is likely the most appropriate course of action in this situation. In any event, I think printing the env_hint message would be really helpful in this case.
Re: [PATCH 2/2] ident: make the useConfigOnly error messages more informative
Quoted 5 lines · Marios Titas
Yeah, maybe informative is not the right word. What I meant is that it directs the user to do the "git config user.name" thing, which is likely the most appropriate course of action in this situation. In any event, I think printing the
env_hintmessage would be really helpful in this case.
OK, let's do this, then.
Thanks.
-- >8 --
From: Marios Titas <[email protected]>
Date: Wed, 30 Mar 2016 22:29:43 +0300
Subject: [PATCH] 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.
--- ident.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
ident.c +8 -4
@@ -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);
Signature · 1 line
2.8.0-246-g1783343
Re: [PATCH 2/2] ident: make the useConfigOnly error messages more informative
Quoted 11 lines · Junio C Hamano
Quoted 5 lines · Marios Titas
Yeah, maybe informative is not the right word. What I meant is that it directs the user to do the "git config user.name" thing, which is likely the most appropriate course of action in this situation. In any event, I think printing the
env_hintmessage would be really helpful in this case.OK, let's do this, then.
Thanks.
A friendly ping asking for an Ack.
Quoted 50 lines
-- >8 --
From: Marios Titas <[email protected]>
Date: Wed, 30 Mar 2016 22:29:43 +0300
Subject: [PATCH] ident: give "please tell me" message upon useConfigOnly errorThe
env_hintmessage 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 <[email protected]>Signed-off-by Junio C Hamano <[email protected]>--- ident.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)ident.c +8
-4@@ -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);
Quoted 3 lines · Marios Titas
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?
Quoted 6 lines
ident.c +2
-0@@ -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 ))
ident.c const char *fmt_ident(const char *name, const char *email, · line 385
Quoted 10 lines
ident.c +1
-3+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" ); }
I wondered on this hunk whether ident_default_email() could ever set the IDENT_MAIL_GIVEN flag. It _does_ set it, but only for "explicitly_given", not for "config_given", which makes sense.
So I think this is doing the right thing.
-Peff
Quoted 9 lines · Jeff King
Quoted 3 lines · Marios Titas
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 "[email protected]" 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.
Quoted 18 lines · Marios Titas
Quoted 9 lines · Jeff King
Quoted 3 lines · Marios Titas
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
Quoted 8 lines
git config --global user.email "[email protected]" 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.
Ah, right. We used to die in xgetpwuid, but now we just set default_name_is_bogus. So I think bumping the use_config_only check above the name_is_bogus check would be sufficient. Where you put it (above ident_default_name) is fine, though it would be a problem if we later lazily loaded the config in that function (I don't have any particular plans to do so, though).
-Peff
Quoted 21 lines · Marios Titas
Quoted 9 lines · Jeff King
Quoted 3 lines · Marios Titas
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 "[email protected]" git config --global user.name "Your Name" to set your account's default identity.
Quoted 5 lines
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 <[email protected]>
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.
--- ident.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
ident.c +6 -6
@@ -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);
Signature · 1 line
2.8.0-246-g1783343