3 # Copyright (c) 2007 Junio C Hamano
6 test_description
='per path merge controlled by merge attribute'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 TEST_PASSES_SANITIZE_LEAK
=true
14 test_expect_success setup
'
16 for f in text binary union
18 echo Initial >$f && git add $f || return 1
21 git commit -m Initial &&
24 for f in text binary union
26 echo Main >>$f && git add $f || return 1
32 for f in text binary union
34 echo Side >>$f && git add $f || return 1
41 cat >./custom-merge <<-\EOF &&
44 orig="$1" ours="$2" theirs="$3" exit="$4" path=$5
48 echo "theirs is $theirs"
60 if test -f ./please-abort
62 echo >>./please-abort killing myself
67 chmod +x ./custom-merge
70 test_expect_success merge
'
72 cat >.gitattributes <<-\EOF &&
79 echo Gaah, should have conflicted
86 test_expect_success
'check merge result in index' '
88 git ls-files -u | grep binary &&
89 git ls-files -u | grep text &&
90 ! (git ls-files -u | grep union)
94 test_expect_success
'check merge result in working tree' '
96 git cat-file -p HEAD:binary >binary-orig &&
97 grep "<<<<<<<" text &&
98 cmp binary-orig binary &&
99 ! grep "<<<<<<<" union &&
105 test_expect_success
'retry the merge with longer context' '
106 echo text conflict-marker-size=32 >>.gitattributes &&
107 git checkout -m text &&
108 sed -ne "/^\([<=>]\)\1\1\1*/{
112 grep ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" actual &&
113 grep "================================" actual &&
114 grep "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" actual
117 test_expect_success
'custom merge backend' '
119 echo "* merge=union" >.gitattributes &&
120 echo "text merge=custom" >>.gitattributes &&
122 git reset --hard anchor &&
123 git config --replace-all \
124 merge.custom.driver "./custom-merge %O %A %B 0 %P" &&
125 git config --replace-all \
126 merge.custom.name "custom merge driver for testing" &&
131 sed -e 1,3d text >check-1 &&
132 o=$(git unpack-file main^:text) &&
133 a=$(git unpack-file side^:text) &&
134 b=$(git unpack-file main:text) &&
135 sh -c "./custom-merge $o $a $b 0 text" &&
136 sed -e 1,3d $a >check-2 &&
137 cmp check-1 check-2 &&
141 test_expect_success
'custom merge backend' '
143 git reset --hard anchor &&
144 git config --replace-all \
145 merge.custom.driver "./custom-merge %O %A %B 1 %P" &&
146 git config --replace-all \
147 merge.custom.name "custom merge driver for testing" &&
151 echo "Eh? should have conflicted"
154 echo "Ok, conflicted"
158 sed -e 1,3d text >check-1 &&
159 o=$(git unpack-file main^:text) &&
160 a=$(git unpack-file anchor:text) &&
161 b=$(git unpack-file main:text) &&
162 sh -c "./custom-merge $o $a $b 0 text" &&
163 sed -e 1,3d $a >check-2 &&
164 cmp check-1 check-2 &&
165 sed -e 1,3d -e 4q $a >check-3 &&
166 echo "path is text" >expect &&
167 cmp expect check-3 &&
171 test_expect_success
!WINDOWS
'custom merge driver that is killed with a signal' '
172 test_when_finished "rm -f output please-abort" &&
174 git reset --hard anchor &&
175 git config --replace-all \
176 merge.custom.driver "./custom-merge %O %A %B 0 %P" &&
177 git config --replace-all \
178 merge.custom.name "custom merge driver for testing" &&
181 echo "* merge=custom" >.gitattributes &&
182 test_must_fail git merge main &&
183 git ls-files -u >output &&
184 git diff --name-only HEAD >>output &&
185 test_must_be_empty output
188 test_expect_success
'up-to-date merge without common ancestor' '
196 git commit -m initial
201 git commit --allow-empty -m initial
206 git fetch ../repo2 main &&
207 git merge --allow-unrelated-histories FETCH_HEAD
211 test_expect_success
'custom merge does not lock index' '
212 git reset --hard anchor &&
213 write_script sleep-an-hour.sh <<-\EOF &&
218 test_write_lines >.gitattributes \
219 "* merge=ours" "text merge=sleep-an-hour" &&
220 test_config merge.ours.driver true &&
221 test_config merge.sleep-an-hour.driver ./sleep-an-hour.sh &&
223 # We are testing that the custom merge driver does not block
224 # index.lock on Windows due to an inherited file handle.
225 # To ensure that the backgrounded process ran sufficiently
226 # long (and has been started in the first place), we do not
227 # ignore the result of the kill command.
228 # By packaging the command in test_when_finished, we get both
229 # the correctness check and the clean-up.
230 test_when_finished "kill \$(cat sleep.pid)" &&
234 test_expect_success
'binary files with union attribute' '
235 git checkout -b bin-main &&
236 printf "base\0" >bin.txt &&
237 echo "bin.txt merge=union" >.gitattributes &&
238 git add bin.txt .gitattributes &&
239 git commit -m base &&
241 printf "one\0" >bin.txt &&
242 git commit -am one &&
244 git checkout -b bin-side HEAD^ &&
245 printf "two\0" >bin.txt &&
246 git commit -am two &&
248 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
250 test_must_fail git merge bin-main >output
252 test_must_fail git merge bin-main 2>output
254 grep -i "warning.*cannot merge.*HEAD vs. bin-main" output