]>
Commit | Line | Data |
---|---|---|
a85d1b69 LH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Lars Hjemli | |
4 | # | |
5 | ||
6 | test_description='git-merge | |
7 | ||
8 | Testing basic merge operations/option parsing.' | |
9 | ||
10 | . ./test-lib.sh | |
11 | ||
12 | cat >file <<EOF | |
13 | 1 | |
14 | 2 | |
15 | 3 | |
16 | 4 | |
17 | 5 | |
18 | 6 | |
19 | 7 | |
20 | 8 | |
21 | 9 | |
22 | EOF | |
23 | ||
24 | cat >file.1 <<EOF | |
25 | 1 X | |
26 | 2 | |
27 | 3 | |
28 | 4 | |
29 | 5 | |
30 | 6 | |
31 | 7 | |
32 | 8 | |
33 | 9 | |
34 | EOF | |
35 | ||
36 | cat >file.5 <<EOF | |
37 | 1 | |
38 | 2 | |
39 | 3 | |
40 | 4 | |
41 | 5 X | |
42 | 6 | |
43 | 7 | |
44 | 8 | |
45 | 9 | |
46 | EOF | |
47 | ||
48 | cat >file.9 <<EOF | |
49 | 1 | |
50 | 2 | |
51 | 3 | |
52 | 4 | |
53 | 5 | |
54 | 6 | |
55 | 7 | |
56 | 8 | |
57 | 9 X | |
58 | EOF | |
59 | ||
60 | cat >result.1 <<EOF | |
61 | 1 X | |
62 | 2 | |
63 | 3 | |
64 | 4 | |
65 | 5 | |
66 | 6 | |
67 | 7 | |
68 | 8 | |
69 | 9 | |
70 | EOF | |
71 | ||
72 | cat >result.1-5 <<EOF | |
73 | 1 X | |
74 | 2 | |
75 | 3 | |
76 | 4 | |
77 | 5 X | |
78 | 6 | |
79 | 7 | |
80 | 8 | |
81 | 9 | |
82 | EOF | |
83 | ||
84 | cat >result.1-5-9 <<EOF | |
85 | 1 X | |
86 | 2 | |
87 | 3 | |
88 | 4 | |
89 | 5 X | |
90 | 6 | |
91 | 7 | |
92 | 8 | |
93 | 9 X | |
94 | EOF | |
95 | ||
96 | create_merge_msgs() { | |
97 | echo "Merge commit 'c2'" >msg.1-5 && | |
98 | echo "Merge commit 'c2'; commit 'c3'" >msg.1-5-9 && | |
99 | echo "Squashed commit of the following:" >squash.1 && | |
100 | echo >>squash.1 && | |
101 | git log --no-merges ^HEAD c1 >>squash.1 && | |
102 | echo "Squashed commit of the following:" >squash.1-5 && | |
103 | echo >>squash.1-5 && | |
104 | git log --no-merges ^HEAD c2 >>squash.1-5 && | |
105 | echo "Squashed commit of the following:" >squash.1-5-9 && | |
106 | echo >>squash.1-5-9 && | |
107 | git log --no-merges ^HEAD c2 c3 >>squash.1-5-9 | |
108 | } | |
109 | ||
110 | verify_diff() { | |
82ebb0b6 | 111 | if ! test_cmp "$1" "$2" |
a85d1b69 LH |
112 | then |
113 | echo "$3" | |
114 | false | |
115 | fi | |
116 | } | |
117 | ||
118 | verify_merge() { | |
119 | verify_diff "$2" "$1" "[OOPS] bad merge result" && | |
120 | if test $(git ls-files -u | wc -l) -gt 0 | |
121 | then | |
122 | echo "[OOPS] unmerged files" | |
123 | false | |
124 | fi && | |
125 | if ! git diff --exit-code | |
126 | then | |
127 | echo "[OOPS] working tree != index" | |
128 | false | |
129 | fi && | |
130 | if test -n "$3" | |
131 | then | |
132 | git show -s --pretty=format:%s HEAD >msg.act && | |
133 | verify_diff "$3" msg.act "[OOPS] bad merge message" | |
134 | fi | |
135 | } | |
136 | ||
137 | verify_head() { | |
138 | if test "$1" != "$(git rev-parse HEAD)" | |
139 | then | |
140 | echo "[OOPS] HEAD != $1" | |
141 | false | |
142 | fi | |
143 | } | |
144 | ||
145 | verify_parents() { | |
146 | i=1 | |
147 | while test $# -gt 0 | |
148 | do | |
149 | if test "$1" != "$(git rev-parse HEAD^$i)" | |
150 | then | |
151 | echo "[OOPS] HEAD^$i != $1" | |
152 | return 1 | |
153 | fi | |
154 | i=$(expr $i + 1) | |
155 | shift | |
156 | done | |
157 | } | |
158 | ||
159 | verify_mergeheads() { | |
160 | i=1 | |
161 | if ! test -f .git/MERGE_HEAD | |
162 | then | |
163 | echo "[OOPS] MERGE_HEAD is missing" | |
164 | false | |
165 | fi && | |
166 | while test $# -gt 0 | |
167 | do | |
b4ce54fc | 168 | head=$(head -n $i .git/MERGE_HEAD | sed -ne \$p) |
a85d1b69 LH |
169 | if test "$1" != "$head" |
170 | then | |
171 | echo "[OOPS] MERGE_HEAD $i != $1" | |
172 | return 1 | |
173 | fi | |
174 | i=$(expr $i + 1) | |
175 | shift | |
176 | done | |
177 | } | |
178 | ||
179 | verify_no_mergehead() { | |
180 | if test -f .git/MERGE_HEAD | |
181 | then | |
182 | echo "[OOPS] MERGE_HEAD exists" | |
183 | false | |
184 | fi | |
185 | } | |
186 | ||
187 | ||
188 | test_expect_success 'setup' ' | |
189 | git add file && | |
190 | test_tick && | |
191 | git commit -m "commit 0" && | |
192 | git tag c0 && | |
193 | c0=$(git rev-parse HEAD) && | |
194 | cp file.1 file && | |
195 | git add file && | |
196 | test_tick && | |
197 | git commit -m "commit 1" && | |
198 | git tag c1 && | |
199 | c1=$(git rev-parse HEAD) && | |
200 | git reset --hard "$c0" && | |
201 | cp file.5 file && | |
202 | git add file && | |
203 | test_tick && | |
204 | git commit -m "commit 2" && | |
205 | git tag c2 && | |
206 | c2=$(git rev-parse HEAD) && | |
207 | git reset --hard "$c0" && | |
208 | cp file.9 file && | |
209 | git add file && | |
210 | test_tick && | |
211 | git commit -m "commit 3" && | |
212 | git tag c3 && | |
213 | c3=$(git rev-parse HEAD) | |
214 | git reset --hard "$c0" && | |
215 | create_merge_msgs | |
216 | ' | |
217 | ||
218 | test_debug 'gitk --all' | |
219 | ||
220 | test_expect_success 'test option parsing' ' | |
221 | if git merge -$ c1 | |
222 | then | |
223 | echo "[OOPS] -$ accepted" | |
224 | false | |
225 | fi && | |
226 | if git merge --no-such c1 | |
227 | then | |
228 | echo "[OOPS] --no-such accepted" | |
229 | false | |
230 | fi && | |
231 | if git merge -s foobar c1 | |
232 | then | |
233 | echo "[OOPS] -s foobar accepted" | |
234 | false | |
235 | fi && | |
236 | if git merge -s=foobar c1 | |
237 | then | |
238 | echo "[OOPS] -s=foobar accepted" | |
239 | false | |
240 | fi && | |
241 | if git merge -m | |
242 | then | |
243 | echo "[OOPS] missing commit msg accepted" | |
244 | false | |
245 | fi && | |
246 | if git merge | |
247 | then | |
248 | echo "[OOPS] missing commit references accepted" | |
249 | false | |
250 | fi | |
251 | ' | |
252 | ||
253 | test_expect_success 'merge c0 with c1' ' | |
254 | git reset --hard c0 && | |
255 | git merge c1 && | |
256 | verify_merge file result.1 && | |
257 | verify_head "$c1" | |
258 | ' | |
259 | ||
260 | test_debug 'gitk --all' | |
261 | ||
262 | test_expect_success 'merge c1 with c2' ' | |
263 | git reset --hard c1 && | |
264 | test_tick && | |
265 | git merge c2 && | |
266 | verify_merge file result.1-5 msg.1-5 && | |
267 | verify_parents $c1 $c2 | |
268 | ' | |
269 | ||
270 | test_debug 'gitk --all' | |
271 | ||
272 | test_expect_success 'merge c1 with c2 and c3' ' | |
273 | git reset --hard c1 && | |
274 | test_tick && | |
275 | git merge c2 c3 && | |
276 | verify_merge file result.1-5-9 msg.1-5-9 && | |
277 | verify_parents $c1 $c2 $c3 | |
278 | ' | |
279 | ||
280 | test_debug 'gitk --all' | |
281 | ||
282 | test_expect_success 'merge c0 with c1 (no-commit)' ' | |
283 | git reset --hard c0 && | |
284 | git merge --no-commit c1 && | |
285 | verify_merge file result.1 && | |
286 | verify_head $c1 | |
287 | ' | |
288 | ||
289 | test_debug 'gitk --all' | |
290 | ||
291 | test_expect_success 'merge c1 with c2 (no-commit)' ' | |
292 | git reset --hard c1 && | |
293 | git merge --no-commit c2 && | |
294 | verify_merge file result.1-5 && | |
295 | verify_head $c1 && | |
296 | verify_mergeheads $c2 | |
297 | ' | |
298 | ||
299 | test_debug 'gitk --all' | |
300 | ||
301 | test_expect_success 'merge c1 with c2 and c3 (no-commit)' ' | |
302 | git reset --hard c1 && | |
303 | git merge --no-commit c2 c3 && | |
304 | verify_merge file result.1-5-9 && | |
305 | verify_head $c1 && | |
306 | verify_mergeheads $c2 $c3 | |
307 | ' | |
308 | ||
309 | test_debug 'gitk --all' | |
310 | ||
311 | test_expect_success 'merge c0 with c1 (squash)' ' | |
312 | git reset --hard c0 && | |
313 | git merge --squash c1 && | |
314 | verify_merge file result.1 && | |
315 | verify_head $c0 && | |
316 | verify_no_mergehead && | |
317 | verify_diff squash.1 .git/SQUASH_MSG "[OOPS] bad squash message" | |
318 | ' | |
319 | ||
320 | test_debug 'gitk --all' | |
321 | ||
322 | test_expect_success 'merge c1 with c2 (squash)' ' | |
323 | git reset --hard c1 && | |
324 | git merge --squash c2 && | |
325 | verify_merge file result.1-5 && | |
326 | verify_head $c1 && | |
327 | verify_no_mergehead && | |
328 | verify_diff squash.1-5 .git/SQUASH_MSG "[OOPS] bad squash message" | |
329 | ' | |
330 | ||
331 | test_debug 'gitk --all' | |
332 | ||
333 | test_expect_success 'merge c1 with c2 and c3 (squash)' ' | |
334 | git reset --hard c1 && | |
335 | git merge --squash c2 c3 && | |
336 | verify_merge file result.1-5-9 && | |
337 | verify_head $c1 && | |
338 | verify_no_mergehead && | |
339 | verify_diff squash.1-5-9 .git/SQUASH_MSG "[OOPS] bad squash message" | |
340 | ' | |
341 | ||
342 | test_debug 'gitk --all' | |
343 | ||
aec7b362 LH |
344 | test_expect_success 'merge c1 with c2 (no-commit in config)' ' |
345 | git reset --hard c1 && | |
346 | git config branch.master.mergeoptions "--no-commit" && | |
347 | git merge c2 && | |
348 | verify_merge file result.1-5 && | |
349 | verify_head $c1 && | |
350 | verify_mergeheads $c2 | |
351 | ' | |
352 | ||
353 | test_debug 'gitk --all' | |
354 | ||
355 | test_expect_success 'merge c1 with c2 (squash in config)' ' | |
356 | git reset --hard c1 && | |
357 | git config branch.master.mergeoptions "--squash" && | |
358 | git merge c2 && | |
359 | verify_merge file result.1-5 && | |
360 | verify_head $c1 && | |
361 | verify_no_mergehead && | |
362 | verify_diff squash.1-5 .git/SQUASH_MSG "[OOPS] bad squash message" | |
363 | ' | |
364 | ||
365 | test_debug 'gitk --all' | |
366 | ||
367 | test_expect_success 'override config option -n' ' | |
368 | git reset --hard c1 && | |
369 | git config branch.master.mergeoptions "-n" && | |
370 | test_tick && | |
371 | git merge --summary c2 >diffstat.txt && | |
372 | verify_merge file result.1-5 msg.1-5 && | |
373 | verify_parents $c1 $c2 && | |
aadbe44f | 374 | if ! grep "^ file | *2 +-$" diffstat.txt |
aec7b362 LH |
375 | then |
376 | echo "[OOPS] diffstat was not generated" | |
377 | fi | |
378 | ' | |
379 | ||
380 | test_debug 'gitk --all' | |
381 | ||
382 | test_expect_success 'override config option --summary' ' | |
383 | git reset --hard c1 && | |
384 | git config branch.master.mergeoptions "--summary" && | |
385 | test_tick && | |
386 | git merge -n c2 >diffstat.txt && | |
387 | verify_merge file result.1-5 msg.1-5 && | |
388 | verify_parents $c1 $c2 && | |
aadbe44f | 389 | if grep "^ file | *2 +-$" diffstat.txt |
aec7b362 LH |
390 | then |
391 | echo "[OOPS] diffstat was generated" | |
392 | false | |
393 | fi | |
394 | ' | |
395 | ||
396 | test_debug 'gitk --all' | |
397 | ||
d08af0ad LH |
398 | test_expect_success 'merge c1 with c2 (override --no-commit)' ' |
399 | git reset --hard c1 && | |
400 | git config branch.master.mergeoptions "--no-commit" && | |
401 | test_tick && | |
402 | git merge --commit c2 && | |
403 | verify_merge file result.1-5 msg.1-5 && | |
404 | verify_parents $c1 $c2 | |
405 | ' | |
406 | ||
407 | test_debug 'gitk --all' | |
408 | ||
409 | test_expect_success 'merge c1 with c2 (override --squash)' ' | |
410 | git reset --hard c1 && | |
411 | git config branch.master.mergeoptions "--squash" && | |
412 | test_tick && | |
413 | git merge --no-squash c2 && | |
414 | verify_merge file result.1-5 msg.1-5 && | |
415 | verify_parents $c1 $c2 | |
416 | ' | |
417 | ||
418 | test_debug 'gitk --all' | |
419 | ||
d66424c4 LH |
420 | test_expect_success 'merge c0 with c1 (no-ff)' ' |
421 | git reset --hard c0 && | |
e6d1f76c | 422 | git config branch.master.mergeoptions "" && |
d66424c4 LH |
423 | test_tick && |
424 | git merge --no-ff c1 && | |
425 | verify_merge file result.1 && | |
426 | verify_parents $c0 $c1 | |
427 | ' | |
428 | ||
429 | test_debug 'gitk --all' | |
430 | ||
e6d1f76c GP |
431 | test_expect_success 'combining --squash and --no-ff is refused' ' |
432 | test_must_fail git merge --squash --no-ff c1 && | |
433 | test_must_fail git merge --no-ff --squash c1 | |
434 | ' | |
435 | ||
d66424c4 LH |
436 | test_expect_success 'merge c0 with c1 (ff overrides no-ff)' ' |
437 | git reset --hard c0 && | |
438 | git config branch.master.mergeoptions "--no-ff" && | |
439 | git merge --ff c1 && | |
440 | verify_merge file result.1 && | |
441 | verify_head $c1 | |
442 | ' | |
443 | ||
444 | test_debug 'gitk --all' | |
445 | ||
a85d1b69 | 446 | test_done |