@@ -1314,11 +1314,22 @@ static int handle_file(struct merge_options *o,
1314
1314
1315
1315
add = filespec_from_entry (& other , dst_entry , stage ^ 1 );
1316
1316
if (add ) {
1317
+ int ren_src_was_dirty = was_dirty (o , rename -> path );
1317
1318
char * add_name = unique_path (o , rename -> path , other_branch );
1318
1319
if (update_file (o , 0 , & add -> oid , add -> mode , add_name ))
1319
1320
return -1 ;
1320
1321
1321
- remove_file (o , 0 , rename -> path , 0 );
1322
+ if (ren_src_was_dirty ) {
1323
+ output (o , 1 , _ ("Refusing to lose dirty file at %s" ),
1324
+ rename -> path );
1325
+ }
1326
+ /*
1327
+ * Because the double negatives somehow keep confusing me...
1328
+ * 1) update_wd iff !ren_src_was_dirty.
1329
+ * 2) no_wd iff !update_wd
1330
+ * 3) so, no_wd == !!ren_src_was_dirty == ren_src_was_dirty
1331
+ */
1332
+ remove_file (o , 0 , rename -> path , ren_src_was_dirty );
1322
1333
dst_name = unique_path (o , rename -> path , cur_branch );
1323
1334
} else {
1324
1335
if (dir_in_way (rename -> path , !o -> call_depth , 0 )) {
@@ -1456,7 +1467,10 @@ static int conflict_rename_rename_2to1(struct merge_options *o,
1456
1467
char * new_path2 = unique_path (o , path , ci -> branch2 );
1457
1468
output (o , 1 , _ ("Renaming %s to %s and %s to %s instead" ),
1458
1469
a -> path , new_path1 , b -> path , new_path2 );
1459
- if (would_lose_untracked (path ))
1470
+ if (was_dirty (o , path ))
1471
+ output (o , 1 , _ ("Refusing to lose dirty file at %s" ),
1472
+ path );
1473
+ else if (would_lose_untracked (path ))
1460
1474
/*
1461
1475
* Only way we get here is if both renames were from
1462
1476
* a directory rename AND user had an untracked file
@@ -2065,6 +2079,7 @@ static void apply_directory_rename_modifications(struct merge_options *o,
2065
2079
{
2066
2080
struct string_list_item * item ;
2067
2081
int stage = (tree == a_tree ? 2 : 3 );
2082
+ int update_wd ;
2068
2083
2069
2084
/*
2070
2085
* In all cases where we can do directory rename detection,
@@ -2075,7 +2090,11 @@ static void apply_directory_rename_modifications(struct merge_options *o,
2075
2090
* saying the file would have been overwritten), but it might
2076
2091
* be dirty, though.
2077
2092
*/
2078
- remove_file (o , 1 , pair -> two -> path , 0 /* no_wd */ );
2093
+ update_wd = !was_dirty (o , pair -> two -> path );
2094
+ if (!update_wd )
2095
+ output (o , 1 , _ ("Refusing to lose dirty file at %s" ),
2096
+ pair -> two -> path );
2097
+ remove_file (o , 1 , pair -> two -> path , !update_wd );
2079
2098
2080
2099
/* Find or create a new re->dst_entry */
2081
2100
item = string_list_lookup (entries , new_path );
0 commit comments