Skip to content

Commit 6d6f9ac

Browse files
committed
checkout -m path: fix recreating conflicts
We should tell ll_merge() that the 3-way merge between stages #2 and #3 is an outermost merge, not a virtual-ancestor creation. Back when this code was originally written, users couldn't write custom merge drivers easily, so the bug didn't matter, but these days it does. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3273ebc commit 6d6f9ac

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

builtin-checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static int checkout_merged(int pos, struct checkout *state)
179179
fill_mm(active_cache[pos+2]->sha1, &theirs);
180180

181181
status = ll_merge(&result_buf, path, &ancestor,
182-
&ours, "ours", &theirs, "theirs", 1);
182+
&ours, "ours", &theirs, "theirs", 0);
183183
free(ancestor.ptr);
184184
free(ours.ptr);
185185
free(theirs.ptr);

t/t7201-co.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,4 +534,61 @@ test_expect_success 'failing checkout -b should not break working tree' '
534534
535535
'
536536

537+
(
538+
echo "#!$SHELL_PATH"
539+
cat <<\EOF
540+
O=$1 A=$2 B=$3
541+
cat "$A" >.tmp
542+
exec >"$A"
543+
echo '<<<<<<< filfre-theirs'
544+
cat "$B"
545+
echo '||||||| filfre-common'
546+
cat "$O"
547+
echo '======='
548+
cat ".tmp"
549+
echo '>>>>>>> filfre-ours'
550+
rm -f .tmp
551+
exit 1
552+
EOF
553+
) >filfre.sh
554+
chmod +x filfre.sh
555+
556+
test_expect_success 'custom merge driver with checkout -m' '
557+
git reset --hard &&
558+
559+
git config merge.filfre.driver "./filfre.sh %O %A %B" &&
560+
git config merge.filfre.name "Feel-free merge driver" &&
561+
git config merge.filfre.recursive binary &&
562+
echo "arm merge=filfre" >.gitattributes &&
563+
564+
git checkout -b left &&
565+
echo neutral >arm &&
566+
git add arm .gitattributes &&
567+
test_tick &&
568+
git commit -m neutral &&
569+
git branch right &&
570+
571+
echo left >arm &&
572+
test_tick &&
573+
git commit -a -m left &&
574+
git checkout right &&
575+
576+
echo right >arm &&
577+
test_tick &&
578+
git commit -a -m right &&
579+
580+
test_must_fail git merge left &&
581+
(
582+
for t in filfre-common left right
583+
do
584+
grep $t arm || exit 1
585+
done
586+
exit 0
587+
) &&
588+
589+
mv arm expect &&
590+
git checkout -m arm &&
591+
test_cmp expect arm
592+
'
593+
537594
test_done

0 commit comments

Comments
 (0)