3 # Copyright (c) 2007 Junio C Hamano
6 test_description='per path merge controlled by merge attribute'
10 test_expect_success setup '
12 for f in text binary union
14 echo Initial >$f && git add $f || return 1
17 git commit -m Initial &&
20 for f in text binary union
22 echo Master >>$f && git add $f || return 1
25 git commit -m Master &&
28 for f in text binary union
30 echo Side >>$f && git add $f || return 1
38 test_expect_success merge '
42 echo "union merge=union"
47 echo Gaah, should have conflicted
54 test_expect_success 'check merge result in index' '
56 git ls-files -u | grep binary &&
57 git ls-files -u | grep text &&
58 ! (git ls-files -u | grep union)
62 test_expect_success 'check merge result in working tree' '
64 git cat-file -p HEAD:binary >binary-orig &&
65 grep "<<<<<<<" text &&
66 cmp binary-orig binary &&
67 ! grep "<<<<<<<" union &&
73 test_expect_success 'retry the merge with longer context' '
74 echo text conflict-marker-size=32 >>.gitattributes &&
75 git checkout -m text &&
76 sed -ne "/^\([<=>]\)\1\1\1*/{
80 grep ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" actual &&
81 grep "================================" actual &&
82 grep "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" actual
85 cat >./custom-merge <<\EOF
88 orig="$1" ours="$2" theirs="$3" exit="$4" path=$5
92 echo "theirs is $theirs"
101 cat "$ours+" >"$ours"
105 chmod +x ./custom-merge
107 test_expect_success 'custom merge backend' '
109 echo "* merge=union" >.gitattributes &&
110 echo "text merge=custom" >>.gitattributes &&
112 git reset --hard anchor &&
113 git config --replace-all \
114 merge.custom.driver "./custom-merge %O %A %B 0 %P" &&
115 git config --replace-all \
116 merge.custom.name "custom merge driver for testing" &&
121 sed -e 1,3d text >check-1 &&
122 o=$(git unpack-file master^:text) &&
123 a=$(git unpack-file side^:text) &&
124 b=$(git unpack-file master:text) &&
125 sh -c "./custom-merge $o $a $b 0 'text'" &&
126 sed -e 1,3d $a >check-2 &&
127 cmp check-1 check-2 &&
131 test_expect_success 'custom merge backend' '
133 git reset --hard anchor &&
134 git config --replace-all \
135 merge.custom.driver "./custom-merge %O %A %B 1 %P" &&
136 git config --replace-all \
137 merge.custom.name "custom merge driver for testing" &&
141 echo "Eh? should have conflicted"
144 echo "Ok, conflicted"
148 sed -e 1,3d text >check-1 &&
149 o=$(git unpack-file master^:text) &&
150 a=$(git unpack-file anchor:text) &&
151 b=$(git unpack-file master:text) &&
152 sh -c "./custom-merge $o $a $b 0 'text'" &&
153 sed -e 1,3d $a >check-2 &&
154 cmp check-1 check-2 &&
155 sed -e 1,3d -e 4q $a >check-3 &&
156 echo "path is text" >expect &&
157 cmp expect check-3 &&
161 test_expect_success 'up-to-date merge without common ancestor' '
162 test_create_repo repo1 &&
163 test_create_repo repo2 &&
169 git commit -m initial
174 git commit --allow-empty -m initial
179 git pull ../repo2 master