Web lists-archives.com

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




Jakub Narebski <jnareb@xxxxxxxxx> writes:

> As Junio said, the "--author=<author name and email>" sets the author
> identity, but not the committer identity; you can work around the issue
> with "git -c user.name=me -c user.email=me@xxxxxxxx".

Having slept on this a bit, I am of two minds here.

It certainly is possible to change the rule to say that committer
identity, when not set at all, takes the default from the author
identity, if and only if the latter is explicitly given, and that
would certainly make it work as Piotr wanted to.

But then, that is only valid if the users use --author with the
author make that refers to self every time s/he makes a commit.  I
am not sure if that is a plausible use case.  The command line
option "--author" is really meant to be used one-off to name
somebody other than self in a rare occasion.  Use of --author that
breaks the built-in safety of committing under undesired identity
(e.g. "<user@localhost>") without realizing before the mistake is
buried deep in the history may not be such a goodidea.

> 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".

It could be s/is not/is/ perhaps, but I do like the line of
reasoning and where it leads us.  "To prevent mistakes" is something
hooks are good for.

Thanks.