Thread View: linux.kernel.git
3 messages
3 total messages
Started by Aniket Gupta
Sat, 07 Nov 2026 04:44
[PATCH] merge: honor --no-overwrite-ignore for real merges
Author: 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
Re: [PATCH] merge: honor --no-overwrite-ignore for real merges
Author: Aniket Gupta
Date: Thu, 19 Nov 2026 17:19
Date: Thu, 19 Nov 2026 17:19
2 lines
10749 bytes
10749 bytes
Friendly ping. Elijah could you pls take a look when possible?
Re: [PATCH] merge: honor --no-overwrite-ignore for real merges
Author: Aniket Gupta
Date: Fri, 27 Nov 2026 16:20
Date: Fri, 27 Nov 2026 16:20
8 lines
10835 bytes
10835 bytes
Hi Patrick, Adding you here since you reviewed the stash --no-overwrite-ignore patch in February. This one does the same for merge. Would you be able to take a look? Thanks
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads