]>
Commit | Line | Data |
---|---|---|
a85d1b69 LH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Lars Hjemli | |
4 | # | |
5 | ||
47a528ad | 6 | test_description='git merge |
a85d1b69 | 7 | |
4c073457 JN |
8 | Testing basic merge operations/option parsing. |
9 | ||
10 | ! [c0] commit 0 | |
11 | ! [c1] commit 1 | |
12 | ! [c2] commit 2 | |
13 | ! [c3] commit 3 | |
14 | ! [c4] c4 | |
15 | ! [c5] c5 | |
16 | ! [c6] c6 | |
17 | * [master] Merge commit 'c1' | |
18 | -------- | |
19 | - [master] Merge commit 'c1' | |
20 | + * [c1] commit 1 | |
21 | + [c6] c6 | |
22 | + [c5] c5 | |
23 | ++ [c4] c4 | |
24 | ++++ [c3] commit 3 | |
25 | + [c2] commit 2 | |
26 | +++++++* [c0] commit 0 | |
27 | ' | |
a85d1b69 LH |
28 | |
29 | . ./test-lib.sh | |
30 | ||
4c073457 JN |
31 | test_expect_success 'set up test data and helpers' ' |
32 | printf "%s\n" 1 2 3 4 5 6 7 8 9 >file && | |
33 | printf "%s\n" "1 X" 2 3 4 5 6 7 8 9 >file.1 && | |
34 | printf "%s\n" 1 2 3 4 "5 X" 6 7 8 9 >file.5 && | |
35 | printf "%s\n" 1 2 3 4 5 6 7 8 "9 X" >file.9 && | |
36 | printf "%s\n" "1 X" 2 3 4 5 6 7 8 9 >result.1 && | |
37 | printf "%s\n" "1 X" 2 3 4 "5 X" 6 7 8 9 >result.1-5 && | |
38 | printf "%s\n" "1 X" 2 3 4 "5 X" 6 7 8 "9 X" >result.1-5-9 && | |
39 | ||
40 | create_merge_msgs() { | |
41 | echo "Merge commit '\''c2'\''" >msg.1-5 && | |
42 | echo "Merge commit '\''c2'\''; commit '\''c3'\''" >msg.1-5-9 && | |
43 | { | |
44 | echo "Squashed commit of the following:" && | |
45 | echo && | |
46 | git log --no-merges ^HEAD c1 | |
47 | } >squash.1 && | |
48 | { | |
49 | echo "Squashed commit of the following:" && | |
50 | echo && | |
51 | git log --no-merges ^HEAD c2 | |
52 | } >squash.1-5 && | |
53 | { | |
54 | echo "Squashed commit of the following:" && | |
55 | echo && | |
56 | git log --no-merges ^HEAD c2 c3 | |
57 | } >squash.1-5-9 && | |
58 | echo >msg.nolog && | |
59 | { | |
60 | echo "* commit '\''c3'\'':" && | |
61 | echo " commit 3" && | |
62 | echo | |
63 | } >msg.log | |
64 | } && | |
65 | ||
66 | verify_merge() { | |
67 | test_cmp "$2" "$1" && | |
68 | git update-index --refresh && | |
69 | git diff --exit-code && | |
70 | if test -n "$3" | |
a85d1b69 | 71 | then |
4c073457 JN |
72 | git show -s --pretty=format:%s HEAD >msg.act && |
73 | test_cmp "$3" msg.act | |
a85d1b69 | 74 | fi |
4c073457 JN |
75 | } && |
76 | ||
77 | verify_head() { | |
78 | echo "$1" >head.expected && | |
79 | git rev-parse HEAD >head.actual && | |
80 | test_cmp head.expected head.actual | |
81 | } && | |
82 | ||
83 | verify_parents() { | |
84 | printf "%s\n" "$@" >parents.expected && | |
85 | >parents.actual && | |
86 | i=1 && | |
87 | while test $i -le $# | |
88 | do | |
89 | git rev-parse HEAD^$i >>parents.actual && | |
90 | i=$(expr $i + 1) || | |
a85d1b69 | 91 | return 1 |
4c073457 JN |
92 | done && |
93 | test_cmp parents.expected parents.actual | |
94 | } && | |
a85d1b69 | 95 | |
4c073457 JN |
96 | verify_mergeheads() { |
97 | printf "%s\n" "$@" >mergehead.expected && | |
98 | test_cmp mergehead.expected .git/MERGE_HEAD | |
99 | } && | |
a85d1b69 | 100 | |
4c073457 JN |
101 | verify_no_mergehead() { |
102 | ! test -e .git/MERGE_HEAD | |
103 | } | |
104 | ' | |
a85d1b69 LH |
105 | |
106 | test_expect_success 'setup' ' | |
107 | git add file && | |
108 | test_tick && | |
109 | git commit -m "commit 0" && | |
110 | git tag c0 && | |
111 | c0=$(git rev-parse HEAD) && | |
112 | cp file.1 file && | |
113 | git add file && | |
114 | test_tick && | |
115 | git commit -m "commit 1" && | |
116 | git tag c1 && | |
117 | c1=$(git rev-parse HEAD) && | |
118 | git reset --hard "$c0" && | |
119 | cp file.5 file && | |
120 | git add file && | |
121 | test_tick && | |
122 | git commit -m "commit 2" && | |
123 | git tag c2 && | |
124 | c2=$(git rev-parse HEAD) && | |
125 | git reset --hard "$c0" && | |
126 | cp file.9 file && | |
127 | git add file && | |
128 | test_tick && | |
129 | git commit -m "commit 3" && | |
130 | git tag c3 && | |
131 | c3=$(git rev-parse HEAD) | |
132 | git reset --hard "$c0" && | |
133 | create_merge_msgs | |
134 | ' | |
135 | ||
df516fb5 | 136 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 | 137 | |
74f5b7fb | 138 | test_expect_success 'test option parsing' ' |
01941bd5 JS |
139 | test_must_fail git merge -$ c1 && |
140 | test_must_fail git merge --no-such c1 && | |
141 | test_must_fail git merge -s foobar c1 && | |
142 | test_must_fail git merge -s=foobar c1 && | |
143 | test_must_fail git merge -m && | |
144 | test_must_fail git merge | |
a85d1b69 LH |
145 | ' |
146 | ||
dce61e72 MV |
147 | test_expect_success 'reject non-strategy with a git-merge-foo name' ' |
148 | test_must_fail git merge -s index c1 | |
149 | ' | |
150 | ||
a85d1b69 LH |
151 | test_expect_success 'merge c0 with c1' ' |
152 | git reset --hard c0 && | |
153 | git merge c1 && | |
154 | verify_merge file result.1 && | |
155 | verify_head "$c1" | |
156 | ' | |
157 | ||
df516fb5 | 158 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 | 159 | |
13474835 BG |
160 | test_expect_success 'merge c0 with c1 with --ff-only' ' |
161 | git reset --hard c0 && | |
162 | git merge --ff-only c1 && | |
163 | git merge --ff-only HEAD c0 c1 && | |
164 | verify_merge file result.1 && | |
165 | verify_head "$c1" | |
166 | ' | |
167 | ||
df516fb5 | 168 | test_debug 'git log --graph --decorate --oneline --all' |
13474835 | 169 | |
a85d1b69 LH |
170 | test_expect_success 'merge c1 with c2' ' |
171 | git reset --hard c1 && | |
172 | test_tick && | |
173 | git merge c2 && | |
174 | verify_merge file result.1-5 msg.1-5 && | |
175 | verify_parents $c1 $c2 | |
176 | ' | |
177 | ||
df516fb5 | 178 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 LH |
179 | |
180 | test_expect_success 'merge c1 with c2 and c3' ' | |
181 | git reset --hard c1 && | |
182 | test_tick && | |
183 | git merge c2 c3 && | |
184 | verify_merge file result.1-5-9 msg.1-5-9 && | |
185 | verify_parents $c1 $c2 $c3 | |
186 | ' | |
187 | ||
df516fb5 | 188 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 | 189 | |
13474835 BG |
190 | test_expect_success 'failing merges with --ff-only' ' |
191 | git reset --hard c1 && | |
192 | test_tick && | |
193 | test_must_fail git merge --ff-only c2 && | |
194 | test_must_fail git merge --ff-only c3 && | |
195 | test_must_fail git merge --ff-only c2 c3 | |
196 | ' | |
197 | ||
a85d1b69 LH |
198 | test_expect_success 'merge c0 with c1 (no-commit)' ' |
199 | git reset --hard c0 && | |
200 | git merge --no-commit c1 && | |
201 | verify_merge file result.1 && | |
202 | verify_head $c1 | |
203 | ' | |
204 | ||
df516fb5 | 205 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 LH |
206 | |
207 | test_expect_success 'merge c1 with c2 (no-commit)' ' | |
208 | git reset --hard c1 && | |
209 | git merge --no-commit c2 && | |
210 | verify_merge file result.1-5 && | |
211 | verify_head $c1 && | |
212 | verify_mergeheads $c2 | |
213 | ' | |
214 | ||
df516fb5 | 215 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 LH |
216 | |
217 | test_expect_success 'merge c1 with c2 and c3 (no-commit)' ' | |
218 | git reset --hard c1 && | |
219 | git merge --no-commit c2 c3 && | |
220 | verify_merge file result.1-5-9 && | |
221 | verify_head $c1 && | |
222 | verify_mergeheads $c2 $c3 | |
223 | ' | |
224 | ||
df516fb5 | 225 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 LH |
226 | |
227 | test_expect_success 'merge c0 with c1 (squash)' ' | |
228 | git reset --hard c0 && | |
229 | git merge --squash c1 && | |
230 | verify_merge file result.1 && | |
231 | verify_head $c0 && | |
232 | verify_no_mergehead && | |
4c073457 | 233 | test_cmp squash.1 .git/SQUASH_MSG |
a85d1b69 LH |
234 | ' |
235 | ||
df516fb5 | 236 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 | 237 | |
13474835 BG |
238 | test_expect_success 'merge c0 with c1 (squash, ff-only)' ' |
239 | git reset --hard c0 && | |
240 | git merge --squash --ff-only c1 && | |
241 | verify_merge file result.1 && | |
242 | verify_head $c0 && | |
243 | verify_no_mergehead && | |
4c073457 | 244 | test_cmp squash.1 .git/SQUASH_MSG |
13474835 BG |
245 | ' |
246 | ||
df516fb5 | 247 | test_debug 'git log --graph --decorate --oneline --all' |
13474835 | 248 | |
a85d1b69 LH |
249 | test_expect_success 'merge c1 with c2 (squash)' ' |
250 | git reset --hard c1 && | |
251 | git merge --squash c2 && | |
252 | verify_merge file result.1-5 && | |
253 | verify_head $c1 && | |
254 | verify_no_mergehead && | |
4c073457 | 255 | test_cmp squash.1-5 .git/SQUASH_MSG |
a85d1b69 LH |
256 | ' |
257 | ||
df516fb5 | 258 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 | 259 | |
13474835 BG |
260 | test_expect_success 'unsuccesful merge of c1 with c2 (squash, ff-only)' ' |
261 | git reset --hard c1 && | |
262 | test_must_fail git merge --squash --ff-only c2 | |
263 | ' | |
264 | ||
df516fb5 | 265 | test_debug 'git log --graph --decorate --oneline --all' |
13474835 | 266 | |
a85d1b69 LH |
267 | test_expect_success 'merge c1 with c2 and c3 (squash)' ' |
268 | git reset --hard c1 && | |
269 | git merge --squash c2 c3 && | |
270 | verify_merge file result.1-5-9 && | |
271 | verify_head $c1 && | |
272 | verify_no_mergehead && | |
4c073457 | 273 | test_cmp squash.1-5-9 .git/SQUASH_MSG |
a85d1b69 LH |
274 | ' |
275 | ||
df516fb5 | 276 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 | 277 | |
aec7b362 LH |
278 | test_expect_success 'merge c1 with c2 (no-commit in config)' ' |
279 | git reset --hard c1 && | |
280 | git config branch.master.mergeoptions "--no-commit" && | |
281 | git merge c2 && | |
282 | verify_merge file result.1-5 && | |
283 | verify_head $c1 && | |
284 | verify_mergeheads $c2 | |
285 | ' | |
286 | ||
df516fb5 | 287 | test_debug 'git log --graph --decorate --oneline --all' |
aec7b362 LH |
288 | |
289 | test_expect_success 'merge c1 with c2 (squash in config)' ' | |
290 | git reset --hard c1 && | |
291 | git config branch.master.mergeoptions "--squash" && | |
292 | git merge c2 && | |
293 | verify_merge file result.1-5 && | |
294 | verify_head $c1 && | |
295 | verify_no_mergehead && | |
4c073457 | 296 | test_cmp squash.1-5 .git/SQUASH_MSG |
aec7b362 LH |
297 | ' |
298 | ||
df516fb5 | 299 | test_debug 'git log --graph --decorate --oneline --all' |
aec7b362 | 300 | |
d8abe148 | 301 | test_expect_success 'override config option -n with --summary' ' |
aec7b362 LH |
302 | git reset --hard c1 && |
303 | git config branch.master.mergeoptions "-n" && | |
304 | test_tick && | |
305 | git merge --summary c2 >diffstat.txt && | |
306 | verify_merge file result.1-5 msg.1-5 && | |
307 | verify_parents $c1 $c2 && | |
aadbe44f | 308 | if ! grep "^ file | *2 +-$" diffstat.txt |
aec7b362 | 309 | then |
d8abe148 SG |
310 | echo "[OOPS] diffstat was not generated with --summary" |
311 | false | |
312 | fi | |
313 | ' | |
314 | ||
315 | test_expect_success 'override config option -n with --stat' ' | |
316 | git reset --hard c1 && | |
317 | git config branch.master.mergeoptions "-n" && | |
318 | test_tick && | |
319 | git merge --stat c2 >diffstat.txt && | |
320 | verify_merge file result.1-5 msg.1-5 && | |
321 | verify_parents $c1 $c2 && | |
322 | if ! grep "^ file | *2 +-$" diffstat.txt | |
323 | then | |
324 | echo "[OOPS] diffstat was not generated with --stat" | |
325 | false | |
aec7b362 LH |
326 | fi |
327 | ' | |
328 | ||
df516fb5 | 329 | test_debug 'git log --graph --decorate --oneline --all' |
aec7b362 | 330 | |
d8abe148 | 331 | test_expect_success 'override config option --stat' ' |
aec7b362 | 332 | git reset --hard c1 && |
d8abe148 | 333 | git config branch.master.mergeoptions "--stat" && |
aec7b362 LH |
334 | test_tick && |
335 | git merge -n c2 >diffstat.txt && | |
336 | verify_merge file result.1-5 msg.1-5 && | |
337 | verify_parents $c1 $c2 && | |
aadbe44f | 338 | if grep "^ file | *2 +-$" diffstat.txt |
aec7b362 LH |
339 | then |
340 | echo "[OOPS] diffstat was generated" | |
341 | false | |
342 | fi | |
343 | ' | |
344 | ||
df516fb5 | 345 | test_debug 'git log --graph --decorate --oneline --all' |
aec7b362 | 346 | |
d08af0ad LH |
347 | test_expect_success 'merge c1 with c2 (override --no-commit)' ' |
348 | git reset --hard c1 && | |
349 | git config branch.master.mergeoptions "--no-commit" && | |
350 | test_tick && | |
351 | git merge --commit c2 && | |
352 | verify_merge file result.1-5 msg.1-5 && | |
353 | verify_parents $c1 $c2 | |
354 | ' | |
355 | ||
df516fb5 | 356 | test_debug 'git log --graph --decorate --oneline --all' |
d08af0ad LH |
357 | |
358 | test_expect_success 'merge c1 with c2 (override --squash)' ' | |
359 | git reset --hard c1 && | |
360 | git config branch.master.mergeoptions "--squash" && | |
361 | test_tick && | |
362 | git merge --no-squash c2 && | |
363 | verify_merge file result.1-5 msg.1-5 && | |
364 | verify_parents $c1 $c2 | |
365 | ' | |
366 | ||
df516fb5 | 367 | test_debug 'git log --graph --decorate --oneline --all' |
d08af0ad | 368 | |
d66424c4 LH |
369 | test_expect_success 'merge c0 with c1 (no-ff)' ' |
370 | git reset --hard c0 && | |
e6d1f76c | 371 | git config branch.master.mergeoptions "" && |
d66424c4 LH |
372 | test_tick && |
373 | git merge --no-ff c1 && | |
374 | verify_merge file result.1 && | |
375 | verify_parents $c0 $c1 | |
376 | ' | |
377 | ||
df516fb5 | 378 | test_debug 'git log --graph --decorate --oneline --all' |
d66424c4 | 379 | |
e6d1f76c GP |
380 | test_expect_success 'combining --squash and --no-ff is refused' ' |
381 | test_must_fail git merge --squash --no-ff c1 && | |
382 | test_must_fail git merge --no-ff --squash c1 | |
383 | ' | |
384 | ||
13474835 BG |
385 | test_expect_success 'combining --ff-only and --no-ff is refused' ' |
386 | test_must_fail git merge --ff-only --no-ff c1 && | |
387 | test_must_fail git merge --no-ff --ff-only c1 | |
388 | ' | |
389 | ||
d66424c4 LH |
390 | test_expect_success 'merge c0 with c1 (ff overrides no-ff)' ' |
391 | git reset --hard c0 && | |
392 | git config branch.master.mergeoptions "--no-ff" && | |
393 | git merge --ff c1 && | |
394 | verify_merge file result.1 && | |
395 | verify_head $c1 | |
396 | ' | |
397 | ||
efb779f8 SG |
398 | test_expect_success 'merge log message' ' |
399 | git reset --hard c0 && | |
400 | git merge --no-log c2 && | |
401 | git show -s --pretty=format:%b HEAD >msg.act && | |
4c073457 | 402 | test_cmp msg.nolog msg.act && |
4393c237 | 403 | |
efb779f8 SG |
404 | git merge --log c3 && |
405 | git show -s --pretty=format:%b HEAD >msg.act && | |
4c073457 | 406 | test_cmp msg.log msg.act && |
4393c237 JH |
407 | |
408 | git reset --hard HEAD^ && | |
409 | git config merge.log yes && | |
410 | git merge c3 && | |
411 | git show -s --pretty=format:%b HEAD >msg.act && | |
4c073457 | 412 | test_cmp msg.log msg.act |
efb779f8 SG |
413 | ' |
414 | ||
df516fb5 | 415 | test_debug 'git log --graph --decorate --oneline --all' |
d66424c4 | 416 | |
3d1dd472 SHJ |
417 | test_expect_success 'merge c1 with c0, c2, c0, and c1' ' |
418 | git reset --hard c1 && | |
419 | git config branch.master.mergeoptions "" && | |
420 | test_tick && | |
421 | git merge c0 c2 c0 c1 && | |
422 | verify_merge file result.1-5 && | |
423 | verify_parents $c1 $c2 | |
424 | ' | |
425 | ||
df516fb5 | 426 | test_debug 'git log --graph --decorate --oneline --all' |
3d1dd472 | 427 | |
711f6b29 JH |
428 | test_expect_success 'merge c1 with c0, c2, c0, and c1' ' |
429 | git reset --hard c1 && | |
430 | git config branch.master.mergeoptions "" && | |
431 | test_tick && | |
432 | git merge c0 c2 c0 c1 && | |
433 | verify_merge file result.1-5 && | |
434 | verify_parents $c1 $c2 | |
435 | ' | |
436 | ||
df516fb5 | 437 | test_debug 'git log --graph --decorate --oneline --all' |
711f6b29 JH |
438 | |
439 | test_expect_success 'merge c1 with c1 and c2' ' | |
440 | git reset --hard c1 && | |
441 | git config branch.master.mergeoptions "" && | |
442 | test_tick && | |
443 | git merge c1 c2 && | |
444 | verify_merge file result.1-5 && | |
445 | verify_parents $c1 $c2 | |
446 | ' | |
447 | ||
df516fb5 | 448 | test_debug 'git log --graph --decorate --oneline --all' |
711f6b29 | 449 | |
9ca8f607 JH |
450 | test_expect_success 'merge fast-forward in a dirty tree' ' |
451 | git reset --hard c0 && | |
452 | mv file file1 && | |
453 | cat file1 >file && | |
454 | rm -f file1 && | |
455 | git merge c2 | |
456 | ' | |
457 | ||
df516fb5 | 458 | test_debug 'git log --graph --decorate --oneline --all' |
9ca8f607 | 459 | |
446247db JH |
460 | test_expect_success 'in-index merge' ' |
461 | git reset --hard c0 && | |
4c073457 | 462 | git merge --no-ff -s resolve c1 >out && |
446247db JH |
463 | grep "Wonderful." out && |
464 | verify_parents $c0 $c1 | |
465 | ' | |
466 | ||
df516fb5 | 467 | test_debug 'git log --graph --decorate --oneline --all' |
446247db | 468 | |
668f26ff MV |
469 | test_expect_success 'refresh the index before merging' ' |
470 | git reset --hard c1 && | |
016e5ff2 | 471 | cp file file.n && mv -f file.n file && |
668f26ff MV |
472 | git merge c3 |
473 | ' | |
474 | ||
b81f925f JN |
475 | cat >expected.branch <<\EOF |
476 | Merge branch 'c5-branch' (early part) | |
477 | EOF | |
478 | cat >expected.tag <<\EOF | |
479 | Merge commit 'c5~1' | |
4e6d4bc0 MV |
480 | EOF |
481 | ||
482 | test_expect_success 'merge early part of c2' ' | |
483 | git reset --hard c3 && | |
4c073457 | 484 | echo c4 >c4.c && |
4e6d4bc0 MV |
485 | git add c4.c && |
486 | git commit -m c4 && | |
487 | git tag c4 && | |
4c073457 | 488 | echo c5 >c5.c && |
4e6d4bc0 MV |
489 | git add c5.c && |
490 | git commit -m c5 && | |
491 | git tag c5 && | |
492 | git reset --hard c3 && | |
4c073457 | 493 | echo c6 >c6.c && |
4e6d4bc0 MV |
494 | git add c6.c && |
495 | git commit -m c6 && | |
496 | git tag c6 && | |
b81f925f JN |
497 | git branch -f c5-branch c5 && |
498 | git merge c5-branch~1 && | |
499 | git show -s --pretty=format:%s HEAD >actual.branch && | |
500 | git reset --keep HEAD^ && | |
4e6d4bc0 | 501 | git merge c5~1 && |
b81f925f JN |
502 | git show -s --pretty=format:%s HEAD >actual.tag && |
503 | test_cmp expected.branch actual.branch && | |
504 | test_cmp expected.tag actual.tag | |
4e6d4bc0 MV |
505 | ' |
506 | ||
df516fb5 | 507 | test_debug 'git log --graph --decorate --oneline --all' |
668f26ff | 508 | |
cf10f9fd MV |
509 | test_expect_success 'merge --no-ff --no-commit && commit' ' |
510 | git reset --hard c0 && | |
511 | git merge --no-ff --no-commit c1 && | |
512 | EDITOR=: git commit && | |
513 | verify_parents $c0 $c1 | |
514 | ' | |
515 | ||
df516fb5 | 516 | test_debug 'git log --graph --decorate --oneline --all' |
cf10f9fd MV |
517 | |
518 | test_expect_success 'amending no-ff merge commit' ' | |
519 | EDITOR=: git commit --amend && | |
520 | verify_parents $c0 $c1 | |
521 | ' | |
522 | ||
df516fb5 | 523 | test_debug 'git log --graph --decorate --oneline --all' |
cf10f9fd | 524 | |
a85d1b69 | 525 | test_done |