]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7600-merge.sh
Git 2.11
[thirdparty/git.git] / t / t7600-merge.sh
CommitLineData
a85d1b69
LH
1#!/bin/sh
2#
3# Copyright (c) 2007 Lars Hjemli
4#
5
47a528ad 6test_description='git merge
a85d1b69 7
4c073457
JN
8Testing 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
b5c9f1c1 30. "$TEST_DIRECTORY"/lib-gpg.sh
a85d1b69 31
73151df0
JN
32printf '%s\n' 1 2 3 4 5 6 7 8 9 >file
33printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >file.1
34printf '%s\n' 1 2 3 4 '5 X' 6 7 8 9 >file.5
35printf '%s\n' 1 2 3 4 5 6 7 8 '9 X' >file.9
b64c1e07 36printf '%s\n' 1 2 3 4 5 6 7 8 '9 Y' >file.9y
73151df0
JN
37printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >result.1
38printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 9 >result.1-5
39printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 '9 X' >result.1-5-9
b64c1e07 40printf '%s\n' 1 2 3 4 5 6 7 8 '9 Z' >result.9z
36a45b4f 41>empty
4c073457 42
73151df0 43create_merge_msgs () {
57b58db7
JH
44 echo "Merge tag 'c2'" >msg.1-5 &&
45 echo "Merge tags 'c2' and 'c3'" >msg.1-5-9 &&
73151df0
JN
46 {
47 echo "Squashed commit of the following:" &&
48 echo &&
49 git log --no-merges ^HEAD c1
50 } >squash.1 &&
51 {
52 echo "Squashed commit of the following:" &&
53 echo &&
54 git log --no-merges ^HEAD c2
55 } >squash.1-5 &&
56 {
57 echo "Squashed commit of the following:" &&
58 echo &&
59 git log --no-merges ^HEAD c2 c3
60 } >squash.1-5-9 &&
cee683b7 61 : >msg.nologff &&
ad2f7255 62 : >msg.nolognoff &&
73151df0 63 {
57b58db7 64 echo "* tag 'c3':" &&
ad2f7255 65 echo " commit 3"
73151df0
JN
66 } >msg.log
67}
4c073457 68
73151df0
JN
69verify_merge () {
70 test_cmp "$2" "$1" &&
71 git update-index --refresh &&
72 git diff --exit-code &&
73 if test -n "$3"
74 then
ad2f7255 75 git show -s --pretty=tformat:%s HEAD >msg.act &&
73151df0
JN
76 test_cmp "$3" msg.act
77 fi
78}
4c073457 79
73151df0
JN
80verify_head () {
81 echo "$1" >head.expected &&
82 git rev-parse HEAD >head.actual &&
83 test_cmp head.expected head.actual
84}
4c073457 85
73151df0
JN
86verify_parents () {
87 printf '%s\n' "$@" >parents.expected &&
88 >parents.actual &&
89 i=1 &&
90 while test $i -le $#
91 do
92 git rev-parse HEAD^$i >>parents.actual &&
93 i=$(expr $i + 1) ||
94 return 1
95 done &&
3fc0dbf0 96 test_must_fail git rev-parse --verify "HEAD^$i" &&
73151df0
JN
97 test_cmp parents.expected parents.actual
98}
a85d1b69 99
73151df0
JN
100verify_mergeheads () {
101 printf '%s\n' "$@" >mergehead.expected &&
274a5c06
JH
102 while read sha1 rest
103 do
104 git rev-parse $sha1
105 done <.git/MERGE_HEAD >mergehead.actual &&
106 test_cmp mergehead.expected mergehead.actual
73151df0 107}
a85d1b69 108
73151df0
JN
109verify_no_mergehead () {
110 ! test -e .git/MERGE_HEAD
111}
a85d1b69
LH
112
113test_expect_success 'setup' '
114 git add file &&
115 test_tick &&
116 git commit -m "commit 0" &&
117 git tag c0 &&
118 c0=$(git rev-parse HEAD) &&
119 cp file.1 file &&
120 git add file &&
121 test_tick &&
122 git commit -m "commit 1" &&
123 git tag c1 &&
124 c1=$(git rev-parse HEAD) &&
125 git reset --hard "$c0" &&
126 cp file.5 file &&
127 git add file &&
128 test_tick &&
129 git commit -m "commit 2" &&
130 git tag c2 &&
131 c2=$(git rev-parse HEAD) &&
132 git reset --hard "$c0" &&
b64c1e07
SS
133 cp file.9y file &&
134 git add file &&
135 test_tick &&
136 git commit -m "commit 7" &&
137 git tag c7 &&
138 git reset --hard "$c0" &&
a85d1b69
LH
139 cp file.9 file &&
140 git add file &&
141 test_tick &&
142 git commit -m "commit 3" &&
143 git tag c3 &&
99094a7a 144 c3=$(git rev-parse HEAD) &&
a85d1b69
LH
145 git reset --hard "$c0" &&
146 create_merge_msgs
147'
148
df516fb5 149test_debug 'git log --graph --decorate --oneline --all'
a85d1b69 150
74f5b7fb 151test_expect_success 'test option parsing' '
01941bd5
JS
152 test_must_fail git merge -$ c1 &&
153 test_must_fail git merge --no-such c1 &&
154 test_must_fail git merge -s foobar c1 &&
155 test_must_fail git merge -s=foobar c1 &&
156 test_must_fail git merge -m &&
157 test_must_fail git merge
a85d1b69
LH
158'
159
da53eec6
NTND
160test_expect_success 'merge -h with invalid index' '
161 mkdir broken &&
162 (
163 cd broken &&
164 git init &&
165 >.git/index &&
166 test_expect_code 129 git merge -h 2>usage
167 ) &&
9a001381 168 test_i18ngrep "[Uu]sage: git merge" broken/usage
da53eec6
NTND
169'
170
dce61e72
MV
171test_expect_success 'reject non-strategy with a git-merge-foo name' '
172 test_must_fail git merge -s index c1
173'
174
a85d1b69 175test_expect_success 'merge c0 with c1' '
ff372c78
JN
176 echo "OBJID HEAD@{0}: merge c1: Fast-forward" >reflog.expected &&
177
a85d1b69
LH
178 git reset --hard c0 &&
179 git merge c1 &&
180 verify_merge file result.1 &&
ff372c78
JN
181 verify_head "$c1" &&
182
183 git reflog -1 >reflog.actual &&
184 sed "s/$_x05[0-9a-f]*/OBJID/g" reflog.actual >reflog.fuzzy &&
185 test_cmp reflog.expected reflog.fuzzy
a85d1b69
LH
186'
187
df516fb5 188test_debug 'git log --graph --decorate --oneline --all'
a85d1b69 189
13474835
BG
190test_expect_success 'merge c0 with c1 with --ff-only' '
191 git reset --hard c0 &&
192 git merge --ff-only c1 &&
193 git merge --ff-only HEAD c0 c1 &&
194 verify_merge file result.1 &&
195 verify_head "$c1"
196'
197
df516fb5 198test_debug 'git log --graph --decorate --oneline --all'
94d63ce2
JN
199
200test_expect_success 'merge from unborn branch' '
201 git checkout -f master &&
202 test_might_fail git branch -D kid &&
203
204 echo "OBJID HEAD@{0}: initial pull" >reflog.expected &&
205
206 git checkout --orphan kid &&
207 test_when_finished "git checkout -f master" &&
208 git rm -fr . &&
209 test_tick &&
210 git merge --ff-only c1 &&
211 verify_merge file result.1 &&
212 verify_head "$c1" &&
213
214 git reflog -1 >reflog.actual &&
215 sed "s/$_x05[0-9a-f][0-9a-f]/OBJID/g" reflog.actual >reflog.fuzzy &&
216 test_cmp reflog.expected reflog.fuzzy
217'
218
219test_debug 'git log --graph --decorate --oneline --all'
13474835 220
a85d1b69
LH
221test_expect_success 'merge c1 with c2' '
222 git reset --hard c1 &&
223 test_tick &&
224 git merge c2 &&
225 verify_merge file result.1-5 msg.1-5 &&
226 verify_parents $c1 $c2
227'
228
b64c1e07
SS
229test_expect_success 'merge --squash c3 with c7' '
230 git reset --hard c3 &&
231 test_must_fail git merge --squash c7 &&
232 cat result.9z >file &&
233 git commit --no-edit -a &&
234
235 {
236 cat <<-EOF
237 Squashed commit of the following:
238
239 $(git show -s c7)
240
241 # Conflicts:
242 # file
243 EOF
244 } >expect &&
245 git cat-file commit HEAD | sed -e '1,/^$/d' >actual &&
246 test_cmp expect actual
247'
248
df516fb5 249test_debug 'git log --graph --decorate --oneline --all'
a85d1b69
LH
250
251test_expect_success 'merge c1 with c2 and c3' '
252 git reset --hard c1 &&
253 test_tick &&
254 git merge c2 c3 &&
255 verify_merge file result.1-5-9 msg.1-5-9 &&
256 verify_parents $c1 $c2 $c3
257'
258
df516fb5 259test_debug 'git log --graph --decorate --oneline --all'
a85d1b69 260
f23e8dec 261test_expect_success 'merges with --ff-only' '
13474835
BG
262 git reset --hard c1 &&
263 test_tick &&
264 test_must_fail git merge --ff-only c2 &&
265 test_must_fail git merge --ff-only c3 &&
f23e8dec
JH
266 test_must_fail git merge --ff-only c2 c3 &&
267 git reset --hard c0 &&
268 git merge c3 &&
269 verify_head $c3
270'
271
272test_expect_success 'merges with merge.ff=only' '
273 git reset --hard c1 &&
274 test_tick &&
cee683b7 275 test_config merge.ff "only" &&
f23e8dec
JH
276 test_must_fail git merge c2 &&
277 test_must_fail git merge c3 &&
278 test_must_fail git merge c2 c3 &&
279 git reset --hard c0 &&
280 git merge c3 &&
281 verify_head $c3
13474835
BG
282'
283
a85d1b69
LH
284test_expect_success 'merge c0 with c1 (no-commit)' '
285 git reset --hard c0 &&
286 git merge --no-commit c1 &&
287 verify_merge file result.1 &&
288 verify_head $c1
289'
290
df516fb5 291test_debug 'git log --graph --decorate --oneline --all'
a85d1b69
LH
292
293test_expect_success 'merge c1 with c2 (no-commit)' '
294 git reset --hard c1 &&
295 git merge --no-commit c2 &&
296 verify_merge file result.1-5 &&
297 verify_head $c1 &&
298 verify_mergeheads $c2
299'
300
df516fb5 301test_debug 'git log --graph --decorate --oneline --all'
a85d1b69
LH
302
303test_expect_success 'merge c1 with c2 and c3 (no-commit)' '
304 git reset --hard c1 &&
305 git merge --no-commit c2 c3 &&
306 verify_merge file result.1-5-9 &&
307 verify_head $c1 &&
308 verify_mergeheads $c2 $c3
309'
310
df516fb5 311test_debug 'git log --graph --decorate --oneline --all'
a85d1b69
LH
312
313test_expect_success 'merge c0 with c1 (squash)' '
314 git reset --hard c0 &&
315 git merge --squash c1 &&
316 verify_merge file result.1 &&
317 verify_head $c0 &&
318 verify_no_mergehead &&
4c073457 319 test_cmp squash.1 .git/SQUASH_MSG
a85d1b69
LH
320'
321
df516fb5 322test_debug 'git log --graph --decorate --oneline --all'
a85d1b69 323
13474835
BG
324test_expect_success 'merge c0 with c1 (squash, ff-only)' '
325 git reset --hard c0 &&
326 git merge --squash --ff-only c1 &&
327 verify_merge file result.1 &&
328 verify_head $c0 &&
329 verify_no_mergehead &&
4c073457 330 test_cmp squash.1 .git/SQUASH_MSG
13474835
BG
331'
332
df516fb5 333test_debug 'git log --graph --decorate --oneline --all'
13474835 334
a85d1b69
LH
335test_expect_success 'merge c1 with c2 (squash)' '
336 git reset --hard c1 &&
337 git merge --squash c2 &&
338 verify_merge file result.1-5 &&
339 verify_head $c1 &&
340 verify_no_mergehead &&
4c073457 341 test_cmp squash.1-5 .git/SQUASH_MSG
a85d1b69
LH
342'
343
df516fb5 344test_debug 'git log --graph --decorate --oneline --all'
a85d1b69 345
f7e604ed 346test_expect_success 'unsuccessful merge of c1 with c2 (squash, ff-only)' '
13474835
BG
347 git reset --hard c1 &&
348 test_must_fail git merge --squash --ff-only c2
349'
350
df516fb5 351test_debug 'git log --graph --decorate --oneline --all'
13474835 352
a85d1b69
LH
353test_expect_success 'merge c1 with c2 and c3 (squash)' '
354 git reset --hard c1 &&
355 git merge --squash c2 c3 &&
356 verify_merge file result.1-5-9 &&
357 verify_head $c1 &&
358 verify_no_mergehead &&
4c073457 359 test_cmp squash.1-5-9 .git/SQUASH_MSG
a85d1b69
LH
360'
361
df516fb5 362test_debug 'git log --graph --decorate --oneline --all'
a85d1b69 363
aec7b362
LH
364test_expect_success 'merge c1 with c2 (no-commit in config)' '
365 git reset --hard c1 &&
cee683b7 366 test_config branch.master.mergeoptions "--no-commit" &&
aec7b362
LH
367 git merge c2 &&
368 verify_merge file result.1-5 &&
369 verify_head $c1 &&
370 verify_mergeheads $c2
371'
372
df516fb5 373test_debug 'git log --graph --decorate --oneline --all'
aec7b362 374
0d8fc3ef 375test_expect_success 'merge c1 with c2 (log in config)' '
0d8fc3ef
JH
376 git reset --hard c1 &&
377 git merge --log c2 &&
378 git show -s --pretty=tformat:%s%n%b >expect &&
379
cee683b7 380 test_config branch.master.mergeoptions "--log" &&
0d8fc3ef
JH
381 git reset --hard c1 &&
382 git merge c2 &&
383 git show -s --pretty=tformat:%s%n%b >actual &&
384
385 test_cmp expect actual
386'
387
388test_expect_success 'merge c1 with c2 (log in config gets overridden)' '
0d8fc3ef
JH
389 git reset --hard c1 &&
390 git merge c2 &&
391 git show -s --pretty=tformat:%s%n%b >expect &&
392
cee683b7
YD
393 test_config branch.master.mergeoptions "--no-log" &&
394 test_config merge.log "true" &&
0d8fc3ef
JH
395 git reset --hard c1 &&
396 git merge c2 &&
397 git show -s --pretty=tformat:%s%n%b >actual &&
398
399 test_cmp expect actual
400'
401
aec7b362
LH
402test_expect_success 'merge c1 with c2 (squash in config)' '
403 git reset --hard c1 &&
cee683b7 404 test_config branch.master.mergeoptions "--squash" &&
aec7b362
LH
405 git merge c2 &&
406 verify_merge file result.1-5 &&
407 verify_head $c1 &&
408 verify_no_mergehead &&
4c073457 409 test_cmp squash.1-5 .git/SQUASH_MSG
aec7b362
LH
410'
411
df516fb5 412test_debug 'git log --graph --decorate --oneline --all'
aec7b362 413
d8abe148 414test_expect_success 'override config option -n with --summary' '
aec7b362 415 git reset --hard c1 &&
cee683b7 416 test_config branch.master.mergeoptions "-n" &&
aec7b362
LH
417 test_tick &&
418 git merge --summary c2 >diffstat.txt &&
419 verify_merge file result.1-5 msg.1-5 &&
420 verify_parents $c1 $c2 &&
aadbe44f 421 if ! grep "^ file | *2 +-$" diffstat.txt
aec7b362 422 then
d8abe148
SG
423 echo "[OOPS] diffstat was not generated with --summary"
424 false
425 fi
426'
427
428test_expect_success 'override config option -n with --stat' '
429 git reset --hard c1 &&
cee683b7 430 test_config branch.master.mergeoptions "-n" &&
d8abe148
SG
431 test_tick &&
432 git merge --stat c2 >diffstat.txt &&
433 verify_merge file result.1-5 msg.1-5 &&
434 verify_parents $c1 $c2 &&
435 if ! grep "^ file | *2 +-$" diffstat.txt
436 then
437 echo "[OOPS] diffstat was not generated with --stat"
438 false
aec7b362
LH
439 fi
440'
441
df516fb5 442test_debug 'git log --graph --decorate --oneline --all'
aec7b362 443
d8abe148 444test_expect_success 'override config option --stat' '
aec7b362 445 git reset --hard c1 &&
cee683b7 446 test_config branch.master.mergeoptions "--stat" &&
aec7b362
LH
447 test_tick &&
448 git merge -n c2 >diffstat.txt &&
449 verify_merge file result.1-5 msg.1-5 &&
450 verify_parents $c1 $c2 &&
aadbe44f 451 if grep "^ file | *2 +-$" diffstat.txt
aec7b362
LH
452 then
453 echo "[OOPS] diffstat was generated"
454 false
455 fi
456'
457
df516fb5 458test_debug 'git log --graph --decorate --oneline --all'
aec7b362 459
d08af0ad
LH
460test_expect_success 'merge c1 with c2 (override --no-commit)' '
461 git reset --hard c1 &&
cee683b7 462 test_config branch.master.mergeoptions "--no-commit" &&
d08af0ad
LH
463 test_tick &&
464 git merge --commit c2 &&
465 verify_merge file result.1-5 msg.1-5 &&
466 verify_parents $c1 $c2
467'
468
df516fb5 469test_debug 'git log --graph --decorate --oneline --all'
d08af0ad
LH
470
471test_expect_success 'merge c1 with c2 (override --squash)' '
472 git reset --hard c1 &&
cee683b7 473 test_config branch.master.mergeoptions "--squash" &&
d08af0ad
LH
474 test_tick &&
475 git merge --no-squash c2 &&
476 verify_merge file result.1-5 msg.1-5 &&
477 verify_parents $c1 $c2
478'
479
df516fb5 480test_debug 'git log --graph --decorate --oneline --all'
d08af0ad 481
d66424c4
LH
482test_expect_success 'merge c0 with c1 (no-ff)' '
483 git reset --hard c0 &&
484 test_tick &&
485 git merge --no-ff c1 &&
486 verify_merge file result.1 &&
487 verify_parents $c0 $c1
488'
489
df516fb5 490test_debug 'git log --graph --decorate --oneline --all'
d66424c4 491
f23e8dec
JH
492test_expect_success 'merge c0 with c1 (merge.ff=false)' '
493 git reset --hard c0 &&
cee683b7 494 test_config merge.ff "false" &&
f23e8dec
JH
495 test_tick &&
496 git merge c1 &&
f23e8dec
JH
497 verify_merge file result.1 &&
498 verify_parents $c0 $c1
499'
500test_debug 'git log --graph --decorate --oneline --all'
501
502test_expect_success 'combine branch.master.mergeoptions with merge.ff' '
503 git reset --hard c0 &&
cee683b7
YD
504 test_config branch.master.mergeoptions "--ff" &&
505 test_config merge.ff "false" &&
f23e8dec
JH
506 test_tick &&
507 git merge c1 &&
f23e8dec
JH
508 verify_merge file result.1 &&
509 verify_parents "$c0"
510'
511
8c5cea00
JN
512test_expect_success 'tolerate unknown values for merge.ff' '
513 git reset --hard c0 &&
cee683b7 514 test_config merge.ff "something-new" &&
8c5cea00
JN
515 test_tick &&
516 git merge c1 2>message &&
8c5cea00
JN
517 verify_head "$c1" &&
518 test_cmp empty message
519'
520
e6d1f76c 521test_expect_success 'combining --squash and --no-ff is refused' '
8c5cea00 522 git reset --hard c0 &&
e6d1f76c
GP
523 test_must_fail git merge --squash --no-ff c1 &&
524 test_must_fail git merge --no-ff --squash c1
525'
526
a54841e9
MV
527test_expect_success 'option --ff-only overwrites --no-ff' '
528 git merge --no-ff --ff-only c1 &&
529 test_must_fail git merge --no-ff --ff-only c2
530'
531
6d2d43dc 532test_expect_success 'option --no-ff overrides merge.ff=only config' '
a54841e9
MV
533 git reset --hard c0 &&
534 test_config merge.ff only &&
535 git merge --no-ff c1
13474835
BG
536'
537
d66424c4
LH
538test_expect_success 'merge c0 with c1 (ff overrides no-ff)' '
539 git reset --hard c0 &&
cee683b7 540 test_config branch.master.mergeoptions "--no-ff" &&
d66424c4
LH
541 git merge --ff c1 &&
542 verify_merge file result.1 &&
543 verify_head $c1
544'
545
efb779f8
SG
546test_expect_success 'merge log message' '
547 git reset --hard c0 &&
548 git merge --no-log c2 &&
549 git show -s --pretty=format:%b HEAD >msg.act &&
cee683b7
YD
550 test_cmp msg.nologff msg.act &&
551
552 git reset --hard c0 &&
553 test_config branch.master.mergeoptions "--no-ff" &&
554 git merge --no-log c2 &&
555 git show -s --pretty=format:%b HEAD >msg.act &&
556 test_cmp msg.nolognoff msg.act &&
4393c237 557
efb779f8
SG
558 git merge --log c3 &&
559 git show -s --pretty=format:%b HEAD >msg.act &&
4c073457 560 test_cmp msg.log msg.act &&
4393c237
JH
561
562 git reset --hard HEAD^ &&
cee683b7 563 test_config merge.log "yes" &&
4393c237
JH
564 git merge c3 &&
565 git show -s --pretty=format:%b HEAD >msg.act &&
4c073457 566 test_cmp msg.log msg.act
efb779f8
SG
567'
568
df516fb5 569test_debug 'git log --graph --decorate --oneline --all'
d66424c4 570
3d1dd472
SHJ
571test_expect_success 'merge c1 with c0, c2, c0, and c1' '
572 git reset --hard c1 &&
3d1dd472
SHJ
573 test_tick &&
574 git merge c0 c2 c0 c1 &&
575 verify_merge file result.1-5 &&
576 verify_parents $c1 $c2
577'
578
df516fb5 579test_debug 'git log --graph --decorate --oneline --all'
3d1dd472 580
711f6b29
JH
581test_expect_success 'merge c1 with c0, c2, c0, and c1' '
582 git reset --hard c1 &&
711f6b29
JH
583 test_tick &&
584 git merge c0 c2 c0 c1 &&
585 verify_merge file result.1-5 &&
586 verify_parents $c1 $c2
587'
588
df516fb5 589test_debug 'git log --graph --decorate --oneline --all'
711f6b29
JH
590
591test_expect_success 'merge c1 with c1 and c2' '
592 git reset --hard c1 &&
711f6b29
JH
593 test_tick &&
594 git merge c1 c2 &&
595 verify_merge file result.1-5 &&
596 verify_parents $c1 $c2
597'
598
df516fb5 599test_debug 'git log --graph --decorate --oneline --all'
711f6b29 600
9ca8f607
JH
601test_expect_success 'merge fast-forward in a dirty tree' '
602 git reset --hard c0 &&
603 mv file file1 &&
604 cat file1 >file &&
605 rm -f file1 &&
606 git merge c2
607'
608
df516fb5 609test_debug 'git log --graph --decorate --oneline --all'
9ca8f607 610
c9ea118e 611test_expect_success 'in-index merge' '
446247db 612 git reset --hard c0 &&
4c073457 613 git merge --no-ff -s resolve c1 >out &&
c9ea118e 614 test_i18ngrep "Wonderful." out &&
446247db
JH
615 verify_parents $c0 $c1
616'
617
df516fb5 618test_debug 'git log --graph --decorate --oneline --all'
446247db 619
668f26ff
MV
620test_expect_success 'refresh the index before merging' '
621 git reset --hard c1 &&
016e5ff2 622 cp file file.n && mv -f file.n file &&
668f26ff
MV
623 git merge c3
624'
625
b81f925f
JN
626cat >expected.branch <<\EOF
627Merge branch 'c5-branch' (early part)
628EOF
629cat >expected.tag <<\EOF
630Merge commit 'c5~1'
4e6d4bc0
MV
631EOF
632
633test_expect_success 'merge early part of c2' '
634 git reset --hard c3 &&
4c073457 635 echo c4 >c4.c &&
4e6d4bc0
MV
636 git add c4.c &&
637 git commit -m c4 &&
638 git tag c4 &&
4c073457 639 echo c5 >c5.c &&
4e6d4bc0
MV
640 git add c5.c &&
641 git commit -m c5 &&
642 git tag c5 &&
643 git reset --hard c3 &&
4c073457 644 echo c6 >c6.c &&
4e6d4bc0
MV
645 git add c6.c &&
646 git commit -m c6 &&
647 git tag c6 &&
b81f925f
JN
648 git branch -f c5-branch c5 &&
649 git merge c5-branch~1 &&
ad2f7255 650 git show -s --pretty=tformat:%s HEAD >actual.branch &&
b81f925f 651 git reset --keep HEAD^ &&
4e6d4bc0 652 git merge c5~1 &&
ad2f7255 653 git show -s --pretty=tformat:%s HEAD >actual.tag &&
b81f925f
JN
654 test_cmp expected.branch actual.branch &&
655 test_cmp expected.tag actual.tag
4e6d4bc0
MV
656'
657
df516fb5 658test_debug 'git log --graph --decorate --oneline --all'
668f26ff 659
cf10f9fd
MV
660test_expect_success 'merge --no-ff --no-commit && commit' '
661 git reset --hard c0 &&
662 git merge --no-ff --no-commit c1 &&
663 EDITOR=: git commit &&
664 verify_parents $c0 $c1
665'
666
df516fb5 667test_debug 'git log --graph --decorate --oneline --all'
cf10f9fd
MV
668
669test_expect_success 'amending no-ff merge commit' '
670 EDITOR=: git commit --amend &&
671 verify_parents $c0 $c1
672'
673
df516fb5 674test_debug 'git log --graph --decorate --oneline --all'
cf10f9fd 675
66f4b98a
JS
676cat >editor <<\EOF
677#!/bin/sh
678# Add a new message string that was not in the template
679(
680 echo "Merge work done on the side branch c1"
681 echo
682 cat <"$1"
683) >"$1.tmp" && mv "$1.tmp" "$1"
684# strip comments and blank lines from end of message
685sed -e '/^#/d' < "$1" | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' > expected
686EOF
687chmod 755 editor
688
689test_expect_success 'merge --no-ff --edit' '
690 git reset --hard c0 &&
691 EDITOR=./editor git merge --no-ff --edit c1 &&
692 verify_parents $c0 $c1 &&
693 git cat-file commit HEAD >raw &&
694 grep "work done on the side branch" raw &&
695 sed "1,/^$/d" >actual raw &&
696 test_cmp actual expected
697'
698
b5c9f1c1
JH
699test_expect_success GPG 'merge --ff-only tag' '
700 git reset --hard c0 &&
701 git commit --allow-empty -m "A newer commit" &&
702 git tag -s -m "A newer commit" signed &&
703 git reset --hard c0 &&
704
705 git merge --ff-only signed &&
706 git rev-parse signed^0 >expect &&
707 git rev-parse HEAD >actual &&
708 test_cmp actual expect
709'
710
3adab6f3
JH
711test_expect_success GPG 'merge --no-edit tag should skip editor' '
712 git reset --hard c0 &&
713 git commit --allow-empty -m "A newer commit" &&
714 git tag -f -s -m "A newer commit" signed &&
715 git reset --hard c0 &&
716
717 EDITOR=false git merge --no-edit signed &&
718 git rev-parse signed^0 >expect &&
719 git rev-parse HEAD^2 >actual &&
720 test_cmp actual expect
721'
722
e34f8027
JK
723test_expect_success 'set up mod-256 conflict scenario' '
724 # 256 near-identical stanzas...
725 for i in $(test_seq 1 256); do
726 for j in 1 2 3 4 5; do
727 echo $i-$j
728 done
729 done >file &&
730 git add file &&
731 git commit -m base &&
732
733 # one side changes the first line of each to "master"
734 sed s/-1/-master/ <file >tmp &&
735 mv tmp file &&
736 git commit -am master &&
737
738 # and the other to "side"; merging the two will
739 # yield 256 separate conflicts
740 git checkout -b side HEAD^ &&
741 sed s/-1/-side/ <file >tmp &&
742 mv tmp file &&
743 git commit -am side
744'
745
746test_expect_success 'merge detects mod-256 conflicts (recursive)' '
747 git reset --hard &&
748 test_must_fail git merge -s recursive master
749'
750
751test_expect_success 'merge detects mod-256 conflicts (resolve)' '
752 git reset --hard &&
753 test_must_fail git merge -s resolve master
754'
755
b84e65d4
JH
756test_expect_success 'merge nothing into void' '
757 git init void &&
758 (
759 cd void &&
760 git remote add up .. &&
761 git fetch up &&
762 test_must_fail git merge FETCH_HEAD
763 )
764'
765
a85d1b69 766test_done