Skip to content

Commit bbafab7

Browse files
newrengitster
authored andcommitted
merge-recursive: fix remaining directory rename + dirty overwrite cases
Reviewed-by: Stefan Beller <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e0052f4 commit bbafab7

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

merge-recursive.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,11 +1314,22 @@ static int handle_file(struct merge_options *o,
13141314

13151315
add = filespec_from_entry(&other, dst_entry, stage ^ 1);
13161316
if (add) {
1317+
int ren_src_was_dirty = was_dirty(o, rename->path);
13171318
char *add_name = unique_path(o, rename->path, other_branch);
13181319
if (update_file(o, 0, &add->oid, add->mode, add_name))
13191320
return -1;
13201321

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);
13221333
dst_name = unique_path(o, rename->path, cur_branch);
13231334
} else {
13241335
if (dir_in_way(rename->path, !o->call_depth, 0)) {
@@ -1456,7 +1467,10 @@ static int conflict_rename_rename_2to1(struct merge_options *o,
14561467
char *new_path2 = unique_path(o, path, ci->branch2);
14571468
output(o, 1, _("Renaming %s to %s and %s to %s instead"),
14581469
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))
14601474
/*
14611475
* Only way we get here is if both renames were from
14621476
* a directory rename AND user had an untracked file
@@ -2065,6 +2079,7 @@ static void apply_directory_rename_modifications(struct merge_options *o,
20652079
{
20662080
struct string_list_item *item;
20672081
int stage = (tree == a_tree ? 2 : 3);
2082+
int update_wd;
20682083

20692084
/*
20702085
* In all cases where we can do directory rename detection,
@@ -2075,7 +2090,11 @@ static void apply_directory_rename_modifications(struct merge_options *o,
20752090
* saying the file would have been overwritten), but it might
20762091
* be dirty, though.
20772092
*/
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);
20792098

20802099
/* Find or create a new re->dst_entry */
20812100
item = string_list_lookup(entries, new_path);

t/t6043-merge-rename-directories.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3370,7 +3370,7 @@ test_expect_success '11b-setup: Avoid losing dirty file involved in directory re
33703370
)
33713371
'
33723372

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' '
33743374
(
33753375
cd 11b &&
33763376
@@ -3512,7 +3512,7 @@ test_expect_success '11d-setup: Avoid losing not-uptodate with rename + D/F conf
35123512
)
35133513
'
35143514

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' '
35163516
(
35173517
cd 11d &&
35183518
@@ -3591,7 +3591,7 @@ test_expect_success '11e-setup: Avoid deleting not-uptodate with dir rename/rena
35913591
)
35923592
'
35933593

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' '
35953595
(
35963596
cd 11e &&
35973597
@@ -3667,7 +3667,7 @@ test_expect_success '11f-setup: Avoid deleting not-uptodate with dir rename/rena
36673667
)
36683668
'
36693669

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)' '
36713671
(
36723672
cd 11f &&
36733673

0 commit comments

Comments
 (0)