Merge branch 'en/merge-cleanup-more'
authorJunio C Hamano <gitster@pobox.com>
Fri, 2 Nov 2018 15:53:57 +0000 (00:53 +0900)
committerJunio C Hamano <gitster@pobox.com>
Fri, 2 Nov 2018 15:53:57 +0000 (00:53 +0900)
Further clean-up of merge-recursive machinery.

* en/merge-cleanup-more:
merge-recursive: avoid showing conflicts with merge branch before HEAD
merge-recursive: improve auto-merging messages with path collisions

merge-recursive.c
t/t6036-recursive-corner-cases.sh
index c0fb83d2858c056633f306b2c3d49b9fd587b767..acc2f64a4e9d03f49165e3c46396ce00a09dc6bd 100644 (file)
@@ -228,7 +228,26 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
                                              struct stage_data *src_entry1,
                                              struct stage_data *src_entry2)
 {
-       struct rename_conflict_info *ci = xcalloc(1, sizeof(struct rename_conflict_info));
+       struct rename_conflict_info *ci;
+
+       /*
+        * When we have two renames involved, it's easiest to get the
+        * correct things into stage 2 and 3, and to make sure that the
+        * content merge puts HEAD before the other branch if we just
+        * ensure that branch1 == o->branch1.  So, simply flip arguments
+        * around if we don't have that.
+        */
+       if (dst_entry2 && branch1 != o->branch1) {
+               setup_rename_conflict_info(rename_type,
+                                          pair2,      pair1,
+                                          branch2,    branch1,
+                                          dst_entry2, dst_entry1,
+                                          o,
+                                          src_entry2, src_entry1);
+               return;
+       }
+
+       ci = xcalloc(1, sizeof(struct rename_conflict_info));
        ci->rename_type = rename_type;
        ci->pair1 = pair1;
        ci->branch1 = branch1;
@@ -1284,6 +1303,17 @@ static int merge_mode_and_contents(struct merge_options *o,
                                   const char *branch2,
                                   struct merge_file_info *result)
 {
+       if (o->branch1 != branch1) {
+               /*
+                * It's weird getting a reverse merge with HEAD on the bottom
+                * side of the conflict markers and the other branch on the
+                * top.  Fix that.
+                */
+               return merge_mode_and_contents(o, one, b, a,
+                                              filename,
+                                              branch2, branch1, result);
+       }
+
        result->merge = 0;
        result->clean = 1;
 
@@ -1675,8 +1705,8 @@ static int handle_rename_rename_2to1(struct merge_options *o,
        remove_file(o, 1, a->path, o->call_depth || would_lose_untracked(a->path));
        remove_file(o, 1, b->path, o->call_depth || would_lose_untracked(b->path));
 
-       path_side_1_desc = xstrfmt("%s (was %s)", path, a->path);
-       path_side_2_desc = xstrfmt("%s (was %s)", path, b->path);
+       path_side_1_desc = xstrfmt("version of %s from %s", path, a->path);
+       path_side_2_desc = xstrfmt("version of %s from %s", path, b->path);
        if (merge_mode_and_contents(o, a, c1, &ci->ren1_other, path_side_1_desc,
                                    o->branch1, o->branch2, &mfi_c1) ||
            merge_mode_and_contents(o, b, &ci->ren2_other, c2, path_side_2_desc,
index 59e52c5a09eebfabe932c5c33a842236f68ffdfb..e1cef58f2af96f6185ed93086c3966fb73d58f79 100755 (executable)
@@ -230,13 +230,13 @@ test_expect_success 'git detects differently handled merges conflict' '
                        :2:new_a :3:new_a &&
                test_cmp expect actual &&
 
-               git cat-file -p B:new_a >ours &&
-               git cat-file -p C:new_a >theirs &&
+               git cat-file -p C:new_a >ours &&
+               git cat-file -p B:new_a >theirs &&
                >empty &&
                test_must_fail git merge-file \
-                       -L "Temporary merge branch 2" \
-                       -L "" \
                        -L "Temporary merge branch 1" \
+                       -L "" \
+                       -L "Temporary merge branch 2" \
                        ours empty theirs &&
                sed -e "s/^\([<=>]\)/\1\1\1/" ours >expect &&
                git cat-file -p :1:new_a >actual &&