@@ -1324,11 +1324,22 @@ static int handle_file(struct merge_options *o,
13241324
13251325 add = filespec_from_entry (& other , dst_entry , stage ^ 1 );
13261326 if (add ) {
1327+ int ren_src_was_dirty = was_dirty (o , rename -> path );
13271328 char * add_name = unique_path (o , rename -> path , other_branch );
13281329 if (update_file (o , 0 , & add -> oid , add -> mode , add_name ))
13291330 return -1 ;
13301331
1331- remove_file (o , 0 , rename -> path , 0 );
1332+ if (ren_src_was_dirty ) {
1333+ output (o , 1 , _ ("Refusing to lose dirty file at %s" ),
1334+ rename -> path );
1335+ }
1336+ /*
1337+ * Because the double negatives somehow keep confusing me...
1338+ * 1) update_wd iff !ren_src_was_dirty.
1339+ * 2) no_wd iff !update_wd
1340+ * 3) so, no_wd == !!ren_src_was_dirty == ren_src_was_dirty
1341+ */
1342+ remove_file (o , 0 , rename -> path , ren_src_was_dirty );
13321343 dst_name = unique_path (o , rename -> path , cur_branch );
13331344 } else {
13341345 if (dir_in_way (rename -> path , !o -> call_depth , 0 )) {
@@ -1466,7 +1477,10 @@ static int conflict_rename_rename_2to1(struct merge_options *o,
14661477 char * new_path2 = unique_path (o , path , ci -> branch2 );
14671478 output (o , 1 , _ ("Renaming %s to %s and %s to %s instead" ),
14681479 a -> path , new_path1 , b -> path , new_path2 );
1469- if (would_lose_untracked (path ))
1480+ if (was_dirty (o , path ))
1481+ output (o , 1 , _ ("Refusing to lose dirty file at %s" ),
1482+ path );
1483+ else if (would_lose_untracked (path ))
14701484 /*
14711485 * Only way we get here is if both renames were from
14721486 * a directory rename AND user had an untracked file
@@ -2075,6 +2089,7 @@ static void apply_directory_rename_modifications(struct merge_options *o,
20752089{
20762090 struct string_list_item * item ;
20772091 int stage = (tree == a_tree ? 2 : 3 );
2092+ int update_wd ;
20782093
20792094 /*
20802095 * In all cases where we can do directory rename detection,
@@ -2085,7 +2100,11 @@ static void apply_directory_rename_modifications(struct merge_options *o,
20852100 * saying the file would have been overwritten), but it might
20862101 * be dirty, though.
20872102 */
2088- remove_file (o , 1 , pair -> two -> path , 0 /* no_wd */ );
2103+ update_wd = !was_dirty (o , pair -> two -> path );
2104+ if (!update_wd )
2105+ output (o , 1 , _ ("Refusing to lose dirty file at %s" ),
2106+ pair -> two -> path );
2107+ remove_file (o , 1 , pair -> two -> path , !update_wd );
20892108
20902109 /* Find or create a new re->dst_entry */
20912110 item = string_list_lookup (entries , new_path );
0 commit comments