Skip to content

Commit ff19620

Browse files
committed
Merge branch 'jc/merge-symlink-ours-theirs' into maint
"git merge -Xours/-Xtheirs" learned to use our/their version when resolving a conflicting updates to a symbolic link. * jc/merge-symlink-ours-theirs: merge: teach -Xours/-Xtheirs to symbolic link merge
2 parents e17cec2 + fd48b46 commit ff19620

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
@@ -1026,10 +1026,19 @@ static int merge_file_1(struct merge_options *o,
10261026
&b->oid,
10271027
!o->call_depth);
10281028
} else if (S_ISLNK(a->mode)) {
1029-
oidcpy(&result->oid, &a->oid);
1030-
1031-
if (!oid_eq(&a->oid, &b->oid))
1032-
result->clean = 0;
1029+
switch (o->recursive_variant) {
1030+
case MERGE_RECURSIVE_NORMAL:
1031+
oidcpy(&result->oid, &a->oid);
1032+
if (!oid_eq(&a->oid, &b->oid))
1033+
result->clean = 0;
1034+
break;
1035+
case MERGE_RECURSIVE_OURS:
1036+
oidcpy(&result->oid, &a->oid);
1037+
break;
1038+
case MERGE_RECURSIVE_THEIRS:
1039+
oidcpy(&result->oid, &b->oid);
1040+
break;
1041+
}
10331042
} else
10341043
die("BUG: unsupported object type in the tree");
10351044
}

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)