Skip to content

Commit a0de2f6

Browse files
newrengitster
authored andcommitted
conflict_rename_delete(): Check whether D/F conflicts are still present
If all the paths below some directory involved in a D/F conflict were not removed during the rest of the merge, then the contents of the file whose path conflicted needs to be recorded in file with an alternative filename. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 71f7ffc commit a0de2f6

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

merge-recursive.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,8 @@ static void conflict_rename_delete(struct merge_options *o,
807807
const char *other_branch)
808808
{
809809
char *dest_name = pair->two->path;
810+
int df_conflict = 0;
811+
struct stat st;
810812

811813
output(o, 1, "CONFLICT (rename/delete): Rename %s->%s in %s "
812814
"and deleted in %s",
@@ -817,7 +819,13 @@ static void conflict_rename_delete(struct merge_options *o,
817819
rename_branch == o->branch1 ? pair->two : NULL,
818820
rename_branch == o->branch1 ? NULL : pair->two,
819821
1);
822+
if (lstat(dest_name, &st) == 0 && S_ISDIR(st.st_mode)) {
823+
dest_name = unique_path(o, dest_name, rename_branch);
824+
df_conflict = 1;
825+
}
820826
update_file(o, 0, pair->two->sha1, pair->two->mode, dest_name);
827+
if (df_conflict)
828+
free(dest_name);
821829
}
822830

823831
static void conflict_rename_rename_1to2(struct merge_options *o,

t/t6022-merge-rename.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ test_expect_success 'setup both rename source and destination involved in D/F co
549549
git commit -m "Conflicts in the way"
550550
'
551551

552-
test_expect_failure 'both rename source and destination involved in D/F conflict' '
552+
test_expect_success 'both rename source and destination involved in D/F conflict' '
553553
git reset --hard &&
554554
rm -rf dir~* &&
555555
git checkout -q rename-dest^0 &&
@@ -589,7 +589,7 @@ test_expect_success 'setup pair rename to parent of other (D/F conflicts)' '
589589
git commit -m "Rename one/file -> two"
590590
'
591591

592-
test_expect_failure 'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
592+
test_expect_success 'pair rename to parent of other (D/F conflicts) w/ untracked dir' '
593593
git checkout -q rename-one^0 &&
594594
mkdir one &&
595595
test_must_fail git merge --strategy=recursive rename-two &&

0 commit comments

Comments
 (0)