From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4DE14C433EF for ; Sun, 17 Oct 2021 06:08:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B61C61050 for ; Sun, 17 Oct 2021 06:08:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244983AbhJQGKT (ORCPT ); Sun, 17 Oct 2021 02:10:19 -0400 Received: from pb-smtp1.pobox.com ([64.147.108.70]:52254 "EHLO pb-smtp1.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232681AbhJQGKT (ORCPT ); Sun, 17 Oct 2021 02:10:19 -0400 Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id B6A84E41FE; Sun, 17 Oct 2021 02:08:08 -0400 (EDT) (envelope-from junio@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:message-id:mime-version:content-type; s=sasl; bh=VYOeia83bWMwbhcTBQrwDmTyqSPze7YrXORKOvoJe7w=; b=eIAR hB+Om5XhtYrbGHMpI416TO3two2FEgXaHEfnlGO2kmp0D2mgKDnxEsM684D/FIa0 Vg7Amdj4WoxVkEAMX5txtajB570Tdxax+8Vjg2CkITCb8eTNhZHOkJpOkQL1nWaU A7EZLgUfEaMSFjVf+7jDFYhMN/tDMeKN6POkJzo= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 6C359E41FC; Sun, 17 Oct 2021 02:08:07 -0400 (EDT) (envelope-from junio@pobox.com) Received: from pobox.com (unknown [104.133.2.91]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 1F64DE41FB; Sun, 17 Oct 2021 02:08:06 -0400 (EDT) (envelope-from junio@pobox.com) From: Junio C Hamano To: "Hongren (Zenithal) Zheng" Cc: Jerry Zhang , git@vger.kernel.org Subject: Re: [PATCH] apply: fix delete-then-new patch fail with 3way References: Date: Sat, 16 Oct 2021 23:08:04 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: 983871FE-2F10-11EC-A2D7-62A2C8D8090B-77302942!pb-smtp1.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org "Hongren (Zenithal) Zheng" 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.