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

Re: git apply --3way behaves abnormally when the patch contains binary changes.

From
Jerry Zhang <jerry@skydio.com>
Date
Jul 27, 2021, 22:44 UTC
Message-ID
<CAMKO5Cs1HP7JNmJLYKti0kajGmD4XK+Boc3WRV2Dpph5a3b5Xw@mail.gmail.com>
In-Reply-To
<fdfd283aeee311ebbfb50024e87935e7@oschina.cn>

On Tue, Jul 27, 2021 at 7:07 AM lilinchao@oschina.cn <lilinchao@oschina.cn> wrote:

Show 26 quoted lines
>
> I see the latest change about `git apply --3way` is 923cd87, but it doesn't seem to have been fully tested
> (in t4108-apply-threeway.sh).
> On latest Git version 2.32.0, consider test case below:
> "
> test_expect_success 'apply binary file patch with --3way' '
>         # 1. on new branch, commit binary file
>         git checkout -b left &&
>         cat "$TEST_DIRECTORY"/test-binary-1.png >bin.png &&
>         git add bin.png &&
>         git commit -m "add binary file" &&
>
>         # 2. based on left_bin branch, make any change, and commit
>         git checkout -b right &&
>         cat bin.png bin.png > bin.png &&
>         git add bin.png &&
>         git commit -m "update binary file" &&
>
>         # 3. make patch
>         git diff --binary left..right >bin.diff &&
>         # apply --3way, and it will fail
>         test_must_fail git apply --index --3way bin.diff
> '
> "
>
> But  "git apply --index --3way bin.diff" will not faill on Git version 2.31.0.

Are you sure? I checked out to "commit a5828ae6b52137b913b978e16cd2334482eb4c1f (HEAD, tag: v2.31.0)" and rebuilt and ran your test snippet and it still failed.

This was the message from the failure on 2.31.0 "error: the patch applies to 'bin.png' (e69de29bb2d1d6434b8b29ae775ad8c2e48c5391), which does not match the current contents. Falling back to three-way merge... warning: Cannot merge binary files: bin.png (ours vs. theirs) Applied patch to 'bin.png' with conflicts. U bin.png"

Versus the message on 2.32.0 "warning: Cannot merge binary files: bin.png (ours vs. theirs) Applied patch to 'bin.png' with conflicts. U bin.png"

So the failure messaging is different but it returns 1 both times. Is there a difference between how we're testing?

I did have to modify your test to add
test_expect_success 'apply binary file patch with --3way' '
       # 1. on new branch, commit binary file
       git checkout -b left &&
+       git reset --hard &&
If this behavior is important I'd urge you to add this test to the suite.
>
>
Previous: lilinchao@oschina.cnNext: Junio C Hamano
Message 2 of 5 in “git apply --3way behaves abnormally when the patch contains binary changes.”
  1. lilinchao@oschina.cnJul 27, 2021
  2. Jerry ZhangJul 27, 2021
  3. Junio C HamanoJul 28, 2021
  4. Jerry ZhangJul 28, 2021
  5. lilinchao@oschina.cnJul 28, 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.