merge-recursive: fix remaining directory rename + dirty overwrite cases
Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Apr 19, 2018 at 10:58 UTC
18797a3b10e4077473740b953651b0032828d0fb
2 files changed
+26
-7
merge-recursive.c
+22
-3
@@ -1324,11 +1324,22 @@ static int handle_file(struct merge_options *o,
1324
1325
add = filespec_from_entry(&other, dst_entry, stage ^ 1);
1326
if (add) {
1327
+ int ren_src_was_dirty = was_dirty(o, rename->path);
1328
char *add_name = unique_path(o, rename->path, other_branch);
1329
if (update_file(o, 0, &add->oid, add->mode, add_name))
1330
return -1;
1331
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);
1343
dst_name = unique_path(o, rename->path, cur_branch);
1344
} else {
1345
if (dir_in_way(rename->path, !o->call_depth, 0)) {
@@ -1466,7 +1477,10 @@ static int conflict_rename_rename_2to1(struct merge_options *o,
1477
char *new_path2 = unique_path(o, path, ci->branch2);
1478
output(o, 1, _("Renaming %s to %s and %s to %s instead"),
1479
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))
1484
/*
1485
* Only way we get here is if both renames were from
1486
* a directory rename AND user had an untracked file
@@ -2075,6 +2089,7 @@ static void apply_directory_rename_modifications(struct merge_options *o,
2089
{
2090
struct string_list_item *item;
2091
int stage = (tree == a_tree ? 2 : 3);
2092
+ int update_wd;
2093
2094
/*
2095
* In all cases where we can do directory rename detection,
@@ -2085,7 +2100,11 @@ static void apply_directory_rename_modifications(struct merge_options *o,
2100
* saying the file would have been overwritten), but it might
2101
* be dirty, though.
2102
*/
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);
2108
2109
/* Find or create a new re->dst_entry */
2110
item = string_list_lookup(entries, new_path);
t/t6043-merge-rename-directories.sh
+4
-4
@@ -3370,7 +3370,7 @@ test_expect_success '11b-setup: Avoid losing dirty file involved in directory re
3370
)
3371
'
3372
3373
-test_expect_failure '11b-check: Avoid losing dirty file involved in directory rename' '
3373
+test_expect_success '11b-check: Avoid losing dirty file involved in directory rename' '
3374
(
3375
cd 11b &&
3376
@@ -3512,7 +3512,7 @@ test_expect_success '11d-setup: Avoid losing not-uptodate with rename + D/F conf
3512
)
3513
'
3514
3515
-test_expect_failure '11d-check: Avoid losing not-uptodate with rename + D/F conflict' '
3515
+test_expect_success '11d-check: Avoid losing not-uptodate with rename + D/F conflict' '
3516
(
3517
cd 11d &&
3518
@@ -3591,7 +3591,7 @@ test_expect_success '11e-setup: Avoid deleting not-uptodate with dir rename/rena
3591
)
3592
'
3593
3594
-test_expect_failure '11e-check: Avoid deleting not-uptodate with dir rename/rename(1to2)/add' '
3594
+test_expect_success '11e-check: Avoid deleting not-uptodate with dir rename/rename(1to2)/add' '
3595
(
3596
cd 11e &&
3597
@@ -3667,7 +3667,7 @@ test_expect_success '11f-setup: Avoid deleting not-uptodate with dir rename/rena
3667
)
3668
'
3669
3670
-test_expect_failure '11f-check: Avoid deleting not-uptodate with dir rename/rename(2to1)' '
3670
+test_expect_success '11f-check: Avoid deleting not-uptodate with dir rename/rename(2to1)' '
3671
(
3672
cd 11f &&
3673