From: Junio C Hamano <gitster@pobox.com>
To: "Hongren (Zenithal) Zheng" <i@zenithal.me>
Cc: Jerry Zhang <jerry@skydio.com>, git@vger.kernel.org
Subject: Re: [PATCH] apply: fix delete-then-new patch fail with 3way
Date: Sat, 16 Oct 2021 23:08:04 -0700 [thread overview]
Message-ID: <xmqqv91wyyij.fsf@gitster.g> (raw)
In-Reply-To: YWsbcbASLG3QNPyZ@Sun
"Hongren (Zenithal) Zheng" <i@zenithal.me> writes:
> On Sun, Oct 03, 2021 at 07:25:29PM +0800, Hongren (Zenithal) Zheng wrote:
>> For one single patch FILE containing both deletion and creation
>> of the same file, applying with three way would fail, which should not.
>> ...
Sigh.
Jerry, it seems that the earlier "let's be more aggressive to use
--3way, instead of using it as a fallback" is turning out to be more
and more trouble than we hoped.
One thing to notice about the patch used for this test is that ...
>> +test_expect_success 'apply delete then new patch with 3way' '
>> + git reset --hard main &&
>> + test_write_lines 1 > delnew &&
>> + git add delnew &&
>> + git commit -m "delnew" &&
>> + cat >delete-then-new.patch <<-\EOF &&
>> + --- a/delnew
>> + +++ /dev/null
>> + @@ -1 +0,0 @@
>> + -1
>> + --- /dev/null
>> + +++ b/delnew
>> + @@ -0,0 +1 @@
>> + +2
>> + EOF
... this is clearly not a patch that was generated by Git. We do
not show two separate patches, to delete and then to create, the
same path to express a file modification, and that is true even when
we are showing a total-rewrite patch.
In addition, the above set of two patches lack the "index" header
that records the old and new blob object name, because it is not a
patch generated by Git. Whether 3-way is attempted before or after
the normal application, because the object names there are a crucial
ingredient for the 3-way merge logic, there is no way for it to work
at all.
>> + # Apply must succeed.
>> + git apply --3way delete-then-new.patch
So, one simple and safe answer would be "Don't do it, --3way is only
about Git patches." IOW, the command is failing as designed.
To extend and automate the solution would be to see, just before
attempting to do the 3-way, if the incoming patch is a Git generated
one, and do not even bother using the 3-way logic if it is not.
next prev parent reply other threads:[~2021-10-17 6:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-03 11:25 [PATCH] apply: fix delete-then-new patch fail with 3way Hongren (Zenithal) Zheng
2021-10-16 18:35 ` Hongren (Zenithal) Zheng
2021-10-17 6:08 ` Junio C Hamano [this message]
2021-10-19 18:56 ` Jerry Zhang
2021-11-04 11:16 ` Hongren (Zenithal) Zheng
2021-12-11 1:53 ` Jerry Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqv91wyyij.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=i@zenithal.me \
--cc=jerry@skydio.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).