@@ -228,7 +228,26 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
228228 struct stage_data * src_entry1 ,
229229 struct stage_data * src_entry2 )
230230{
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 ));
232251 ci -> rename_type = rename_type ;
233252 ci -> pair1 = pair1 ;
234253 ci -> branch1 = branch1 ;
@@ -1284,6 +1303,17 @@ static int merge_mode_and_contents(struct merge_options *o,
12841303 const char * branch2 ,
12851304 struct merge_file_info * result )
12861305{
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+
12871317 result -> merge = 0 ;
12881318 result -> clean = 1 ;
12891319
@@ -1675,8 +1705,8 @@ static int handle_rename_rename_2to1(struct merge_options *o,
16751705 remove_file (o , 1 , a -> path , o -> call_depth || would_lose_untracked (a -> path ));
16761706 remove_file (o , 1 , b -> path , o -> call_depth || would_lose_untracked (b -> path ));
16771707
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 );
16801710 if (merge_mode_and_contents (o , a , c1 , & ci -> ren1_other , path_side_1_desc ,
16811711 o -> branch1 , o -> branch2 , & mfi_c1 ) ||
16821712 merge_mode_and_contents (o , b , & ci -> ren2_other , c2 , path_side_2_desc ,
0 commit comments