@@ -228,7 +228,26 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
228
228
struct stage_data * src_entry1 ,
229
229
struct stage_data * src_entry2 )
230
230
{
231
- struct rename_conflict_info * ci = xcalloc (1 , sizeof (struct rename_conflict_info ));
231
+ struct rename_conflict_info * ci ;
232
+
233
+ /*
234
+ * When we have two renames involved, it's easiest to get the
235
+ * correct things into stage 2 and 3, and to make sure that the
236
+ * content merge puts HEAD before the other branch if we just
237
+ * ensure that branch1 == o->branch1. So, simply flip arguments
238
+ * around if we don't have that.
239
+ */
240
+ if (dst_entry2 && branch1 != o -> branch1 ) {
241
+ setup_rename_conflict_info (rename_type ,
242
+ pair2 , pair1 ,
243
+ branch2 , branch1 ,
244
+ dst_entry2 , dst_entry1 ,
245
+ o ,
246
+ src_entry2 , src_entry1 );
247
+ return ;
248
+ }
249
+
250
+ ci = xcalloc (1 , sizeof (struct rename_conflict_info ));
232
251
ci -> rename_type = rename_type ;
233
252
ci -> pair1 = pair1 ;
234
253
ci -> branch1 = branch1 ;
@@ -1284,6 +1303,17 @@ static int merge_mode_and_contents(struct merge_options *o,
1284
1303
const char * branch2 ,
1285
1304
struct merge_file_info * result )
1286
1305
{
1306
+ if (o -> branch1 != branch1 ) {
1307
+ /*
1308
+ * It's weird getting a reverse merge with HEAD on the bottom
1309
+ * side of the conflict markers and the other branch on the
1310
+ * top. Fix that.
1311
+ */
1312
+ return merge_mode_and_contents (o , one , b , a ,
1313
+ filename ,
1314
+ branch2 , branch1 , result );
1315
+ }
1316
+
1287
1317
result -> merge = 0 ;
1288
1318
result -> clean = 1 ;
1289
1319
@@ -1675,8 +1705,8 @@ static int handle_rename_rename_2to1(struct merge_options *o,
1675
1705
remove_file (o , 1 , a -> path , o -> call_depth || would_lose_untracked (a -> path ));
1676
1706
remove_file (o , 1 , b -> path , o -> call_depth || would_lose_untracked (b -> path ));
1677
1707
1678
- path_side_1_desc = xstrfmt ("%s (was %s) " , path , a -> path );
1679
- path_side_2_desc = xstrfmt ("%s (was %s) " , path , b -> path );
1708
+ path_side_1_desc = xstrfmt ("version of %s from %s" , path , a -> path );
1709
+ path_side_2_desc = xstrfmt ("version of %s from %s" , path , b -> path );
1680
1710
if (merge_mode_and_contents (o , a , c1 , & ci -> ren1_other , path_side_1_desc ,
1681
1711
o -> branch1 , o -> branch2 , & mfi_c1 ) ||
1682
1712
merge_mode_and_contents (o , b , & ci -> ren2_other , c2 , path_side_2_desc ,
0 commit comments