merge-recursive: ensure we write updates for directory-renamed file

When a file is present in HEAD before the merge and the other side of the merge does not modify that file, we try to avoid re-writing the file and making it stat-dirty. However, when a file is present in HEAD before the merge and was in a directory that was renamed by the other side of the merge, we have to move the file to a new location and re-write it. Update the code that checks whether we can skip the update to also work in the presence of directory renames. Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Feb 14, 2018 at 10:52 UTC c5b761fb2711542073cf1906c0e86a34616b79ae
2 files changed +2 -4
merge-recursive.c
+1 -3
@@ -2763,7 +2763,6 @@ static int merge_content(struct merge_options *o,
2763
2764 if (mfi.clean && !df_conflict_remains &&
2765 oid_eq(&mfi.oid, a_oid) && mfi.mode == a_mode) {
2766 - int path_renamed_outside_HEAD;
2766 output(o, 3, _("Skipped %s (merged same as existing)"), path);
2767 /*
2768 * The content merge resulted in the same file contents we
@@ -2771,8 +2770,7 @@ static int merge_content(struct merge_options *o,
2770 * are recorded at the correct path (which may not be true
2771 * if the merge involves a rename).
2772 */
2774 - path_renamed_outside_HEAD = !path2 || !strcmp(path, path2);
2775 - if (!path_renamed_outside_HEAD) {
2773 + if (was_tracked(path)) {
2774 add_cacheinfo(o, mfi.mode, &mfi.oid, path,
2775 0, (!o->call_depth), 0);
2776 return mfi.clean;
t/t6043-merge-rename-directories.sh
+1 -1
@@ -3884,7 +3884,7 @@ test_expect_success '12b-setup: Moving one directory hierarchy into another' '
3884 )
3885 '
3886
3887 -test_expect_failure '12b-check: Moving one directory hierarchy into another' '
3887 +test_expect_success '12b-check: Moving one directory hierarchy into another' '
3888 (
3889 cd 12b &&
3890