git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* "commit --author=..." does not work if global email and name is not set
@ 2019-04-05  7:34 Piotr Krukowiecki
  2019-04-05  8:11 ` Junio C Hamano
  2019-04-06 18:25 ` Jakub Narebski
  0 siblings, 2 replies; 10+ messages in thread
From: Piotr Krukowiecki @ 2019-04-05  7:34 UTC (permalink / raw)
  To: git

Hi,

I have a repo downloaded on machines which do automatic tests.
Sometimes I want to make a quick fix there and push back to origin.
Reading git-commit docs I had impression that I can use "--author=me"
and it will work. But it requires setting global user name and email:

========================================================
$ git commit --author=pkruk

*** 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 'some@default.(none)')
========================================================

I do not want to set the default name/email, because I want commits to
have real names, and not some "automatic test account" info. For
pushing back to origin I already have to use a read-write SSH key, but
lack of default name/email would prevent accidental commits (people
WILL forget to use --author ...).

Do you think changing git to not require default name/email if
"--author" is specified is possible (and hopefully easy and quick to
implement ;))?

Thanks,

-- 
Piotr Krukowiecki

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "commit --author=..." does not work if global email and name is not set
  2019-04-05  7:34 "commit --author=..." does not work if global email and name is not set Piotr Krukowiecki
@ 2019-04-05  8:11 ` Junio C Hamano
  2019-04-06 18:25 ` Jakub Narebski
  1 sibling, 0 replies; 10+ messages in thread
From: Junio C Hamano @ 2019-04-05  8:11 UTC (permalink / raw)
  To: Piotr Krukowiecki; +Cc: Git Mailing List

On Fri, Apr 5, 2019 at 4:35 PM Piotr Krukowiecki
<piotr.krukowiecki@gmail.com> wrote:
>
> Hi,
>
> I have a repo downloaded on machines which do automatic tests.
> Sometimes I want to make a quick fix there and push back to origin.
> Reading git-commit docs I had impression that I can use "--author=me"
> and it will work. But it requires setting global user name and email:

You can still do

 git -c user.name=me -c user.email=me@my.addre.ss commit ...

if you do not want to follow the advice message to store the ident
permanently.

>   git config --global user.email "you@example.com"
>   git config --global user.name "Your Name"

Technically, what you are missing when you give --author is only
the committer ident, so you can probably use

  GIT_COMMITTER_NAME=me GIT_COMMITTER_EMAIL=me@my.addre.ss \
  git commit --author=me ...

even though it is not any shorter ;-).

I think all of the above is quite expected. The fact that --author is used to
specify the ident of the author is a good sign that it is different from the
committer ident (otherwise the user would be using a configured default
ident that is always used as the committer ident, without overriding it
with the --author) option.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "commit --author=..." does not work if global email and name is not set
  2019-04-05  7:34 "commit --author=..." does not work if global email and name is not set Piotr Krukowiecki
  2019-04-05  8:11 ` Junio C Hamano
@ 2019-04-06 18:25 ` Jakub Narebski
  2019-04-08  6:57   ` Junio C Hamano
  1 sibling, 1 reply; 10+ messages in thread
From: Jakub Narebski @ 2019-04-06 18:25 UTC (permalink / raw)
  To: Piotr Krukowiecki; +Cc: git

Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:

> Hi,
>
> I have a repo downloaded on machines which do automatic tests.
> Sometimes I want to make a quick fix there and push back to origin.
> Reading git-commit docs I had impression that I can use "--author=me"
> and it will work. But it requires setting global user name and email:
>
> ========================================================
> $ git commit --author=pkruk
>
> *** 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 'some@default.(none)')
> ========================================================
>
> I do not want to set the default name/email, because I want commits to
> have real names, and not some "automatic test account" info. For
> pushing back to origin I already have to use a read-write SSH key, but
> lack of default name/email would prevent accidental commits (people
> WILL forget to use --author ...).
>
> Do you think changing git to not require default name/email if
> "--author" is specified is possible (and hopefully easy and quick to
> implement ;))?

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@email.my".

In Git the commit stories both the author and the committer.  The author
is the person who made the changes, the committer is the person who
entered the changes into repository (created a commit object).  You
might want to enter into your repository changes made by somebody else
(that you for example got as a patch): that is what --author is for.

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

Hope that helps,
--
Jakub Narębski

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "commit --author=..." does not work if global email and name is not set
  2019-04-06 18:25 ` Jakub Narebski
@ 2019-04-08  6:57   ` Junio C Hamano
  2019-04-08  9:54     ` Piotr Krukowiecki
  0 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2019-04-08  6:57 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: Piotr Krukowiecki, git

Jakub Narebski <jnareb@gmail.com> 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@email.my".

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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "commit --author=..." does not work if global email and name is not set
  2019-04-08  6:57   ` Junio C Hamano
@ 2019-04-08  9:54     ` Piotr Krukowiecki
  2019-04-08 11:06       ` Jakub Narebski
  0 siblings, 1 reply; 10+ messages in thread
From: Piotr Krukowiecki @ 2019-04-08  9:54 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jakub Narebski, git

On Fri, Apr 5, 2019 at 10:12 AM Junio C Hamano <gitster@pobox.com> wrote:
> You can still do
>
>  git -c user.name=me -c user.email=me@my.addre.ss commit ...
[...]
>   GIT_COMMITTER_NAME=me GIT_COMMITTER_EMAIL=me@my.addre.ss \
>   git commit --author=me ...
>
> even though it is not any shorter ;-).

There are a couple of problems with this approach:

1. it's long, as you mentioned
2. it's easy to make a mistake - misspell name or address
3. you need to remember the options/variable names ("-c", user.name
or GIT_COMMITER_NAME etc) - it's not user friendly

If you make a mistake you end up with two different identities in
history. Then e.g. searching for an author might not find all commits.


On Mon, Apr 8, 2019 at 8:57 AM Junio C Hamano <gitster@pobox.com> wrote:
> 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.

Yes it would. But I understand your arguments too.

Maybe instead of changing how "--author" works, we could add
"--commiter" which works the same but for commiter, that is searches
for committer in history? Then I could do "git commit --commiter=me".

On the other hand this makes commiter somehow more important than
author. The "author" is more obvious to users I think. When both
author and commiter are the same, git shows the author only. In svn
(and I think also in mercurial) there is only "author".
So the first thought for users is "I should set the author", I
believe. At least it was like that for me. From this point of view, I
think the author should be more important. So I would prefer to be
able to use "git commit --author=me" and have it work, instead of
using "--commiter" which I believe is an implementation detail... I
don't want to set the commiter, I want to set the author of the
commit.

So another possibility: add "--user=me" which would set both(?) author
and commiter. I don't like that we would add another "idiom"
("author", "commiter", and now "user") but OTOH we already have
"user.name" and "user.email" configuration names.


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


-- 
Piotr Krukowiecki

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "commit --author=..." does not work if global email and name is not set
  2019-04-08  9:54     ` Piotr Krukowiecki
@ 2019-04-08 11:06       ` Jakub Narebski
  2019-04-08 11:55         ` Piotr Krukowiecki
  0 siblings, 1 reply; 10+ messages in thread
From: Jakub Narebski @ 2019-04-08 11:06 UTC (permalink / raw)
  To: Piotr Krukowiecki; +Cc: Junio C Hamano, git

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "commit --author=..." does not work if global email and name is not set
  2019-04-08 11:06       ` Jakub Narebski
@ 2019-04-08 11:55         ` Piotr Krukowiecki
  2019-04-09  6:31           ` Junio C Hamano
  2019-04-09  7:43           ` Jakub Narebski
  0 siblings, 2 replies; 10+ messages in thread
From: Piotr Krukowiecki @ 2019-04-08 11:55 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: Junio C Hamano, git

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.


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


-- 
Piotr Krukowiecki

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "commit --author=..." does not work if global email and name is not set
  2019-04-08 11:55         ` Piotr Krukowiecki
@ 2019-04-09  6:31           ` Junio C Hamano
  2019-04-09  7:03             ` Piotr Krukowiecki
  2019-04-09  7:43           ` Jakub Narebski
  1 sibling, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2019-04-09  6:31 UTC (permalink / raw)
  To: Piotr Krukowiecki; +Cc: Jakub Narebski, git

Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:

>> 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.
> ...
> 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
> 4. real users will set AUTHOR to their own identity (--author=me)

I do not think 4. is what Jakub meant, which is to make the author
and committer identity for real humans come from the configuration
that becomes in effect automatically by merely logging in.

If that cannot be arranged, something like 4. may have to serve as a
rough approximation; that sound like the best you could do under
that limitation without breaking the general usability of the
system.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "commit --author=..." does not work if global email and name is not set
  2019-04-09  6:31           ` Junio C Hamano
@ 2019-04-09  7:03             ` Piotr Krukowiecki
  0 siblings, 0 replies; 10+ messages in thread
From: Piotr Krukowiecki @ 2019-04-09  7:03 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jakub Narebski, git

On Tue, Apr 9, 2019 at 8:31 AM Junio C Hamano <gitster@pobox.com> wrote:
> I do not think 4. is what Jakub meant, which is to make the author
> and committer identity for real humans come from the configuration
> that becomes in effect automatically by merely logging in.

Unfortunately this is not possible


> If that cannot be arranged, something like 4. may have to serve as a
> rough approximation; that sound like the best you could do under
> that limitation without breaking the general usability of the
> system.

What do you think about my "--user" idea?


-- 
Piotr Krukowiecki

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "commit --author=..." does not work if global email and name is not set
  2019-04-08 11:55         ` Piotr Krukowiecki
  2019-04-09  6:31           ` Junio C Hamano
@ 2019-04-09  7:43           ` Jakub Narebski
  1 sibling, 0 replies; 10+ messages in thread
From: Jakub Narebski @ 2019-04-09  7:43 UTC (permalink / raw)
  To: Piotr Krukowiecki; +Cc: Junio C Hamano, git

Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:
> 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...

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-04-09  7:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-05  7:34 "commit --author=..." does not work if global email and name is not set Piotr Krukowiecki
2019-04-05  8:11 ` Junio C Hamano
2019-04-06 18:25 ` Jakub Narebski
2019-04-08  6:57   ` Junio C Hamano
2019-04-08  9:54     ` Piotr Krukowiecki
2019-04-08 11:06       ` Jakub Narebski
2019-04-08 11:55         ` Piotr Krukowiecki
2019-04-09  6:31           ` Junio C Hamano
2019-04-09  7:03             ` Piotr Krukowiecki
2019-04-09  7:43           ` Jakub Narebski

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