Article View: linux.kernel.git
Article #2573[PATCH] merge: honor --no-overwrite-ignore for real merges
From: Aniket Gupta
Date: Sat, 07 Nov 2026 04:44
Date: Sat, 07 Nov 2026 04:44
139 lines
15246 bytes
15246 bytes
"git merge --no-overwrite-ignore" is meant to abort instead of
overwriting an ignored file that is in the way. However, only a
fast-forward honors it. When a real merge is needed, ort and recursive
overwrite the ignored file whatever the option says. Two FIXME comments
in merge-ort.c and builtin/merge.c mark where it was never passed along.
Add a preserve_ignored bit to struct merge_options then set it from the
option and use it where merge-ort updates the working tree. The
trivial-merge path in builtin/merge.c gets the same treatment. Other
callers of merge-ort leave the bit unset so nothing will change for
them.
Add tests for a plain merge and for a directory rename.
Reported-by: Coy Geek <coygeek@gmail.com>
Signed-off-by: Aniket Gupta <aniketgupta3001@gmail.com>
---
builtin/merge.c | 3 ++-
merge-ort.c | 2 +-
merge-ort.h | 1 +
t/t7600-merge.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 63 insertions(+), 2 deletions(-)
diff --git a/builtin/merge.c b/builtin/merge.c
index 5b4eb23a83..c7cd3ce29e 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -756,7 +756,7 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,
opts.verbose_update = 1;
opts.trivial_merges_only = 1;
opts.merge = 1;
- opts.preserve_ignored = 0; /* FIXME: !overwrite_ignore */
+ opts.preserve_ignored = !overwrite_ignore;
trees[nr_trees] = repo_parse_tree_indirect(the_repository, common);
if (!trees[nr_trees++])
return -1;
@@ -812,6 +812,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
}
init_ui_merge_options(&o, the_repository);
+ o.preserve_ignored = !overwrite_ignore;
if (!strcmp(strategy, "subtree"))
o.subtree_shift = "";
diff --git a/merge-ort.c b/merge-ort.c
index c410a5d353..38dd1ac99d 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -4632,7 +4632,7 @@ static int checkout(struct merge_options *opt,
unpack_opts.quiet = 0; /* FIXME: sequencer might want quiet? */
unpack_opts.verbose_update = (opt->verbosity > 2);
unpack_opts.fn = twoway_merge;
- unpack_opts.preserve_ignored = 0; /* FIXME: !opts->overwrite_ignore */
+ unpack_opts.preserve_ignored = opt->preserve_ignored;
if (repo_parse_tree(opt->repo, prev) < 0)
return -1;
init_tree_desc(&trees[0], &prev->object.oid, prev->buffer, prev->size);
diff --git a/merge-ort.h b/merge-ort.h
index 6045579825..d5747f358e 100644
--- a/merge-ort.h
+++ b/merge-ort.h
@@ -85,6 +85,7 @@ struct merge_options {
unsigned renormalize : 1;
unsigned mergeability_only : 1; /* exit early, write fewer objects */
unsigned record_conflict_msgs_as_headers : 1;
+ unsigned preserve_ignored : 1; /* do not overwrite ignored files */
const char *msg_header_prefix;
/* internal fields used by the implementation */
diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh
index 64fe21717d..c1150e50e0 100755
--- a/t/t7600-merge.sh
+++ b/t/t7600-merge.sh
@@ -1179,4 +1179,63 @@ test_expect_success 'merge with no argument defaults to upstream' '
)
'
+test_expect_success 'merge --no-overwrite-ignore keeps an ignored file in the way' '
+ test_when_finished "rm -rf ignored" &&
+ git init ignored &&
+ (
+ cd ignored &&
+ echo secret >.gitignore &&
+ git add .gitignore &&
+ test_tick &&
+ git commit -m base &&
+ git checkout -b side &&
+ echo side >secret &&
+ git add -f secret &&
+ test_tick &&
+ git commit -m side &&
+ git checkout - &&
+ test_commit other &&
+ echo mine >secret &&
+
+ test_must_fail git merge --no-overwrite-ignore side &&
+ echo mine >expect &&
+ test_cmp expect secret &&
+ test_path_is_missing .git/MERGE_HEAD &&
+
+ git merge --overwrite-ignore side &&
+ echo side >expect &&
+ test_cmp expect secret
+ )
+'
+
+test_expect_success 'merge --no-overwrite-ignore with a directory rename' '
+ test_when_finished "rm -rf ignored" &&
+ git init ignored &&
+ (
+ cd ignored &&
+ echo new/private >.gitignore &&
+ mkdir old &&
+ echo seed >old/seed &&
+ git add .gitignore old/seed &&
+ test_tick &&
+ git commit -m base &&
+ git checkout -b incoming &&
+ git mv old new &&
+ test_tick &&
+ git commit -m "rename old to new" &&
+ git checkout - &&
+ echo committed >old/private &&
+ git add old/private &&
+ test_tick &&
+ git commit -m "add old/private" &&
+ mkdir new &&
+ echo mine >new/private &&
+
+ test_must_fail git merge --no-overwrite-ignore incoming &&
+ echo mine >expect &&
+ test_cmp expect new/private &&
+ test_path_is_missing .git/MERGE_HEAD
+ )
+'
+
test_done
--
2.43.0
Technical Details
Message-ID:
<20261107044419.209119-1-aniketgupta3001@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-74753-linux-kernel-git=dewy.ruReferences:
<CACgTecNrMKHGexWTkm1bqpVzL7SVWD5Hwo17wVokVGe3_Rnx0A@mail.gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-74753-linux-kernel-git=dewy.ru
From: aniketgupta3001@gmail.com (Aniket Gupta)
Newsgroups: linux.kernel.git
Subject: [PATCH] merge: honor --no-overwrite-ignore for real merges
Date: Sat, 7 Nov 2026 04:44:19 +0000
Organization: Usenet Network
Message-ID: <20261107044419.209119-1-aniketgupta3001@gmail.com>
References: <CACgTecNrMKHGexWTkm1bqpVzL7SVWD5Hwo17wVokVGe3_Rnx0A@mail.gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="4040265"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:9a52IT8qcLQpssfZvVk5zsfdBuU= sha256:I5x3uuI0xaJZ52nUzPA9BgNp83IE44vJ/uugueXyO+s=
sha1:sd4WQTmY1m7P39RdRvNzEZTuH7g= sha256:Ywes3u03Cqc/+eOqqIPtekSr9BsOJhx4CPaE1bipYk0=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id D47FE11338C; Sat, 7 Nov 2026 07:44:45 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.149
X-Spam-Status: No, score=-3.149 tagged_above=-9999 required=6.31
tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id kAED7DlJAx-3;
Sat, 7 Nov 2026 07:44:42 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=git+bounces-74753-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mail.dewy.ru (Postfix) with ESMTPS id 7910A1118D0; Sat, 7 Nov 2026 07:44:33 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sto.lore.kernel.org (Postfix) with ESMTP id 9FAD760D96E; Sat, 7 Nov 2026 04:44:29 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1794026667;
b=JGVB10C8kmu9yOFCUKR/Sbyiudpo3OUYbHvQuUmcEN9b6t17u03WEZ24E24oSY72NHr1
WN+aQ2gycvxdFIuRWEA29ehBGjKz7US0F5Id8TYQoFqW2F5TlNOr3SUJSnvJ87dGY6NFB
CfkJ+2VAS5ASqtwR3p5JOtLr9VSYPCePVAVuTbadGNJGBBuFf9WEM7hVAalzLJ5f+ZXhi
VLNRn1NjVzhQkGFX0tX0UXIg7d2kuQRwR6WIIZstkD95h4bgf/Vkf07mnBP0URZBZCgJP
muKe+6QuFN4z0WfiryMjVF++72pQA2iw0GXJVROawmr0GSjUKyQjzNIC7IgHu7H6mKg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794026667;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:
References:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Transfer-Encoding;
bh=i2N803mCYNoqV0f/UzaUxFpsGml85Pa3jKto2s8kcZM=;
b=KVCK0uHVFBEZPztmhrE29wgOb17OobPjyWHHX2aKubMEv0+wl/HV5SSk+o3r2KprV/0Z
VihPSeiHSLssSqv/wi57IAqdvzcMCEXf1QWVCfftk11abbw3LK+nA1JF8HqT3s3FickTp
z0vjdYsrj+3MTAod8ZOwIbc6VspnMMFrGDWy64U78AVhAne2wyo9XJQ1B4cargwq4/J0L
yyFZj3CwjD9EiXSyK9A8cwVQJGZ8uNwcfGpVNNAHRBnK1CjNxtdq6mQRix2jtymMeUrr5
0zdtjAIhwz/eBORH+BMqRHpXiAn3+zPWFKE0Ms9xTI9E3AxVubNtrqj3wZqfSb7h3sw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=qVn5cr2m;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id A0508606A333;
Sat, 7 Nov 2026 04:44:27 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=qVn5cr2m
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.176
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1794026666;
b=vLH2ZhCj0S/hbYwjJDVUMEbuSZ8uLMOlJWU7GnVgYZJzFAFp2WbeH0pldUZlUrLRu6MM
a71ATcirj6j5Dr2mig+VlkhQr7PHsFkaBpJKtm0guwragJq/azQpfHUj89lLkRuIQsulR
PNtGZC+b2Nl+XFqjRiFp8lNN9cb9wMumkikAncpdz8JmLMrUMRut2G7FtErdbsgq/mcSy
gAthGcS8SrVUr3yXKdUFbQBMxbd1mYOQ+5XtOxKgmcIzTRGlxESXAvG2n11IIapfFqTKB
glulcryO/qV9AZnETgy2GFYt9lUvFAncIN9oVe0o/FWxFJKYxbuYWPtNLwL34ccRY9Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794026666;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
Content-Transfer-Encoding;
bh=i2N803mCYNoqV0f/UzaUxFpsGml85Pa3jKto2s8kcZM=;
b=ci5PMlxlFSZmaxcT7BhZFVNgAYRIaqk/uYJkjc818rQqZoavnToJbSMjpx0Vww+Q1rvL
PFr71e1slun5UdWPSRoh8Z0FvSHl3NH0Qpyq91C746e2ls1CQctpbXGUQhNjQOIuGb43b
IuTMqceOHrY5l+ogPFoQ8yfDtmHmxNzkqRJtcUgZhmf+XQjSf8Gqtm+S5wh7jBAAohP2Y
Mboa07lZXRZjkBnraXVKj3GzrPFtppoLf5DOzN/RItLiD5Shuj1v0eLt2IBBfAyJYTXZ9
Tr8HbApanZn1W9eV7EL4Bw/MQSVGTGOP5Lk/KmM4in+bwJ6m2rMhy4iLo6oaa9GpS1Q==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=qVn5cr2m;
arc=none smtp.remote-ip=74.125.82.176
X-Received: from mail-dy1-f176.google.com (mail-dy1-f176.google.com [74.125.82.176])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68825606A326
for <git@vger.kernel.org>; Sat, 7 Nov 2026 04:44:26 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 68825606A326
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-dy1-f176.google.com with SMTP id 5a478bee46e88-35829219da8so340500eec.0
for <git@vger.kernel.org>; Fri, 06 Nov 2026 20:44:26 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1794026665; x=1794631465; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=i2N803mCYNoqV0f/UzaUxFpsGml85Pa3jKto2s8kcZM=;
b=qVn5cr2md6xBusWGYTyHkR7AgBtY60lIZ6v5WHTBQk/yDpVX+oufBtWX3YK6lirR3F
90u4isghNaEo+ic7AFhS78RDXTCT2fnsKGAshcFRPszIp53RBDrFJ006oxTDsk4kkTVl
AHPIdcYL2rZfwFy9O2UBJ9yyJh811Une+5GzcgQHpENPkoMc3xaUq0snaVK4J+sbjl4B
mLjnz1jTudpi7eDcFWCURouNLRt4lhayH7yPR0SVHw2Q1+RzR/F0BxziMvwp9xNE8ARe
gHBR0n9ihh2f3/tQ8p/mYKwWFoMeVcqvddeChMRDi+3iHSquDAjYSEnoCFX7vMa1sTLB
YrzQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1794026665; x=1794631465;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
:to:cc:subject:date:message-id:reply-to:content-type;
bh=i2N803mCYNoqV0f/UzaUxFpsGml85Pa3jKto2s8kcZM=;
b=s94vaQRRpyfgeOEqml3rIdCiDZSM28HjwwZTxAFO2qopmmyNsCl0BqeWOV5/x/b27q
ONO7KljHQe2EW4+V0jIt9QRfQplVRGpOFEzZ7hhLcsYn4xaBEbIQqZmmG/sBdVz+l+Gz
bVbXUUqwt2aF6BbWhAak+nqZjHaln+kn5eS/M0MsuaWUa9tZnMr6EDwVb5p9fBjUd4ja
0KTiYZPQBOuKjJFxeNkXsK5hR9SoM8IZx8WKTBa4sg/SiQ8luIAqStK7gdN/s1O9uAkN
XD1LqdsNzSa+0EfqUP8Tfqh5B6B9f7rcloKpHF8eqXTKEfpCISCcG4qpIVOSLP7VaFd2
rgag==
X-Gm-Message-State: APuU4Z/7dvOLWZwctsLzJ9lozqag7MC91GFnuQVDjne6t+1MRLg6oCiJ
c7sfXFE9QFsJb0dzvnBSe5lvLTymPlxTIQMtcRAXkkS2uCyJarO2cMN3rRviWGYY/fU=
X-Gm-Gg: AYBFou0FxVqurx8Gwx3RQLjhHS+/XMpOrfzkhXoPjE/ExtOqJaqY7XHsj1U9P8p1WHb
2GvdANsRwXM0+2qEntFGU9sIyIuGKVVnqGI5Sk97Kn634U7CwmaXmnvUssYKjbcUhvTt3Fkey15
X4pjiHrH+TVeq6okkzw10ZAKgxOM+maGISPuwABR+e8Iuu3oQyXeQJI5fysTL4kNBRMPEfE3UEp
vSvvJx0BO0IJH+BsU54m8cFpvBvrnLFueopW6lPkeHX3aOhuP1AEHyID98ZHDFmlZG3SPiW3nKs
GrL6fBtXjQAlBi8sX5KY3NwcioJHl1mjasYhaDz3lpdN3wtMy6l6Rwzxt2ASz29CfN16cDzBtOz
EqTSfRpj+CEnTX5aXKNGDtrlEq/w8oQcEuNoZ1YkrZ7jYdCUCCWMP0WP0WW7I1hwOANP3jcFf+Z
2+LOYCGCVi2GduRGEqRUCK5jeNgBuWgPxDn/haxFJBSU40iWjlJky5hjvSk1T6LH+YfXjYJ8oE9
BmuziW4hv4bYpOKXO79Bpc18BrGd7nlut8b15F0Oe/UgU47f9j2f65SazXO9z6odnZFDYnZ5mT3
3LYjhL6f1dIRySkuenOTE5zh8h+uJ1ML6EWS9FzD7jeibgiYSocikRdKocd+4YHM9fcomF1C3A=
=
X-Received: by 2002:a05:7301:d810:b0:36a:37:1404 with SMTP id 5a478bee46e88-370f6018313mr1859364eec.13.1794026665286;
Fri, 06 Nov 2026 20:44:25 -0800 (PST)
X-Received: from LAPTOP-PVRSMPQK ([223.190.82.143])
by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36faa4b8aacsm11317465eec.23.2026.11.06.20.44.22
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Fri, 06 Nov 2026 20:44:24 -0800 (PST)
X-Cc: Junio C Hamano <gitster@pobox.com>,
Elijah Newren <newren@gmail.com>,
Coy Geek <coygeek@gmail.com>
X-Mailer: git-send-email 2.56.0.344.gfa103ac04e
X-In-Reply-To: <CACgTecNrMKHGexWTkm1bqpVzL7SVWD5Hwo17wVokVGe3_Rnx0A@mail.gmail.com>
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list