Re: "commit --author=..." does not work if global email and name is not set
- From
Jakub Narebski <jnareb@gmail.com>
- Date
- Apr 8, 2019, 11:06 UTC
- Message-ID
- <86y34kn4c8.fsf@gmail.com>
- In-Reply-To
- <CAA01CsqAt8osKArhdgATNj29+a9VO6wUwhX6=cRebnDBFx_EVg@mail.gmail.com>
Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:
Show 18 quoted lines
>> 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 with
$ git config --global user.name "My Name" $ git config --global user.email me@my.email.com
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.
I hope that helps, -- Jakub Narębski