{"thread":{"id":"66440","subject":"[BUG] merge-ort: --no-overwrite-ignore overwrites an ignored file at a directory-rename destination","startedAt":"2026-10-01T23:54:24Z","lastAt":"2026-11-19T17:19:54Z","messageCount":3,"participants":["Coy Geek","Aniket Gupta"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"553878","messageId":"CACgTecNrMKHGexWTkm1bqpVzL7SVWD5Hwo17wVokVGe3_Rnx0A@mail.gmail.com","threadId":"66440","inReplyTo":null,"subject":"[BUG] merge-ort: --no-overwrite-ignore overwrites an ignored file at a directory-rename destination","fromName":"Coy Geek","fromEmail":"coygeek@gmail.com","sentAt":"2026-10-01T23:54:12Z","receivedAt":"2026-10-01T23:54:24Z","isPatch":false,"sender":{"key":"coygeek@gmail.com","avatar":null},"body":"Hello,\n\nConsider the following ...\n\n`git merge --no-overwrite-ignore` is documented to abort rather than\noverwrite ignored files. When directory rename detection moves a file\nthat was added on the current branch into a path that holds an ignored,\nuntracked file, the merge replaces that file's contents without any\nwarning.\n\nWith merge.directoryRenames=true the merge reports success (exit 0).\nWith the default, merge.directoryRenames=conflict, it stops with a \"file\nlocation\" conflict, but the ignored file has already been overwritten. A\ndirect collision with the same ignored path is correctly refused, so the\nprotection is bypassed only for the destination path that rename\ndetection generates.\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\n\nSave the script below as repro.sh and run it as \"sh repro.sh true\", \"sh\nrepro.sh conflict\", or \"sh repro.sh default\" (no -c override). It works\nin a throwaway repository with empty global and system configuration.\n\n    #!/bin/sh\n    set -eu\n    mode=${1:-true}\n    unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_COMMON_DIR\nGIT_CONFIG_PARAMETERS\n    export GIT_CONFIG_NOSYSTEM=1 GIT_CONFIG_GLOBAL=/dev/null\n    tmp=$(mktemp -d)\n    cd \"$tmp\"\n    git init -q -b main repo\n    cd repo\n    git config user.name Example\n    git config user.email example@example.invalid\n    echo new/private.dat >.gitignore\n    mkdir old\n    echo seed >old/seed\n    git add .gitignore old/seed\n    git commit -qm base\n    git checkout -qb incoming\n    git mv old new\n    git commit -qm 'rename old/ to new/'\n    git checkout -q main\n    echo 'committed local bytes' >old/private.dat\n    git add old/private.dat\n    git commit -qm 'add old/private.dat'\n    mkdir new\n    echo 'unique ignored bytes' >new/private.dat\n    git status --porcelain --ignored\n    git version\n    status=0\n    if [ \"$mode\" = default ]; then set -- ; else set -- -c\nmerge.directoryRenames=\"$mode\"; fi\n    git \"$@\" merge --no-edit --no-overwrite-ignore incoming || status=$?\n    echo \"merge exit status: $status\"\n    echo \"new/private.dat now contains: $(cat new/private.dat)\"\n\nBefore the merge, `git status --porcelain --ignored` reports only \"!!\nnew/\": the worktree is clean, and new/private.dat is ignored and\nuntracked.\n\nWhat did you expect to happen? (Expected behavior)\n\nAs for any other merge result that would overwrite an ignored file under\n--no-overwrite-ignore, Git refuses before touching the worktree, names\nnew/private.dat, and leaves its contents as \"unique ignored bytes\".\n\nWhat happened instead? (Actual behavior)\n\nWith merge.directoryRenames=true:\n\n    Path updated: old/private.dat added in HEAD inside a directory\nthat was renamed in incoming; moving it to new/private.dat.\n    Merge made by the 'ort' strategy.\n     {old => new}/private.dat | 0\n     {old => new}/seed        | 0\n     2 files changed, 0 insertions(+), 0 deletions(-)\n     rename {old => new}/private.dat (100%)\n     rename {old => new}/seed (100%)\n    merge exit status: 0\n    new/private.dat now contains: committed local bytes\n\nWith the default configuration, or merge.directoryRenames=conflict:\n\n    CONFLICT (file location): old/private.dat added in HEAD inside a\ndirectory that was renamed in incoming, suggesting it should perhaps\nbe moved to new/private.dat.\n    Automatic merge failed; fix conflicts and then commit the result.\n    merge exit status: 1\n    new/private.dat now contains: committed local bytes\n\nIn both cases the ignored bytes are lost. They are not in any commit, in\nthe index, or in a stash, so `git merge --abort` cannot restore them.\n\nWhat's different between what you expected and what actually happened?\n\nControl case: if \"incoming\" instead adds new/private.dat directly (with\n`git add -f`, no rename involved), the same `git merge --no-edit\n--no-overwrite-ignore incoming` aborts with exit 1 and leaves \"unique\nignored bytes\" intact:\n\n    error: The following untracked working tree files would be\noverwritten by merge:\n            new/private.dat\n    Please move or remove them before you merge.\n    Aborting\n\nSo --no-overwrite-ignore works for a direct collision and fails only\nwhen the destination is produced by directory rename detection in the\nort strategy.\n\nThis matters because --no-overwrite-ignore is the only merge-level guard\nfor ignored content such as local configuration, credential files, or\nbuild inputs that users deliberately keep out of history. A user or tool\nrelying on it can lose unique, unversioned data, with no error at all or\nwith only an unrelated rename conflict message.\n\nAnything else you want to add:\n\nReproduced with identical results, in both modes, on:\n\n    git version 2.56.0.138.gc61827130   (built from next)\n    git version 2.56.0.50.gc46c1e3772   (built from master)\n    git version 2.56.0                  (Homebrew)\n    git version 2.55.0                  (Homebrew)\n    git version 2.54.0 (Apple Git-157)\n\nall on macOS 27 (arm64, APFS), using the empty-configuration environment\nshown in the script. I am happy to test a patch.\n\nRegards, CoyGeek\n"},{"id":"557765","messageId":"20261107044419.209119-1-aniketgupta3001@gmail.com","threadId":"66440","inReplyTo":"CACgTecNrMKHGexWTkm1bqpVzL7SVWD5Hwo17wVokVGe3_Rnx0A@mail.gmail.com","subject":"[PATCH] merge: honor --no-overwrite-ignore for real merges","fromName":"Aniket Gupta","fromEmail":"aniketgupta3001@gmail.com","sentAt":"2026-11-07T04:44:19Z","receivedAt":"2026-11-07T04:44:19Z","isPatch":true,"sender":{"key":"aniketgupta3001@gmail.com","avatar":null},"body":"\"git merge --no-overwrite-ignore\" is meant to abort instead of\noverwriting an ignored file that is in the way. However, only a\nfast-forward honors it. When a real merge is needed, ort and recursive\noverwrite the ignored file whatever the option says. Two FIXME comments\nin merge-ort.c and builtin/merge.c mark where it was never passed along.\nAdd a preserve_ignored bit to struct merge_options then set it from the\noption and use it where merge-ort updates the working tree. The\ntrivial-merge path in builtin/merge.c gets the same treatment. Other\ncallers of merge-ort leave the bit unset so nothing will change for\nthem.\n\nAdd tests for a plain merge and for a directory rename.\n\nReported-by: Coy Geek <coygeek@gmail.com>\nSigned-off-by: Aniket Gupta <aniketgupta3001@gmail.com>\n---\n builtin/merge.c  |  3 ++-\n merge-ort.c      |  2 +-\n merge-ort.h      |  1 +\n t/t7600-merge.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++++++\n 4 files changed, 63 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 5b4eb23a83..c7cd3ce29e 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -756,7 +756,7 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,\n \topts.verbose_update = 1;\n \topts.trivial_merges_only = 1;\n \topts.merge = 1;\n-\topts.preserve_ignored = 0; /* FIXME: !overwrite_ignore */\n+\topts.preserve_ignored = !overwrite_ignore;\n \ttrees[nr_trees] = repo_parse_tree_indirect(the_repository, common);\n \tif (!trees[nr_trees++])\n \t\treturn -1;\n@@ -812,6 +812,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,\n \t\t}\n \n \t\tinit_ui_merge_options(&o, the_repository);\n+\t\to.preserve_ignored = !overwrite_ignore;\n \t\tif (!strcmp(strategy, \"subtree\"))\n \t\t\to.subtree_shift = \"\";\n \ndiff --git a/merge-ort.c b/merge-ort.c\nindex c410a5d353..38dd1ac99d 100644\n--- a/merge-ort.c\n+++ b/merge-ort.c\n@@ -4632,7 +4632,7 @@ static int checkout(struct merge_options *opt,\n \tunpack_opts.quiet = 0; /* FIXME: sequencer might want quiet? */\n \tunpack_opts.verbose_update = (opt->verbosity > 2);\n \tunpack_opts.fn = twoway_merge;\n-\tunpack_opts.preserve_ignored = 0; /* FIXME: !opts->overwrite_ignore */\n+\tunpack_opts.preserve_ignored = opt->preserve_ignored;\n \tif (repo_parse_tree(opt->repo, prev) < 0)\n \t\treturn -1;\n \tinit_tree_desc(&trees[0], &prev->object.oid, prev->buffer, prev->size);\ndiff --git a/merge-ort.h b/merge-ort.h\nindex 6045579825..d5747f358e 100644\n--- a/merge-ort.h\n+++ b/merge-ort.h\n@@ -85,6 +85,7 @@ struct merge_options {\n \tunsigned renormalize : 1;\n \tunsigned mergeability_only : 1; /* exit early, write fewer objects */\n \tunsigned record_conflict_msgs_as_headers : 1;\n+\tunsigned preserve_ignored : 1; /* do not overwrite ignored files */\n \tconst char *msg_header_prefix;\n \n \t/* internal fields used by the implementation */\ndiff --git a/t/t7600-merge.sh b/t/t7600-merge.sh\nindex 64fe21717d..c1150e50e0 100755\n--- a/t/t7600-merge.sh\n+++ b/t/t7600-merge.sh\n@@ -1179,4 +1179,63 @@ test_expect_success 'merge with no argument defaults to upstream' '\n \t)\n '\n \n+test_expect_success 'merge --no-overwrite-ignore keeps an ignored file in the way' '\n+\ttest_when_finished \"rm -rf ignored\" &&\n+\tgit init ignored &&\n+\t(\n+\t\tcd ignored &&\n+\t\techo secret >.gitignore &&\n+\t\tgit add .gitignore &&\n+\t\ttest_tick &&\n+\t\tgit commit -m base &&\n+\t\tgit checkout -b side &&\n+\t\techo side >secret &&\n+\t\tgit add -f secret &&\n+\t\ttest_tick &&\n+\t\tgit commit -m side &&\n+\t\tgit checkout - &&\n+\t\ttest_commit other &&\n+\t\techo mine >secret &&\n+\n+\t\ttest_must_fail git merge --no-overwrite-ignore side &&\n+\t\techo mine >expect &&\n+\t\ttest_cmp expect secret &&\n+\t\ttest_path_is_missing .git/MERGE_HEAD &&\n+\n+\t\tgit merge --overwrite-ignore side &&\n+\t\techo side >expect &&\n+\t\ttest_cmp expect secret\n+\t)\n+'\n+\n+test_expect_success 'merge --no-overwrite-ignore with a directory rename' '\n+\ttest_when_finished \"rm -rf ignored\" &&\n+\tgit init ignored &&\n+\t(\n+\t\tcd ignored &&\n+\t\techo new/private >.gitignore &&\n+\t\tmkdir old &&\n+\t\techo seed >old/seed &&\n+\t\tgit add .gitignore old/seed &&\n+\t\ttest_tick &&\n+\t\tgit commit -m base &&\n+\t\tgit checkout -b incoming &&\n+\t\tgit mv old new &&\n+\t\ttest_tick &&\n+\t\tgit commit -m \"rename old to new\" &&\n+\t\tgit checkout - &&\n+\t\techo committed >old/private &&\n+\t\tgit add old/private &&\n+\t\ttest_tick &&\n+\t\tgit commit -m \"add old/private\" &&\n+\t\tmkdir new &&\n+\t\techo mine >new/private &&\n+\n+\t\ttest_must_fail git merge --no-overwrite-ignore incoming &&\n+\t\techo mine >expect &&\n+\t\ttest_cmp expect new/private &&\n+\t\ttest_path_is_missing .git/MERGE_HEAD\n+\t)\n+'\n+\n test_done\n-- \n2.43.0\n\n\n"},{"id":"558866","messageId":"20261119171954.85707-1-aniketgupta3001@gmail.com","threadId":"66440","inReplyTo":"20261107044419.209119-1-aniketgupta3001@gmail.com","subject":"Re: [PATCH] merge: honor --no-overwrite-ignore for real merges","fromName":"Aniket Gupta","fromEmail":"aniketgupta3001@gmail.com","sentAt":"2026-11-19T17:19:54Z","receivedAt":"2026-11-19T17:19:54Z","isPatch":true,"sender":{"key":"aniketgupta3001@gmail.com","avatar":null},"body":"Friendly ping. Elijah could you pls take a look when possible?\n\n"}]}