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