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

Re: Git commit amend empty emails

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 10, 2014, 18:46 UTC
Message-ID
<xmqqmw6vgx6v.fsf@gitster.dls.corp.google.com>
In-Reply-To
<20141210153952.GA14910@peff.net>
Jeff King <peff@peff.net> writes:
Show 6 quoted lines
> However, there's something else going on. I am surprised that we allow
> empty emails at all and the code here is quite strange. The first check
> on the ident format is when we feed the data to fmt_ident to generate
> the string that goes into the commit object.  We disallow empty _names_
> there, but not empty _emails_.  I'm not sure if this is an oversight, or
> an intentional historic compatibility thing.

Looking at e27ddb6 you cited, I think we knew about historical mistakes that allowed an empty names, but not an empty e-mail address. We probably have tried to kill both in one stone.

Show 7 quoted lines
> Once upon a time, it relied only on split_ident_lane to report problems.
> But Junio's e27ddb6 (split_ident_line(): make best effort when parsing
> author/committer line, 2012-08-31) made split_ident_line more lenient,
> and introduced sane_ident_split to cover the difference. Except that it
> did more than that: besides checking whether the name is empty (which
> the original split_ident_line used to do), it also complains if the
> email is empty (which is new in that commit).
Show 5 quoted lines
> So we now notice the empty email in this code path, but the only thing
> we do is avoid writing out the environment variables and continue. Which
> means that the actual string generated by fmt_ident (complete with empty
> email) is what goes into the commit. So why are we setting the
> environment variables at all?
I think that part was more underthinking than oversight.

We didn't want to abort the commit but we didn't want to contaminate the environment variables with known-to-be-bad values to spread the problem further. But there is no guarantee that not exporting the environment variables would give us more comformant name and e-mail address, so that thinking is flawed.

Show 21 quoted lines
> Here are two patches to improve this. These are on top of the
> jk/commit-date-approxidate topic, as that is where the regression was
> introduced.
>
> The first one fixes the regression and can stand by itself. The second
> fixes the GIT_AUTHOR problem, but AFAIK that has been there for years.
> So it is not as urgent, but is still maint-worthy, in my opinion.
>
>   [1/2]: commit: loosen ident checks when generating template
>   [2/2]: commit: always populate GIT_AUTHOR_* variables
>
> If we did want to truly disallow empty emails, we could do a follow-on
> 3/2 that teaches fmt_ident to reject them (that is the right place
> because it is where the validation checks for the author go, and also
> because we would probably want the same validation for the committer).
>
> But I do not think we should do that lightly. It has been this way for
> years, and clearly at least one person is depending on it. If we're
> going to change it, we might want a warning/deprecation period.
>
> -Peff
Previous: Jeff KingNext: Jeff King
Message 6 of 7 in “Git commit amend empty emails”
  1. SimonDec 10, 2014
  2. Jeff KingDec 10, 2014
  3. 1/2 commit: loosen ident checks when generating templateJeff King, Dec 10, 2014
  4. Eric SunshineDec 11, 2014
  5. 2/2 commit: always populate GIT_AUTHOR_* variablesJeff King, Dec 10, 2014
  6. Junio C HamanoDec 10, 2014
  7. Jeff KingDec 10, 2014

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.