@matheusbsbs / matheus-bagliano / commits / b798671fa9
Fork 0

merge-recursive: do not rudely die on binary merge

When you try to merge a path that involves binary file-level merge, merge-recursive died rudely without cleaning up its own mess. A files added by the merge were left in the working tree, but the index was not written out (because it just punted and died), so it was cumbersome for the user to retry it by first running "git reset --hard". This changes merge-recursive to still warn but do the "binary" merge for such a path; leave the "our" version in the working tree, but still keep the path unmerged so that the user can sort it out. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Aug 14, 2007 at 15:33 UTC b798671fa935492ce511766bc99fb26b2892499b
2 files changed +95 -23
merge-recursive.c
+28 -23
@@ -677,6 +677,26 @@ struct ll_merge_driver {
677 /*
678 * Built-in low-levels
679 */
680 +static int ll_binary_merge(const struct ll_merge_driver *drv_unused,
681 + const char *path_unused,
682 + mmfile_t *orig,
683 + mmfile_t *src1, const char *name1,
684 + mmfile_t *src2, const char *name2,
685 + mmbuffer_t *result)
686 +{
687 + /*
688 + * The tentative merge result is "ours" for the final round,
689 + * or common ancestor for an internal merge. Still return
690 + * "conflicted merge" status.
691 + */
692 + mmfile_t *stolen = index_only ? orig : src1;
693 +
694 + result->ptr = stolen->ptr;
695 + result->size = stolen->size;
696 + stolen->ptr = NULL;
697 + return 1;
698 +}
699 +
700 static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
701 const char *path_unused,
702 mmfile_t *orig,
@@ -687,10 +707,15 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
707 xpparam_t xpp;
708
709 if (buffer_is_binary(orig->ptr, orig->size) ||
690 - buffer_is_binary(src1->ptr, src1->size) ||
691 - buffer_is_binary(src2->ptr, src2->size))
692 - return error("Cannot merge binary files: %s vs. %s\n",
710 + buffer_is_binary(src1->ptr, src1->size) ||
711 + buffer_is_binary(src2->ptr, src2->size)) {
712 + warning("Cannot merge binary files: %s vs. %s\n",
713 name1, name2);
714 + return ll_binary_merge(drv_unused, path_unused,
715 + orig, src1, name1,
716 + src2, name2,
717 + result);
718 + }
719
720 memset(&xpp, 0, sizeof(xpp));
721 return xdl_merge(orig,
@@ -743,26 +768,6 @@ static int ll_union_merge(const struct ll_merge_driver *drv_unused,
768 return 0;
769 }
770
746 -static int ll_binary_merge(const struct ll_merge_driver *drv_unused,
747 - const char *path_unused,
748 - mmfile_t *orig,
749 - mmfile_t *src1, const char *name1,
750 - mmfile_t *src2, const char *name2,
751 - mmbuffer_t *result)
752 -{
753 - /*
754 - * The tentative merge result is "ours" for the final round,
755 - * or common ancestor for an internal merge. Still return
756 - * "conflicted merge" status.
757 - */
758 - mmfile_t *stolen = index_only ? orig : src1;
759 -
760 - result->ptr = stolen->ptr;
761 - result->size = stolen->size;
762 - stolen->ptr = NULL;
763 - return 1;
764 -}
765 -
771 #define LL_BINARY_MERGE 0
772 #define LL_TEXT_MERGE 1
773 #define LL_UNION_MERGE 2
t/t6027-merge-binary.sh new
+67
@@ -0,0 +1,67 @@
1 +#!/bin/sh
2 +
3 +test_description='ask merge-recursive to merge binary files'
4 +
5 +. ./test-lib.sh
6 +
7 +test_expect_success setup '
8 +
9 + cat ../test4012.png >m &&
10 + git add m &&
11 + git ls-files -s | sed -e "s/ 0 / 1 /" >E1 &&
12 + test_tick &&
13 + git commit -m "initial" &&
14 +
15 + git branch side &&
16 + echo frotz >a &&
17 + git add a &&
18 + echo nitfol >>m &&
19 + git add a m &&
20 + git ls-files -s a >E0 &&
21 + git ls-files -s m | sed -e "s/ 0 / 3 /" >E3 &&
22 + test_tick &&
23 + git commit -m "master adds some" &&
24 +
25 + git checkout side &&
26 + echo rezrov >>m &&
27 + git add m &&
28 + git ls-files -s m | sed -e "s/ 0 / 2 /" >E2 &&
29 + test_tick &&
30 + git commit -m "side modifies" &&
31 +
32 + git tag anchor &&
33 +
34 + cat E0 E1 E2 E3 >expect
35 +'
36 +
37 +test_expect_success resolve '
38 +
39 + rm -f a* m* &&
40 + git reset --hard anchor &&
41 +
42 + if git merge -s resolve master
43 + then
44 + echo Oops, should not have succeeded
45 + false
46 + else
47 + git ls-files -s >current
48 + diff -u current expect
49 + fi
50 +'
51 +
52 +test_expect_success recursive '
53 +
54 + rm -f a* m* &&
55 + git reset --hard anchor &&
56 +
57 + if git merge -s recursive master
58 + then
59 + echo Oops, should not have succeeded
60 + false
61 + else
62 + git ls-files -s >current
63 + diff -u current expect
64 + fi
65 +'
66 +
67 +test_done