Skip to content

Commit 7d879ad

Browse files
peffgitster
authored andcommitted
ll_binary_merge(): handle XDL_MERGE_FAVOR_UNION
Prior to commit a944af1 (merge: teach -Xours/-Xtheirs to binary ll-merge driver, 2012-09-08), we always reported a conflict from ll_binary_merge() by returning "1" (in the xdl_merge and ll_merge code, this value is the number of conflict hunks). After that commit, we report zero conflicts if the "variant" flag is set, under the assumption that it is one of XDL_MERGE_FAVOR_OURS or XDL_MERGE_FAVOR_THEIRS. But this gets confused by XDL_MERGE_FAVOR_UNION. We do not know how to do a binary union merge, but erroneously report no conflicts anyway (and just blindly use the "ours" content as the result). Let's tighten our check to just the cases that a944af1 meant to cover. This fixes the union case (which existed already back when that commit was made), as well as future-proofing us against any other variants that get added later. Note that you can't trigger this from "git merge-file --union", as that bails on binary files before even calling into the ll-merge machinery. The test here uses the "union" merge attribute, which does erroneously report a successful merge. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 48bf2fa commit 7d879ad

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

ll-merge.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ static int ll_binary_merge(const struct ll_merge_driver *drv_unused,
9191
* With -Xtheirs or -Xours, we have cleanly merged;
9292
* otherwise we got a conflict.
9393
*/
94-
return (opts->variant ? 0 : 1);
94+
return opts->variant == XDL_MERGE_FAVOR_OURS ||
95+
opts->variant == XDL_MERGE_FAVOR_THEIRS ?
96+
0 : 1;
9597
}
9698

9799
static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,

t/t6406-merge-attr.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,21 @@ test_expect_success 'custom merge does not lock index' '
207207
git merge main
208208
'
209209

210+
test_expect_success 'binary files with union attribute' '
211+
git checkout -b bin-main &&
212+
printf "base\0" >bin.txt &&
213+
echo "bin.txt merge=union" >.gitattributes &&
214+
git add bin.txt .gitattributes &&
215+
git commit -m base &&
216+
217+
printf "one\0" >bin.txt &&
218+
git commit -am one &&
219+
220+
git checkout -b bin-side HEAD^ &&
221+
printf "two\0" >bin.txt &&
222+
git commit -am two &&
223+
224+
test_must_fail git merge bin-main
225+
'
226+
210227
test_done

0 commit comments

Comments
 (0)