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

Re: [BUG] Apply patches failed without any changes

From
Jeff King <peff@peff.net>
Date
Nov 18, 2024, 10:15 UTC
Message-ID
<20241118101521.GB3991628@coredump.intra.peff.net>
In-Reply-To
<CAGtHOOFutv6wHgoFnkZoETJwq6FDkbbBgGqzSXT9V7ESXQswCg@mail.gmail.com>
On Sun, Nov 17, 2024 at 08:40:06PM +0800, Ylarod wrote:
Show 17 quoted lines
> ```
> Applying: Florida: string_frida_rpc
> Applying: Florida: frida_agent_so
> Applying: Florida: symbol_frida_agent_main
> .git/rebase-apply/patch:126: trailing whitespace.
> 
> error: patch failed: lib/agent/frida-agent.def:1
> error: lib/agent/frida-agent.def: patch does not apply
> error: patch failed: tests/labrats/agent.def:1
> error: tests/labrats/agent.def: patch does not apply
> Patch failed at 0003 Florida: symbol_frida_agent_main
> hint: Use 'git am --show-current-patch=diff' to see the failed patch
> hint: When you have resolved this problem, run "git am --continue".
> hint: If you prefer to skip this patch, run "git am --skip" instead.
> hint: To restore the original branch and stop patching, run "git am --abort".
> hint: Disable this message with "git config advice.mergeConflict false"
> ```
Your .def files have CRLF line endings:
  $ git show --oneline 357374cfbbcb '*/frida-agent.def' | cat -A
  357374cf Florida: symbol_frida_agent_main$
  diff --git a/lib/agent/frida-agent.def b/lib/agent/frida-agent.def$
  index 7634e3fd..dc297d6f 100644$
  --- a/lib/agent/frida-agent.def$
  +++ b/lib/agent/frida-agent.def$
  @@ -1,2 +1,2 @@$
   EXPORTS^M$
  -^Ifrida_agent_main^M$
  +^Imain^M$

The email format created by format-patch puts the diff inline in a text/plain email part. And since emails use CRLF as the line terminator, they are stripped when it is read back in by git-am. So it tries to apply the change above _without_ the extra CR, and we fail to find the context.

You can use "git am --keep-cr" to retain the literal line endings on the diff. This would work for the commands you showed above, but I suspect would be a problem if you were actually sending the emails to somebody else (since the mail transport would probably normalize everything to CRLF).

To robustly send them you'd either have to:
  - send a binary patch. I don't think there's an easy way to ask for
    this for a particular format-patch invocation. You'd probably have
    to mark them with .gitattributes which would also suppress diffs,
    etc.
  - store the files in the repository with regular LF endings. If it's
    important that they have CRLF in the working tree, you can use
    attributes to convert them on checkout. See "End-of-line conversion"
    in "git help attributes".
-Peff
Previous: Ylarod
Message 2 of 2 in “[BUG] Apply patches failed without any changes”
  1. YlarodNov 17, 2024
  2. Jeff KingNov 18, 2024

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.