git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: --author arg on commit only works if there is an email configured already

From
AAAlvaro Aleman <aaleman@redhat.com>
Date
Aug 21, 2020, 19:55 UTC
Message-ID
<CAOW=8D3WZyoc=PpyzmPRYM2MT_=F4tnuTxJ0Z+_dHMb4Xk8imQ@mail.gmail.com>
In-Reply-To
<xmqqr1rz96ry.fsf@gitster.c.googlers.com>

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:
Show 114 quoted lines
>
> 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);
>
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 10 in “--author arg on commit only works if there is an email configured already”
  1. Alvaro AlemanAug 21, 2020
  2. Andreas SchwabAug 21, 2020
  3. Junio C HamanoAug 21, 2020
  4. Alvaro AlemanAug 21, 2020
  5. ident: say whose identity is missing when giving user.name hintJunio C Hamano, Aug 21, 2020
  6. Eric SunshineAug 21, 2020
  7. Junio C HamanoAug 21, 2020
  8. Alvaro AlemanAug 21, 2020
  9. Eric SunshineAug 21, 2020
  10. Junio C HamanoAug 21, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.