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
45 orig_name="$6" our_name="$7" their_name="$8"
49 echo "theirs is $theirs"
51 echo "orig_name is $orig_name"
52 echo "our_name is $our_name"
53 echo "their_name is $their_name"
64 if test -f ./please-abort
66 echo >>./please-abort killing myself
71 chmod +x ./custom-merge
74 test_expect_success merge
'
76 cat >.gitattributes <<-\EOF &&
83 echo Gaah, should have conflicted
90 test_expect_success
'check merge result in index' '
92 git ls-files -u | grep binary &&
93 git ls-files -u | grep text &&
94 ! (git ls-files -u | grep union)
98 test_expect_success
'check merge result in working tree' '
100 git cat-file -p HEAD:binary >binary-orig &&
101 grep "<<<<<<<" text &&
102 cmp binary-orig binary &&
103 ! grep "<<<<<<<" union &&
109 test_expect_success
'retry the merge with longer context' '
110 echo text conflict-marker-size=32 >>.gitattributes &&
111 git checkout -m text &&
112 sed -ne "/^\([<=>]\)\1\1\1*/{
116 grep ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" actual &&
117 grep "================================" actual &&
118 grep "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" actual
121 test_expect_success
'custom merge backend' '
123 echo "* merge=union" >.gitattributes &&
124 echo "text merge=custom" >>.gitattributes &&
126 git reset --hard anchor &&
127 git config --replace-all \
128 merge.custom.driver "./custom-merge %O %A %B 0 %P %S %X %Y" &&
129 git config --replace-all \
130 merge.custom.name "custom merge driver for testing" &&
135 sed -e 1,3d text >check-1 &&
136 o=$(git unpack-file main^:text) &&
137 a=$(git unpack-file side^:text) &&
138 b=$(git unpack-file main:text) &&
139 base_revid=$(git rev-parse --short main^) &&
140 sh -c "./custom-merge $o $a $b 0 text $base_revid HEAD main" &&
141 sed -e 1,3d $a >check-2 &&
142 cmp check-1 check-2 &&
146 test_expect_success
'custom merge backend' '
148 git reset --hard anchor &&
149 git config --replace-all \
150 merge.custom.driver "./custom-merge %O %A %B 1 %P %S %X %Y" &&
151 git config --replace-all \
152 merge.custom.name "custom merge driver for testing" &&
156 echo "Eh? should have conflicted"
159 echo "Ok, conflicted"
163 sed -e 1,3d text >check-1 &&
164 o=$(git unpack-file main^:text) &&
165 a=$(git unpack-file anchor:text) &&
166 b=$(git unpack-file main:text) &&
167 base_revid=$(git rev-parse --short main^) &&
168 sh -c "./custom-merge $o $a $b 0 text $base_revid HEAD main" &&
169 sed -e 1,3d $a >check-2 &&
170 cmp check-1 check-2 &&
171 sed -e 1,3d -e 4q $a >check-3 &&
172 echo "path is text" >expect &&
173 cmp expect check-3 &&
177 test_expect_success
!WINDOWS
'custom merge driver that is killed with a signal' '
178 test_when_finished "rm -f output please-abort" &&
180 git reset --hard anchor &&
181 git config --replace-all \
182 merge.custom.driver "./custom-merge %O %A %B 0 %P %S %X %Y" &&
183 git config --replace-all \
184 merge.custom.name "custom merge driver for testing" &&
187 echo "* merge=custom" >.gitattributes &&
188 test_must_fail git merge main 2>err &&
189 grep "^error: failed to execute internal merge" err &&
190 git ls-files -u >output &&
191 git diff --name-only HEAD >>output &&
192 test_must_be_empty output
195 test_expect_success
'up-to-date merge without common ancestor' '
203 git commit -m initial
208 git commit --allow-empty -m initial
213 git fetch ../repo2 main &&
214 git merge --allow-unrelated-histories FETCH_HEAD
218 test_expect_success
'custom merge does not lock index' '
219 git reset --hard anchor &&
220 write_script sleep-an-hour.sh <<-\EOF &&
225 test_write_lines >.gitattributes \
226 "* merge=ours" "text merge=sleep-an-hour" &&
227 test_config merge.ours.driver true &&
228 test_config merge.sleep-an-hour.driver ./sleep-an-hour.sh &&
230 # We are testing that the custom merge driver does not block
231 # index.lock on Windows due to an inherited file handle.
232 # To ensure that the backgrounded process ran sufficiently
233 # long (and has been started in the first place), we do not
234 # ignore the result of the kill command.
235 # By packaging the command in test_when_finished, we get both
236 # the correctness check and the clean-up.
237 test_when_finished "kill \$(cat sleep.pid)" &&
241 test_expect_success
'binary files with union attribute' '
242 git checkout -b bin-main &&
243 printf "base\0" >bin.txt &&
244 echo "bin.txt merge=union" >.gitattributes &&
245 git add bin.txt .gitattributes &&
246 git commit -m base &&
248 printf "one\0" >bin.txt &&
249 git commit -am one &&
251 git checkout -b bin-side HEAD^ &&
252 printf "two\0" >bin.txt &&
253 git commit -am two &&
255 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
257 test_must_fail git merge bin-main >output
259 test_must_fail git merge bin-main 2>output
261 grep -i "warning.*cannot merge.*HEAD vs. bin-main" output