]>
Commit | Line | Data |
---|---|---|
47579efc JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Junio C Hamano | |
4 | # | |
5 | ||
6 | test_description='per path merge controlled by merge attribute' | |
7 | ||
5902f5f4 | 8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
10 | ||
e84a26e3 | 11 | TEST_PASSES_SANITIZE_LEAK=true |
47579efc JH |
12 | . ./test-lib.sh |
13 | ||
14 | test_expect_success setup ' | |
15 | ||
16 | for f in text binary union | |
17 | do | |
e6821d09 | 18 | echo Initial >$f && git add $f || return 1 |
47579efc JH |
19 | done && |
20 | test_tick && | |
21 | git commit -m Initial && | |
22 | ||
23 | git branch side && | |
24 | for f in text binary union | |
25 | do | |
5902f5f4 | 26 | echo Main >>$f && git add $f || return 1 |
47579efc JH |
27 | done && |
28 | test_tick && | |
5902f5f4 | 29 | git commit -m Main && |
47579efc JH |
30 | |
31 | git checkout side && | |
32 | for f in text binary union | |
33 | do | |
e6821d09 | 34 | echo Side >>$f && git add $f || return 1 |
47579efc JH |
35 | done && |
36 | test_tick && | |
f3ef6b6b | 37 | git commit -m Side && |
47579efc | 38 | |
42d180dd EN |
39 | git tag anchor && |
40 | ||
41 | cat >./custom-merge <<-\EOF && | |
42 | #!/bin/sh | |
43 | ||
44 | orig="$1" ours="$2" theirs="$3" exit="$4" path=$5 | |
45 | ( | |
46 | echo "orig is $orig" | |
47 | echo "ours is $ours" | |
48 | echo "theirs is $theirs" | |
49 | echo "path is $path" | |
50 | echo "=== orig ===" | |
51 | cat "$orig" | |
52 | echo "=== ours ===" | |
53 | cat "$ours" | |
54 | echo "=== theirs ===" | |
55 | cat "$theirs" | |
56 | ) >"$ours+" | |
57 | cat "$ours+" >"$ours" | |
58 | rm -f "$ours+" | |
2b7b788f JH |
59 | |
60 | if test -f ./please-abort | |
61 | then | |
62 | echo >>./please-abort killing myself | |
63 | kill -9 $$ | |
64 | fi | |
42d180dd EN |
65 | exit "$exit" |
66 | EOF | |
67 | chmod +x ./custom-merge | |
47579efc JH |
68 | ' |
69 | ||
70 | test_expect_success merge ' | |
71 | ||
020b813f ES |
72 | cat >.gitattributes <<-\EOF && |
73 | binary -merge | |
74 | union merge=union | |
75 | EOF | |
47579efc | 76 | |
5902f5f4 | 77 | if git merge main |
47579efc JH |
78 | then |
79 | echo Gaah, should have conflicted | |
80 | false | |
81 | else | |
82 | echo Ok, conflicted. | |
83 | fi | |
84 | ' | |
85 | ||
86 | test_expect_success 'check merge result in index' ' | |
87 | ||
88 | git ls-files -u | grep binary && | |
89 | git ls-files -u | grep text && | |
90 | ! (git ls-files -u | grep union) | |
91 | ||
92 | ' | |
93 | ||
94 | test_expect_success 'check merge result in working tree' ' | |
95 | ||
96 | git cat-file -p HEAD:binary >binary-orig && | |
97 | grep "<<<<<<<" text && | |
98 | cmp binary-orig binary && | |
99 | ! grep "<<<<<<<" union && | |
5902f5f4 | 100 | grep Main union && |
47579efc JH |
101 | grep Side union |
102 | ||
103 | ' | |
104 | ||
4c734803 JH |
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*/{ | |
109 | s/ .*$// | |
110 | p | |
111 | }" >actual text && | |
112 | grep ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" actual && | |
113 | grep "================================" actual && | |
114 | grep "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" actual | |
115 | ' | |
116 | ||
f3ef6b6b JH |
117 | test_expect_success 'custom merge backend' ' |
118 | ||
119 | echo "* merge=union" >.gitattributes && | |
120 | echo "text merge=custom" >>.gitattributes && | |
121 | ||
122 | git reset --hard anchor && | |
123 | git config --replace-all \ | |
ef45bb1f | 124 | merge.custom.driver "./custom-merge %O %A %B 0 %P" && |
153920da JH |
125 | git config --replace-all \ |
126 | merge.custom.name "custom merge driver for testing" && | |
f3ef6b6b | 127 | |
5902f5f4 | 128 | git merge main && |
f3ef6b6b JH |
129 | |
130 | cmp binary union && | |
131 | sed -e 1,3d text >check-1 && | |
5902f5f4 | 132 | o=$(git unpack-file main^:text) && |
3604e7c5 | 133 | a=$(git unpack-file side^:text) && |
5902f5f4 | 134 | b=$(git unpack-file main:text) && |
c76b84a1 | 135 | sh -c "./custom-merge $o $a $b 0 text" && |
f3ef6b6b JH |
136 | sed -e 1,3d $a >check-2 && |
137 | cmp check-1 check-2 && | |
138 | rm -f $o $a $b | |
139 | ' | |
140 | ||
141 | test_expect_success 'custom merge backend' ' | |
142 | ||
143 | git reset --hard anchor && | |
144 | git config --replace-all \ | |
ef45bb1f | 145 | merge.custom.driver "./custom-merge %O %A %B 1 %P" && |
153920da JH |
146 | git config --replace-all \ |
147 | merge.custom.name "custom merge driver for testing" && | |
f3ef6b6b | 148 | |
5902f5f4 | 149 | if git merge main |
f3ef6b6b JH |
150 | then |
151 | echo "Eh? should have conflicted" | |
152 | false | |
153 | else | |
154 | echo "Ok, conflicted" | |
155 | fi && | |
156 | ||
157 | cmp binary union && | |
158 | sed -e 1,3d text >check-1 && | |
5902f5f4 | 159 | o=$(git unpack-file main^:text) && |
3604e7c5 | 160 | a=$(git unpack-file anchor:text) && |
5902f5f4 | 161 | b=$(git unpack-file main:text) && |
c76b84a1 | 162 | sh -c "./custom-merge $o $a $b 0 text" && |
f3ef6b6b JH |
163 | sed -e 1,3d $a >check-2 && |
164 | cmp check-1 check-2 && | |
ef45bb1f JH |
165 | sed -e 1,3d -e 4q $a >check-3 && |
166 | echo "path is text" >expect && | |
167 | cmp expect check-3 && | |
f3ef6b6b JH |
168 | rm -f $o $a $b |
169 | ' | |
170 | ||
34d765e7 | 171 | test_expect_success !WINDOWS 'custom merge driver that is killed with a signal' ' |
2b7b788f JH |
172 | test_when_finished "rm -f output please-abort" && |
173 | ||
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" && | |
179 | ||
180 | >./please-abort && | |
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 | |
186 | ' | |
187 | ||
42716660 | 188 | test_expect_success 'up-to-date merge without common ancestor' ' |
6693fb3f EN |
189 | git init repo1 && |
190 | git init repo2 && | |
42716660 MV |
191 | test_tick && |
192 | ( | |
193 | cd repo1 && | |
194 | >a && | |
195 | git add a && | |
196 | git commit -m initial | |
197 | ) && | |
198 | test_tick && | |
199 | ( | |
200 | cd repo2 && | |
201 | git commit --allow-empty -m initial | |
202 | ) && | |
203 | test_tick && | |
204 | ( | |
205 | cd repo1 && | |
5902f5f4 | 206 | git fetch ../repo2 main && |
e379fdf3 | 207 | git merge --allow-unrelated-histories FETCH_HEAD |
42716660 MV |
208 | ) |
209 | ' | |
210 | ||
05d1ed61 | 211 | test_expect_success 'custom merge does not lock index' ' |
ad65f7e3 | 212 | git reset --hard anchor && |
a7d6bcc3 JS |
213 | write_script sleep-an-hour.sh <<-\EOF && |
214 | sleep 3600 & | |
5babb5bd | 215 | echo $! >sleep.pid |
ad65f7e3 BW |
216 | EOF |
217 | ||
218 | test_write_lines >.gitattributes \ | |
a7d6bcc3 | 219 | "* merge=ours" "text merge=sleep-an-hour" && |
ad65f7e3 | 220 | test_config merge.ours.driver true && |
a7d6bcc3 | 221 | test_config merge.sleep-an-hour.driver ./sleep-an-hour.sh && |
fdf4f6c7 JS |
222 | |
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)" && | |
5902f5f4 | 231 | git merge main |
ad65f7e3 BW |
232 | ' |
233 | ||
7d879ad7 JK |
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 && | |
240 | ||
241 | printf "one\0" >bin.txt && | |
242 | git commit -am one && | |
243 | ||
244 | git checkout -b bin-side HEAD^ && | |
245 | printf "two\0" >bin.txt && | |
246 | git commit -am two && | |
247 | ||
24dbdab5 EN |
248 | if test "$GIT_TEST_MERGE_ALGORITHM" = ort |
249 | then | |
250 | test_must_fail git merge bin-main >output | |
251 | else | |
252 | test_must_fail git merge bin-main 2>output | |
253 | fi && | |
254 | grep -i "warning.*cannot merge.*HEAD vs. bin-main" output | |
7d879ad7 JK |
255 | ' |
256 | ||
47579efc | 257 | test_done |