When a merge results in contents that already existed in HEAD (because the changes on a side branch were a subset of what was changed by HEAD), and those contents were already at the right path, the working directory updates can be skipped. However, the relevant code would sometimes claim the working directory update could be skipped despite the fact that the contents were at the wrong path. Make the output reflect the situation more precisely, including an additional message that tests can check for to make sure we are getting correct behavior. Signed-off-by: Elijah Newren <newren@xxxxxxxxx> --- merge-recursive.c | 11 ++++++----- t/t6022-merge-rename.sh | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/merge-recursive.c b/merge-recursive.c index 4a1ecdea03..05250939c7 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -2761,21 +2761,22 @@ static int merge_content(struct merge_options *o, o->branch2, path2, &mfi)) return -1; - if (mfi.clean && !df_conflict_remains && - oid_eq(&mfi.oid, a_oid) && mfi.mode == a_mode) { + if (mfi.clean && oid_eq(&mfi.oid, a_oid) && mfi.mode == a_mode) { int path_renamed_outside_HEAD; - output(o, 3, _("Skipped %s (merged same as existing)"), path); /* * The content merge resulted in the same file contents we * already had. We can return early if those file contents * are recorded at the correct path (which may not be true - * if the merge involves a rename). + * if the merge involves a rename or there's a D/F conflict). */ path_renamed_outside_HEAD = !path2 || !strcmp(path, path2); - if (!path_renamed_outside_HEAD) { + if (!df_conflict_remains && !path_renamed_outside_HEAD) { + output(o, 3, _("Skipped %s (merged same as existing)"), path); add_cacheinfo(o, mfi.mode, &mfi.oid, path, 0, (!o->call_depth), 0); return mfi.clean; + } else { + output(o, 3, _("Had correct contents for %s, but not at right path"), path); } } else output(o, 2, _("Auto-merging %s"), path); diff --git a/t/t6022-merge-rename.sh b/t/t6022-merge-rename.sh index 05ebba7afa..574088bfaf 100755 --- a/t/t6022-merge-rename.sh +++ b/t/t6022-merge-rename.sh @@ -245,7 +245,7 @@ test_expect_success 'merge of identical changes in a renamed file' ' GIT_MERGE_VERBOSITY=3 git merge change | test_i18ngrep "^Skipped B" && git reset --hard HEAD^ && git checkout change && - GIT_MERGE_VERBOSITY=3 git merge change+rename | test_i18ngrep "^Skipped B" + GIT_MERGE_VERBOSITY=3 git merge change+rename | test_i18ngrep "^Had correct contents for B, but not at right path" ' test_expect_success 'setup for rename + d/f conflicts' ' -- 2.16.0.35.g6dd7ede834