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

Re: git format-patch produces invalid patch if the commit adds an empty file?

From
Adam Williamson <awilliam@redhat.com>
Date
Aug 19, 2021, 21:25 UTC
Message-ID
<953c8ccbbb282850191b199345465dac485b933e.camel@redhat.com>
In-Reply-To
<xmqq5yw1ywdk.fsf@gitster.g>
On Thu, 2021-08-19 at 14:09 -0700, Junio C Hamano wrote:
Show 28 quoted lines
> Adam Williamson <awilliam@redhat.com> writes:
> 
> > Hi folks! So I ran into an odd issue with git today. I'm kinda
> > surprised I can't find any prior discussion of it, but oh well. The
> > situation is this: I ran git format-patch on a commit that adds three
> > empty files to a repository - this commit:
> > https://github.com/mesonbuild/meson/commit/5c87167a34c6ed703444af180fffd8a45a7928ee
> > the relevant lines from the patch file it produced look like this:
> > 
> > ===
> > 
> > diff --git a/test cases/common/56 array methods/a.txt b/test cases/common/56 array methods/a.txt
> > new file mode 100644
> > index 000000000..e69de29bb
> > diff --git a/test cases/common/56 array methods/b.txt b/test cases/common/56 array methods/b.txt
> > new file mode 100644
> > index 000000000..e69de29bb
> > diff --git a/test cases/common/56 array methods/c.txt b/test cases/common/56 array methods/c.txt
> > new file mode 100644
> > index 000000000..e69de29bb
> 
> I do not have very ancient build of Git handy, but I know Git as old
> as v1.3.0 (which I consider is one of the two versions of historical
> importance, the other being v1.5.3) behaved this way and we haven't
> changed it ever since, so I am surprised too to learn that "GNU
> patch" cannot grok it.  Even though you didn't mention it, am I
> correct to assume that "patch" has a similar issue with a change
> that removes an empty file?
Hi Junio!
I didn't test that. It does seem likely, though.
Show 8 quoted lines
> I do not think our patch injestion machinery in "git apply" minds if
> we added the "--- /dev/null" + "+++ b/<path>" headers (and the
> reverse for removal of an empty file) to the current output, and I
> am not fundamentally opposed to such a change.
> 
> But because it is such a rare event (and a discouraged practice) to
> record a completely empty file, I wouldn't place a high priority on
> doing so myself.
Thanks.
-- 
Adam Williamson
Fedora QA
IRC: adamw | Twitter: adamw_ha
https://www.happyassassin.net
Previous: Junio C HamanoNext: Gwyneth Morgan
Message 3 of 6 in “git format-patch produces invalid patch if the commit adds an empty file?”
  1. Adam WilliamsonAug 17, 2021
  2. Junio C HamanoAug 19, 2021
  3. Adam WilliamsonAug 19, 2021
  4. Gwyneth MorganAug 20, 2021
  5. Adam WilliamsonAug 20, 2021
  6. Junio C HamanoAug 20, 2021

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.