Skip to content

Commit fd48b46

Browse files
committed
merge: teach -Xours/-Xtheirs to symbolic link merge
The -Xours/-Xtheirs merge options were originally defined as a way to "force" the resolution of 3way textual merge conflicts to take one side without using your editor, hence did not even trigger in situations where you would normally not get the <<< === >>> conflict markers. This was improved for binary files back in 2012 with a944af1 ("merge: teach -Xours/-Xtheirs to binary ll-merge driver", 2012-09-08). Teach a similar trick to the codepath that deals with merging two conflicting changes to symbolic links. Signed-off-by: Junio C Hamano <[email protected]> Tested-by: Yaroslav Halchenko <[email protected]> Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 94c9fd2 commit fd48b46

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

merge-recursive.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,10 +1002,19 @@ static int merge_file_1(struct merge_options *o,
10021002
&b->oid,
10031003
!o->call_depth);
10041004
} else if (S_ISLNK(a->mode)) {
1005-
oidcpy(&result->oid, &a->oid);
1006-
1007-
if (!oid_eq(&a->oid, &b->oid))
1008-
result->clean = 0;
1005+
switch (o->recursive_variant) {
1006+
case MERGE_RECURSIVE_NORMAL:
1007+
oidcpy(&result->oid, &a->oid);
1008+
if (!oid_eq(&a->oid, &b->oid))
1009+
result->clean = 0;
1010+
break;
1011+
case MERGE_RECURSIVE_OURS:
1012+
oidcpy(&result->oid, &a->oid);
1013+
break;
1014+
case MERGE_RECURSIVE_THEIRS:
1015+
oidcpy(&result->oid, &b->oid);
1016+
break;
1017+
}
10091018
} else
10101019
die("BUG: unsupported object type in the tree");
10111020
}

t/t6037-merge-ours-theirs.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,36 @@ test_expect_success 'pull passes -X to underlying merge' '
7373
git reset --hard master && test_must_fail git pull -s recursive -X bork . side
7474
'
7575

76+
test_expect_success SYMLINKS 'symlink with -Xours/-Xtheirs' '
77+
git reset --hard master &&
78+
git checkout -b two master &&
79+
ln -s target-zero link &&
80+
git add link &&
81+
git commit -m "add link pointing to zero" &&
82+
83+
ln -f -s target-two link &&
84+
git commit -m "add link pointing to two" link &&
85+
86+
git checkout -b one HEAD^ &&
87+
ln -f -s target-one link &&
88+
git commit -m "add link pointing to one" link &&
89+
90+
# we expect symbolic links not to resolve automatically, of course
91+
git checkout one^0 &&
92+
test_must_fail git merge -s recursive two &&
93+
94+
# favor theirs to resolve to target-two?
95+
git reset --hard &&
96+
git checkout one^0 &&
97+
git merge -s recursive -X theirs two &&
98+
git diff --exit-code two HEAD link &&
99+
100+
# favor ours to resolve to target-one?
101+
git reset --hard &&
102+
git checkout one^0 &&
103+
git merge -s recursive -X ours two &&
104+
git diff --exit-code one HEAD link
105+
106+
'
107+
76108
test_done

0 commit comments

Comments
 (0)