* --author arg on commit only works if there is an email configured already
@ 2020-08-21 16:15 Alvaro Aleman
2020-08-21 18:28 ` Andreas Schwab
0 siblings, 1 reply; 10+ messages in thread
From: Alvaro Aleman @ 2020-08-21 16:15 UTC (permalink / raw)
To: git
Hello everyone,
It seems the `--author` arg on the `git commit` command only works if
an author email is configured already somewhere:
Sample that I would expect to work and that does not work:
```
$ docker run --rm -it golang /bin/bash -c 'cd $(mktemp -d); git init;
touch test; git add test; git commit -m message --author "A U Thor
<author@example.com>"'
Initialized empty Git repository in /tmp/tmp.TiNqOZsw9C/.git/
*** 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 'root@aedfbe0df193.(none)')
```
When configuring any mail first, this works and uses the mail
specified in the `--author` arg:
```
$ docker run --rm -it golang /bin/bash -c 'cd $(mktemp -d); git init;
touch test; git add test; git config --local user.email
"mail@domain.com"; git commit -m message --author "A U Thor
<author@example.com>"'
Initialized empty Git repository in /tmp/tmp.1drhE2Rgmh/.git/
[master (root-commit) b3dad37] message
Author: A U Thor <author@example.com>
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test
```
The git version:
$ docker run --rm -it golang git --version
git version 2.20
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: --author arg on commit only works if there is an email configured already
2020-08-21 16:15 --author arg on commit only works if there is an email configured already Alvaro Aleman
@ 2020-08-21 18:28 ` Andreas Schwab
2020-08-21 18:46 ` Junio C Hamano
0 siblings, 1 reply; 10+ messages in thread
From: Andreas Schwab @ 2020-08-21 18:28 UTC (permalink / raw)
To: Alvaro Aleman; +Cc: git
On Aug 21 2020, Alvaro Aleman wrote:
> It seems the `--author` arg on the `git commit` command only works if
> an author email is configured already somewhere:
The `--author' argument only sets the author, but git still need to fill
in the committer.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: --author arg on commit only works if there is an email configured already
2020-08-21 18:28 ` Andreas Schwab
@ 2020-08-21 18:46 ` Junio C Hamano
2020-08-21 19:55 ` Alvaro Aleman
0 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2020-08-21 18:46 UTC (permalink / raw)
To: Andreas Schwab; +Cc: Alvaro Aleman, git
Andreas Schwab <schwab@linux-m68k.org> writes:
> On Aug 21 2020, Alvaro Aleman wrote:
>
>> It seems the `--author` arg on the `git commit` command only works if
>> an author email is configured already somewhere:
>
> The `--author' argument only sets the author, but git still need to fill
> in the committer.
In other words, the --author option works just fine. You still need
to tell Git what committer identity you want to use, and the easiest
way to do so is with user.{name,email} configuration variables.
I wonder if it helps to give an extra line of message like the
attached (untested) patch, though.
ident.c | 51 ++++++++++++++++++++++++++++++++++-----------------
1 file changed, 34 insertions(+), 17 deletions(-)
diff --git a/ident.c b/ident.c
index e666ee4e59..177ac00261 100644
--- a/ident.c
+++ b/ident.c
@@ -345,18 +345,35 @@ int split_ident_line(struct ident_split *split, const char *line, int len)
return 0;
}
-static const char *env_hint =
-N_("\n"
- "*** Please tell me who you are.\n"
- "\n"
- "Run\n"
- "\n"
- " git config --global user.email \"you@example.com\"\n"
- " git config --global user.name \"Your Name\"\n"
- "\n"
- "to set your account\'s default identity.\n"
- "Omit --global to set the identity only in this repository.\n"
- "\n");
+
+static void ident_env_hint(enum want_ident whose_ident)
+{
+ static const char *env_hint =
+ N_("\n"
+ "*** Please tell me who you are.\n"
+ "\n"
+ "Run\n"
+ "\n"
+ " git config --global user.email \"you@example.com\"\n"
+ " git config --global user.name \"Your Name\"\n"
+ "\n"
+ "to set your account\'s default identity.\n"
+ "Omit --global to set the identity only in this repository.\n"
+ "\n");
+
+ switch (whose_ident) {
+ case WANT_AUTHOR_IDENT:
+ fputs(_("Author identity unknown\n"), stderr);
+ break;
+ case WANT_COMMITTER_IDENT:
+ fputs(_("Committer identity unknown\n"), stderr);
+ break;
+ default:
+ break;
+ }
+
+ fputs(_(env_hint), stderr);
+}
const char *fmt_ident(const char *name, const char *email,
enum want_ident whose_ident, const char *date_str, int flag)
@@ -375,12 +392,12 @@ const char *fmt_ident(const char *name, const char *email,
if (!email) {
if (strict && ident_use_config_only
&& !(ident_config_given & IDENT_MAIL_GIVEN)) {
- fputs(_(env_hint), stderr);
+ ident_env_hint(whose_ident);
die(_("no email was given and auto-detection is disabled"));
}
email = ident_default_email();
if (strict && default_email_is_bogus) {
- fputs(_(env_hint), stderr);
+ ident_env_hint(whose_ident);
die(_("unable to auto-detect email address (got '%s')"), email);
}
}
@@ -397,13 +414,13 @@ const char *fmt_ident(const char *name, const char *email,
if (!name) {
if (strict && ident_use_config_only
&& !(ident_config_given & IDENT_NAME_GIVEN)) {
- fputs(_(env_hint), stderr);
+ ident_env_hint(whose_ident);
die(_("no name was given and auto-detection is disabled"));
}
name = ident_default_name();
using_default = 1;
if (strict && default_name_is_bogus) {
- fputs(_(env_hint), stderr);
+ ident_env_hint(whose_ident);
die(_("unable to auto-detect name (got '%s')"), name);
}
}
@@ -411,7 +428,7 @@ const char *fmt_ident(const char *name, const char *email,
struct passwd *pw;
if (strict) {
if (using_default)
- fputs(_(env_hint), stderr);
+ ident_env_hint(whose_ident);
die(_("empty ident name (for <%s>) not allowed"), email);
}
pw = xgetpwuid_self(NULL);
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: --author arg on commit only works if there is an email configured already
2020-08-21 18:46 ` Junio C Hamano
@ 2020-08-21 19:55 ` Alvaro Aleman
2020-08-21 20:36 ` [PATCH] ident: say whose identity is missing when giving user.name hint Junio C Hamano
0 siblings, 1 reply; 10+ messages in thread
From: Alvaro Aleman @ 2020-08-21 19:55 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Andreas Schwab, git
Thank you for the explanation. Yes, having the error explicitly
mention t about which of author/committer this is would be helpful.
On Fri, Aug 21, 2020 at 2:47 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Andreas Schwab <schwab@linux-m68k.org> writes:
>
> > On Aug 21 2020, Alvaro Aleman wrote:
> >
> >> It seems the `--author` arg on the `git commit` command only works if
> >> an author email is configured already somewhere:
> >
> > The `--author' argument only sets the author, but git still need to fill
> > in the committer.
>
> In other words, the --author option works just fine. You still need
> to tell Git what committer identity you want to use, and the easiest
> way to do so is with user.{name,email} configuration variables.
>
> I wonder if it helps to give an extra line of message like the
> attached (untested) patch, though.
>
> ident.c | 51 ++++++++++++++++++++++++++++++++++-----------------
> 1 file changed, 34 insertions(+), 17 deletions(-)
>
> diff --git a/ident.c b/ident.c
> index e666ee4e59..177ac00261 100644
> --- a/ident.c
> +++ b/ident.c
> @@ -345,18 +345,35 @@ int split_ident_line(struct ident_split *split, const char *line, int len)
> return 0;
> }
>
> -static const char *env_hint =
> -N_("\n"
> - "*** Please tell me who you are.\n"
> - "\n"
> - "Run\n"
> - "\n"
> - " git config --global user.email \"you@example.com\"\n"
> - " git config --global user.name \"Your Name\"\n"
> - "\n"
> - "to set your account\'s default identity.\n"
> - "Omit --global to set the identity only in this repository.\n"
> - "\n");
> +
> +static void ident_env_hint(enum want_ident whose_ident)
> +{
> + static const char *env_hint =
> + N_("\n"
> + "*** Please tell me who you are.\n"
> + "\n"
> + "Run\n"
> + "\n"
> + " git config --global user.email \"you@example.com\"\n"
> + " git config --global user.name \"Your Name\"\n"
> + "\n"
> + "to set your account\'s default identity.\n"
> + "Omit --global to set the identity only in this repository.\n"
> + "\n");
> +
> + switch (whose_ident) {
> + case WANT_AUTHOR_IDENT:
> + fputs(_("Author identity unknown\n"), stderr);
> + break;
> + case WANT_COMMITTER_IDENT:
> + fputs(_("Committer identity unknown\n"), stderr);
> + break;
> + default:
> + break;
> + }
> +
> + fputs(_(env_hint), stderr);
> +}
>
> const char *fmt_ident(const char *name, const char *email,
> enum want_ident whose_ident, const char *date_str, int flag)
> @@ -375,12 +392,12 @@ const char *fmt_ident(const char *name, const char *email,
> if (!email) {
> if (strict && ident_use_config_only
> && !(ident_config_given & IDENT_MAIL_GIVEN)) {
> - fputs(_(env_hint), stderr);
> + ident_env_hint(whose_ident);
> die(_("no email was given and auto-detection is disabled"));
> }
> email = ident_default_email();
> if (strict && default_email_is_bogus) {
> - fputs(_(env_hint), stderr);
> + ident_env_hint(whose_ident);
> die(_("unable to auto-detect email address (got '%s')"), email);
> }
> }
> @@ -397,13 +414,13 @@ const char *fmt_ident(const char *name, const char *email,
> if (!name) {
> if (strict && ident_use_config_only
> && !(ident_config_given & IDENT_NAME_GIVEN)) {
> - fputs(_(env_hint), stderr);
> + ident_env_hint(whose_ident);
> die(_("no name was given and auto-detection is disabled"));
> }
> name = ident_default_name();
> using_default = 1;
> if (strict && default_name_is_bogus) {
> - fputs(_(env_hint), stderr);
> + ident_env_hint(whose_ident);
> die(_("unable to auto-detect name (got '%s')"), name);
> }
> }
> @@ -411,7 +428,7 @@ const char *fmt_ident(const char *name, const char *email,
> struct passwd *pw;
> if (strict) {
> if (using_default)
> - fputs(_(env_hint), stderr);
> + ident_env_hint(whose_ident);
> die(_("empty ident name (for <%s>) not allowed"), email);
> }
> pw = xgetpwuid_self(NULL);
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH] ident: say whose identity is missing when giving user.name hint
2020-08-21 19:55 ` Alvaro Aleman
@ 2020-08-21 20:36 ` Junio C Hamano
2020-08-21 20:52 ` Eric Sunshine
0 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2020-08-21 20:36 UTC (permalink / raw)
To: git; +Cc: Andreas Schwab, Alvaro Aleman
OK, so here is essentially the same patch but with a bit of cleaning
up, with a test update and a proposed log message.
-- >8 --
When the author or the committer identity is missing when required,
"git" errors out with a message that suggests to set these
configuration variables at the per-user level as the easiest way
forward. This message is given to a brand-new user, whose
~/.gitconfig hasn't been configured for user.name and user.email,
who runs "git commit --author=...", too, but such a user may find it
confusing ("why? I just gave you a name and e-mail").
State whose identity is missing as the reason why we are erroring
out, when we give the hint, to help reduce the confusion.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
ident.c | 48 ++++++++++++++++++++++-------------
t/t7518-ident-corner-cases.sh | 13 +++++++++-
2 files changed, 43 insertions(+), 18 deletions(-)
diff --git a/ident.c b/ident.c
index e666ee4e59..813741c06c 100644
--- a/ident.c
+++ b/ident.c
@@ -345,18 +345,32 @@ int split_ident_line(struct ident_split *split, const char *line, int len)
return 0;
}
-static const char *env_hint =
-N_("\n"
- "*** Please tell me who you are.\n"
- "\n"
- "Run\n"
- "\n"
- " git config --global user.email \"you@example.com\"\n"
- " git config --global user.name \"Your Name\"\n"
- "\n"
- "to set your account\'s default identity.\n"
- "Omit --global to set the identity only in this repository.\n"
- "\n");
+
+static void ident_env_hint(enum want_ident whose_ident)
+{
+ switch (whose_ident) {
+ case WANT_AUTHOR_IDENT:
+ fputs(_("Author identity unknown\n"), stderr);
+ break;
+ case WANT_COMMITTER_IDENT:
+ fputs(_("Committer identity unknown\n"), stderr);
+ break;
+ default:
+ break;
+ }
+
+ fputs(_("\n"
+ "*** Please tell me who you are.\n"
+ "\n"
+ "Run\n"
+ "\n"
+ " git config --global user.email \"you@example.com\"\n"
+ " git config --global user.name \"Your Name\"\n"
+ "\n"
+ "to set your account\'s default identity.\n"
+ "Omit --global to set the identity only in this repository.\n"
+ "\n"), stderr);
+}
const char *fmt_ident(const char *name, const char *email,
enum want_ident whose_ident, const char *date_str, int flag)
@@ -375,12 +389,12 @@ const char *fmt_ident(const char *name, const char *email,
if (!email) {
if (strict && ident_use_config_only
&& !(ident_config_given & IDENT_MAIL_GIVEN)) {
- fputs(_(env_hint), stderr);
+ ident_env_hint(whose_ident);
die(_("no email was given and auto-detection is disabled"));
}
email = ident_default_email();
if (strict && default_email_is_bogus) {
- fputs(_(env_hint), stderr);
+ ident_env_hint(whose_ident);
die(_("unable to auto-detect email address (got '%s')"), email);
}
}
@@ -397,13 +411,13 @@ const char *fmt_ident(const char *name, const char *email,
if (!name) {
if (strict && ident_use_config_only
&& !(ident_config_given & IDENT_NAME_GIVEN)) {
- fputs(_(env_hint), stderr);
+ ident_env_hint(whose_ident);
die(_("no name was given and auto-detection is disabled"));
}
name = ident_default_name();
using_default = 1;
if (strict && default_name_is_bogus) {
- fputs(_(env_hint), stderr);
+ ident_env_hint(whose_ident);
die(_("unable to auto-detect name (got '%s')"), name);
}
}
@@ -411,7 +425,7 @@ const char *fmt_ident(const char *name, const char *email,
struct passwd *pw;
if (strict) {
if (using_default)
- fputs(_(env_hint), stderr);
+ ident_env_hint(whose_ident);
die(_("empty ident name (for <%s>) not allowed"), email);
}
pw = xgetpwuid_self(NULL);
diff --git a/t/t7518-ident-corner-cases.sh b/t/t7518-ident-corner-cases.sh
index b22f631261..dc3e9c8c88 100755
--- a/t/t7518-ident-corner-cases.sh
+++ b/t/t7518-ident-corner-cases.sh
@@ -29,7 +29,18 @@ test_expect_success 'empty configured name does not auto-detect' '
sane_unset GIT_AUTHOR_NAME &&
test_must_fail \
git -c user.name= commit --allow-empty -m foo 2>err &&
- test_i18ngrep "empty ident name" err
+ test_i18ngrep "empty ident name" err &&
+ test_i18ngrep "Author identity unknown" err
+ )
+'
+
+test_expect_success 'empty configured name does not auto-detect for committer' '
+ (
+ sane_unset GIT_COMMITTER_NAME &&
+ test_must_fail \
+ git -c user.name= commit --allow-empty -m foo 2>err &&
+ test_i18ngrep "empty ident name" err &&
+ test_i18ngrep "Committer identity unknown" err
)
'
--
2.28.0-416-g2947c83ecf
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] ident: say whose identity is missing when giving user.name hint
2020-08-21 20:36 ` [PATCH] ident: say whose identity is missing when giving user.name hint Junio C Hamano
@ 2020-08-21 20:52 ` Eric Sunshine
2020-08-21 21:13 ` Junio C Hamano
0 siblings, 1 reply; 10+ messages in thread
From: Eric Sunshine @ 2020-08-21 20:52 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Git List, Andreas Schwab, Alvaro Aleman
On Fri, Aug 21, 2020 at 4:36 PM Junio C Hamano <gitster@pobox.com> wrote:
> When the author or the committer identity is missing when required,
> "git" errors out with a message that suggests to set these
> configuration variables at the per-user level as the easiest way
> forward. This message is given to a brand-new user, whose
> ~/.gitconfig hasn't been configured for user.name and user.email,
> who runs "git commit --author=...", too, but such a user may find it
> confusing ("why? I just gave you a name and e-mail").
>
> State whose identity is missing as the reason why we are erroring
> out, when we give the hint, to help reduce the confusion.
I had trouble following the first paragraph due to the run-on nature
of the second sentence. Perhaps the entire message could be rewritten
something like this:
If `user.name` and `user.email` have not been configured and the
user invokes:
git commit --author=...
without without specifying `--committer=`, then Git errors out
with a message asking the user to configure `user.name` and
`user.email` but doesn't tell the user which attribution was
missing. This can be confusing for a user new to Git who isn't
aware of the distinction between user, author, and committer.
Give such users a bit more help by extending the error message to
also say which attribution is expected.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] ident: say whose identity is missing when giving user.name hint
2020-08-21 20:52 ` Eric Sunshine
@ 2020-08-21 21:13 ` Junio C Hamano
2020-08-21 21:31 ` Alvaro Aleman
0 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2020-08-21 21:13 UTC (permalink / raw)
To: Eric Sunshine; +Cc: Git List, Andreas Schwab, Alvaro Aleman
Eric Sunshine <sunshine@sunshineco.com> writes:
> If `user.name` and `user.email` have not been configured and the
> user invokes:
>
> git commit --author=...
>
> without without specifying `--committer=`, then Git errors out
> with a message asking the user to configure `user.name` and
> `user.email` but doesn't tell the user which attribution was
> missing. This can be confusing for a user new to Git who isn't
> aware of the distinction between user, author, and committer.
> Give such users a bit more help by extending the error message to
> also say which attribution is expected.
Much easier to read. Will steal.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] ident: say whose identity is missing when giving user.name hint
2020-08-21 21:13 ` Junio C Hamano
@ 2020-08-21 21:31 ` Alvaro Aleman
2020-08-21 21:37 ` Eric Sunshine
0 siblings, 1 reply; 10+ messages in thread
From: Alvaro Aleman @ 2020-08-21 21:31 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Eric Sunshine, Git List, Andreas Schwab
One nit though: There is no `--committer` flag for `git commit`,
unless this has changed after the v2.28.0 release:
```
$ g commit -m message --committer someone@somemail.com
error: unknown option `committer'
$ git --version
git version 2.28.0
```
On Fri, Aug 21, 2020 at 5:13 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Eric Sunshine <sunshine@sunshineco.com> writes:
>
> > If `user.name` and `user.email` have not been configured and the
> > user invokes:
> >
> > git commit --author=...
> >
> > without without specifying `--committer=`, then Git errors out
> > with a message asking the user to configure `user.name` and
> > `user.email` but doesn't tell the user which attribution was
> > missing. This can be confusing for a user new to Git who isn't
> > aware of the distinction between user, author, and committer.
> > Give such users a bit more help by extending the error message to
> > also say which attribution is expected.
>
> Much easier to read. Will steal.
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] ident: say whose identity is missing when giving user.name hint
2020-08-21 21:31 ` Alvaro Aleman
@ 2020-08-21 21:37 ` Eric Sunshine
2020-08-21 22:35 ` Junio C Hamano
0 siblings, 1 reply; 10+ messages in thread
From: Eric Sunshine @ 2020-08-21 21:37 UTC (permalink / raw)
To: Alvaro Aleman; +Cc: Junio C Hamano, Git List, Andreas Schwab
On Fri, Aug 21, 2020 at 5:31 PM Alvaro Aleman <aaleman@redhat.com> wrote:
> One nit though: There is no `--committer` flag for `git commit`,
Indeed, that `--committer=` was a last-second edit (without checking
docs). How about this?
If `user.name` and `user.email` have not been configured and the
user invokes:
git commit --author=...
without specifying the committer, then Git errors out with a
message asking the user to configure `user.name` and `user.email`
but doesn't tell the user which attribution was missing. This can
be confusing for a user new to Git who isn't aware of the
distinction between user, author, and committer. Give such users
a bit more help by extending the error message to also say which
attribution is expected.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] ident: say whose identity is missing when giving user.name hint
2020-08-21 21:37 ` Eric Sunshine
@ 2020-08-21 22:35 ` Junio C Hamano
0 siblings, 0 replies; 10+ messages in thread
From: Junio C Hamano @ 2020-08-21 22:35 UTC (permalink / raw)
To: Eric Sunshine; +Cc: Alvaro Aleman, Git List, Andreas Schwab
Eric Sunshine <sunshine@sunshineco.com> writes:
> On Fri, Aug 21, 2020 at 5:31 PM Alvaro Aleman <aaleman@redhat.com> wrote:
>> One nit though: There is no `--committer` flag for `git commit`,
>
> Indeed, that `--committer=` was a last-second edit (without checking
> docs).
Yeah, I forgot that we deliberately omit the command line option for
the committer info.
> How about this?
>
> If `user.name` and `user.email` have not been configured and the
> user invokes:
>
> git commit --author=...
>
> without specifying the committer, then Git errors out with a
> message asking the user to configure `user.name` and `user.email`
> but doesn't tell the user which attribution was missing. This can
> be confusing for a user new to Git who isn't aware of the
> distinction between user, author, and committer. Give such users
> a bit more help by extending the error message to also say which
> attribution is expected.
OK.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2020-08-21 22:35 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-21 16:15 --author arg on commit only works if there is an email configured already Alvaro Aleman
2020-08-21 18:28 ` Andreas Schwab
2020-08-21 18:46 ` Junio C Hamano
2020-08-21 19:55 ` Alvaro Aleman
2020-08-21 20:36 ` [PATCH] ident: say whose identity is missing when giving user.name hint Junio C Hamano
2020-08-21 20:52 ` Eric Sunshine
2020-08-21 21:13 ` Junio C Hamano
2020-08-21 21:31 ` Alvaro Aleman
2020-08-21 21:37 ` Eric Sunshine
2020-08-21 22:35 ` Junio C Hamano
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).