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

Re: [PATCH] format-patch: output header for empty commits

From
John Keeping <john@keeping.me.uk>
Date
Mar 4, 2023, 10:45 UTC
Message-ID
<ZAMhOehmuIov/KM8@keeping.me.uk>
In-Reply-To
<xmqqwn3xg3m0.fsf@gitster.g>
On Fri, Mar 03, 2023 at 09:13:27AM -0800, Junio C Hamano wrote:
Show 9 quoted lines
> John Keeping <john@keeping.me.uk> writes:
> 
> > When formatting an empty commit, it is surprising that a totally empty
> > file is generated.  Set the flag to always print the header, matching
> > the behaviour of git-log.
> 
> Don't these empty files help send-email as safety against sending
> them out?  Unless existing tools depend on the current behaviour in
> such a way, I think this is quite a sensible change.

Yes, send-email fails trying to send an empty file, but to me this feels more like an accident than an intentional safeguard. If there were something intentional I'd expect format-patch to fail with --allow-empty as an option to bypass that safety check.

Since there are checks in place to avoid unintentionally creating empty commits, it seems reasonable for format-patch to create output that represents what is present in the repository without needing extra options.

Show 28 quoted lines
> > diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
> > index f3313b8c58..ffc7c60680 100755
> > --- a/t/t4014-format-patch.sh
> > +++ b/t/t4014-format-patch.sh
> > @@ -59,6 +59,10 @@ test_expect_success setup '
> >  	test_tick &&
> >  	git commit -m "patchid 3" &&
> >  
> > +	git checkout -b empty main &&
> > +	test_tick &&
> > +	git commit --allow-empty -m "empty commit" &&
> > +
> >  	git checkout main
> >  '
> >  
> > @@ -128,6 +132,12 @@ test_expect_success 'replay did not screw up the log message' '
> >  	grep "^Side .* with .* backslash-n" actual
> >  '
> >  
> > +test_expect_success 'format-patch empty commit' '
> > +	git format-patch --stdout main..empty >empty &&
> > +	grep "^From " empty >from &&
> > +	test_line_count = 1 from
> > +'
> > +
> >  test_expect_success 'extra headers' '
> >  	git config format.headers "To: R E Cipient <rcipient@example.com>
> >  " &&
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 6 in “format-patch: output header for empty commits”
  1. format-patch: output header for empty commitsJohn Keeping, Mar 3, 2023
  2. Junio C HamanoMar 3, 2023
  3. John KeepingMar 4, 2023
  4. Junio C HamanoMar 6, 2023
  5. John KeepingMar 8, 2023
  6. Junio C HamanoMar 8, 2023

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.