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 20, 2021, 06:46 UTC
Message-ID
<2119ea2a7b8cd3cb3a84d69b9a9f4471f645667d.camel@redhat.com>
In-Reply-To
<YR9Iaj/FqAyCMade@tilde.club>
On Fri, 2021-08-20 at 06:15 +0000, Gwyneth Morgan wrote:
Show 22 quoted lines
> On 2021-08-19 14:09:43-0700, Junio C Hamano wrote:
> > 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.
> 
> GNU patch chokes in this case with an unquoted filename with spaces.
> However if we output
> 
> 	diff --git "a/test cases/common/56 array methods/a.txt" "b/test cases/common/56 array methods/a.txt"
> 
> instead of
> 
> 	diff --git a/test cases/common/56 array methods/a.txt b/test cases/common/56 array methods/a.txt
> 
> GNU patch (and Git) will read it correctly. Rather than adding the "---"
> "+++" lines, could we instead quote filenames in the "diff --git" line
> when they contain spaces?

Aha, I did actually wonder about that, because even with the added lines, the patches don't apply (via `patch`) on Fedora 33 and 34 (and the error message after adding the lines does seem to indicate the spaces in the filenames as the culprit). They only apply on Fedora 35 and 36. I hadn't thought to just add quote marks, though of course it seems obvious now. So yeah, that seems likely to be the best fix. I'll try and confirm your results tomorrow. Thanks!

-- 
Adam Williamson
Fedora QA
IRC: adamw | Twitter: adamw_ha
https://www.happyassassin.net
Previous: Gwyneth MorganNext: Junio C Hamano
Message 5 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.