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 a944af1d ("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 <gitster@pobox.com> Tested-by: Yaroslav Halchenko <yoh@onerussian.com> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Sep 26, 2017 at 11:40 UTC fd48b464747c275b3d014b3f14d60d9ac19d184a
2 files changed +45 -4
merge-recursive.c
+13 -4
@@ -1002,10 +1002,19 @@ static int merge_file_1(struct merge_options *o,
1002 &b->oid,
1003 !o->call_depth);
1004 } 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 + }
1018 } else
1019 die("BUG: unsupported object type in the tree");
1020 }
t/t6037-merge-ours-theirs.sh
+32
@@ -73,4 +73,36 @@ test_expect_success 'pull passes -X to underlying merge' '
73 git reset --hard master && test_must_fail git pull -s recursive -X bork . side
74 '
75
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 +
108 test_done