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

Re: "commit --author=..." does not work if global email and name is not set

From
Jakub Narebski <jnareb@gmail.com>
Date
Apr 9, 2019, 07:43 UTC
Message-ID
<86tvf7mxni.fsf@gmail.com>
In-Reply-To
<CAA01CspJAPnBFsQsXP4Dpweeg6oBVj==TB0aEnK5o1Et5zS30Q@mail.gmail.com>
Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:
Show 28 quoted lines
> On Mon, Apr 8, 2019 at 1:06 PM Jakub Narebski <jnareb@gmail.com> wrote:
>> Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:
>>>> On Sat, Apr 6, 2019 at 8:25 PM Jakub Narebski <jnareb@gmail.com> wrote:
>>>>>
>>>>> Better though is to focus on what you want, namely to prevent accidental
>>>>> commits without specified author, instead of how you want to achieve it,
>>>>> i.e. using --author to provide both author and committer identity (the
>>>>> XY problem).  On that machine with "automatic test account" set up
>>>>> pre-commit or commit-msg hook that fails if the GIT_AUTHOR_IDENT
>>>>> environment variable is not the "automatic test account".
>>>
>>> I'm not sure if I follow you. I want to be able to make both "real
>>> user" and "automatic test account user" commits from that machine. I
>>> want to make sure that:
>>> - automatic commits (scripts) use their own account
>>> - real person making commit uses their own account
>>>
>>> IMO the only way this can be achieved is by not having any default
>>> account setup, so that both the scripts and the real users need to
>>> specify it "by hand".
>>
>> If a real person making commits uses their own account (just on that
>> machine), he or she can set up `user.name` and `user.email` settings in
>> the per-user Git configuration file
>
> There is one common "test" (Windows) account which is used both by
> automatic test scripts and by real people who log into that machine,
> so this is not possible.

Well, if it is not possible to make it multi-account machine, where everybody logins with their own account...

Show 17 quoted lines
>> If however one is doing commits from the "automatic test user" account,
>> then the `pre-commit` or `commit-msg` hook configured for that specific
>> repository for that automatic account would be run, which can detect
>> that the commit was not done with
>>
>>   $ git commit --author="My Name <me@my.email.com>"
>>
>> The additional advantage is that you can examine committer data to
>> detect such cases of committing out of automatic account.
>
> Do you mean following?
>
> 1. set default user (user.name, user.email) to "automatic test user"
> on that machine
> 2. set commit hook to prevent commits with "automatic test user" AUTHOR
> 3. scripts will set AUTHOR (--author) to for example "script X" or
> "automatic script user" - different than the default user

Or, if possible, you could simply check if `git commit` was called from a login shell / interactive shell, rather than from a script. This would make all scripts work automatically without any changes.

Alternatively scripts could set some special environment variable that would be checked by the commit hook.

> 4. real users will set AUTHOR to their own identity (--author=me)
>
> I suppose that would work. Looks much more complicated than simply
> setting "--author" (or "--user") though...
however, it is one-time configuration.

Yet another solution would be for each user to create his or her own clone of repository (sharing repository data using `git clone --reference`), and set up their identities in per-repository configuration. Though that requires them to use the correct directory...

Best, -- Jakub Narębski

Previous: Piotr Krukowiecki
Message 10 of 10 in “"commit --author=..." does not work if global email and name is not set”
  1. Piotr KrukowieckiApr 5, 2019
  2. Junio C HamanoApr 5, 2019
  3. Jakub NarebskiApr 6, 2019
  4. Junio C HamanoApr 8, 2019
  5. Piotr KrukowieckiApr 8, 2019
  6. Jakub NarebskiApr 8, 2019
  7. Piotr KrukowieckiApr 8, 2019
  8. Junio C HamanoApr 9, 2019
  9. Piotr KrukowieckiApr 9, 2019
  10. Jakub NarebskiApr 9, 2019

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.