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

Re: Bug in 'git am' when applying a broken patch

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 26, 2015, 20:58 UTC
Message-ID
<xmqq7fqqtceq.fsf@gitster.dls.corp.google.com>
In-Reply-To
<CAGZ79kYbyTOeEvJBPqWOX8fxbB637N5aV3Q=yENQXu4v9FzBPQ@mail.gmail.com>
Stefan Beller <sbeller@google.com> writes:
Show 5 quoted lines
> In the hunk header we can learn about the
> expected lines to read for this hunk and after the hunk we only have
> 3 possible lines:
>
>   * it's the next hunk, then the line starts with @@
This is true.
>   * it's a new file, so the line starts with "diff --git"
This is true with s/--git//.
>   * it's the end of the patch, so the line is "--\n" and the line there after
>     is version number as git describe puts (not sure we want to test on that)

This is not true in general, as we do not want to limit "git apply" to only what "git diff" produces. You can write anything after a patch and that is still a valid patch. And that anything could be a line that begins with '-', ' ' and '+'; as long as the line numbers in the hunk header are correct, we'd ignore it.

So as you said, the change you are responding to is "better than nothing", and would only help when you truncate the patch (or break the numbers), but does not protect against arbitrary breakage.

One thing we _could_ do is after seeing the end of a message (i.e. we did not see "@@" that signals there are more hunks in the current patch, and we did not see "diff " that signals there are more patches), we keep scanning and declare breakage if we see lines that begin with something that looks like a hunk "@@ ... @@".

Previous: Stefan Beller
Message 10 of 10 in “Bug in 'git am' when applying a broken patch”
  1. Greg KHJun 1, 2015
  2. Greg KHJun 1, 2015
  3. Christian CouderJun 1, 2015
  4. Junio C HamanoJun 1, 2015
  5. Junio C HamanoJun 1, 2015
  6. Eric SunshineJun 1, 2015
  7. Junio C HamanoJun 1, 2015
  8. Greg KHJun 2, 2015
  9. Stefan BellerJun 26, 2015
  10. Junio C HamanoJun 26, 2015

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.