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

[PATCH] merge: honor --no-overwrite-ignore for real merges

From
AGAniket Gupta <aniketgupta3001@gmail.com>
Date
Nov 7, 2026, 04:44 UTC
Message-ID
<20261107044419.209119-1-aniketgupta3001@gmail.com>
In-Reply-To
<CACgTecNrMKHGexWTkm1bqpVzL7SVWD5Hwo17wVokVGe3_Rnx0A@mail.gmail.com>

"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
Previous: Coy GeekNext: Aniket Gupta
Message 2 of 3 in “[BUG] merge-ort: --no-overwrite-ignore overwrites an ignored file at a directory-rename destination”
  1. Coy GeekOct 1, 2026
  2. merge: honor --no-overwrite-ignore for real mergesAniket Gupta, Nov 7, 2026
  3. Aniket GuptaNov 19, 2026

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.