]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7600-merge.sh
tests: use 'test_must_be_empty' instead of 'test_cmp /dev/null <out>'
[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 &&
042e290d
CP
157 test_must_fail git merge --abort foobar &&
158 test_must_fail git merge --abort --quiet &&
367ff694
CP
159 test_must_fail git merge --continue foobar &&
160 test_must_fail git merge --continue --quiet &&
01941bd5 161 test_must_fail git merge
a85d1b69
LH
162'
163
da53eec6
NTND
164test_expect_success 'merge -h with invalid index' '
165 mkdir broken &&
166 (
167 cd broken &&
168 git init &&
169 >.git/index &&
170 test_expect_code 129 git merge -h 2>usage
171 ) &&
9a001381 172 test_i18ngrep "[Uu]sage: git merge" broken/usage
da53eec6
NTND
173'
174
dce61e72
MV
175test_expect_success 'reject non-strategy with a git-merge-foo name' '
176 test_must_fail git merge -s index c1
177'
178
a85d1b69 179test_expect_success 'merge c0 with c1' '
ff372c78
JN
180 echo "OBJID HEAD@{0}: merge c1: Fast-forward" >reflog.expected &&
181
a85d1b69
LH
182 git reset --hard c0 &&
183 git merge c1 &&
184 verify_merge file result.1 &&
ff372c78
JN
185 verify_head "$c1" &&
186
187 git reflog -1 >reflog.actual &&
188 sed "s/$_x05[0-9a-f]*/OBJID/g" reflog.actual >reflog.fuzzy &&
189 test_cmp reflog.expected reflog.fuzzy
a85d1b69
LH
190'
191
df516fb5 192test_debug 'git log --graph --decorate --oneline --all'
a85d1b69 193
13474835
BG
194test_expect_success 'merge c0 with c1 with --ff-only' '
195 git reset --hard c0 &&
196 git merge --ff-only c1 &&
197 git merge --ff-only HEAD c0 c1 &&
198 verify_merge file result.1 &&
199 verify_head "$c1"
200'
201
df516fb5 202test_debug 'git log --graph --decorate --oneline --all'
94d63ce2
JN
203
204test_expect_success 'merge from unborn branch' '
205 git checkout -f master &&
206 test_might_fail git branch -D kid &&
207
208 echo "OBJID HEAD@{0}: initial pull" >reflog.expected &&
209
210 git checkout --orphan kid &&
211 test_when_finished "git checkout -f master" &&
212 git rm -fr . &&
213 test_tick &&
214 git merge --ff-only c1 &&
215 verify_merge file result.1 &&
216 verify_head "$c1" &&
217
218 git reflog -1 >reflog.actual &&
219 sed "s/$_x05[0-9a-f][0-9a-f]/OBJID/g" reflog.actual >reflog.fuzzy &&
220 test_cmp reflog.expected reflog.fuzzy
221'
222
223test_debug 'git log --graph --decorate --oneline --all'
13474835 224
a85d1b69
LH
225test_expect_success 'merge c1 with c2' '
226 git reset --hard c1 &&
227 test_tick &&
228 git merge c2 &&
229 verify_merge file result.1-5 msg.1-5 &&
230 verify_parents $c1 $c2
231'
232
b64c1e07
SS
233test_expect_success 'merge --squash c3 with c7' '
234 git reset --hard c3 &&
235 test_must_fail git merge --squash c7 &&
236 cat result.9z >file &&
237 git commit --no-edit -a &&
238
239 {
240 cat <<-EOF
241 Squashed commit of the following:
242
243 $(git show -s c7)
244
245 # Conflicts:
246 # file
247 EOF
248 } >expect &&
249 git cat-file commit HEAD | sed -e '1,/^$/d' >actual &&
250 test_cmp expect actual
251'
252
df516fb5 253test_debug 'git log --graph --decorate --oneline --all'
a85d1b69
LH
254
255test_expect_success 'merge c1 with c2 and c3' '
256 git reset --hard c1 &&
257 test_tick &&
258 git merge c2 c3 &&
259 verify_merge file result.1-5-9 msg.1-5-9 &&
260 verify_parents $c1 $c2 $c3
261'
262
df516fb5 263test_debug 'git log --graph --decorate --oneline --all'
a85d1b69 264
f23e8dec 265test_expect_success 'merges with --ff-only' '
13474835
BG
266 git reset --hard c1 &&
267 test_tick &&
268 test_must_fail git merge --ff-only c2 &&
269 test_must_fail git merge --ff-only c3 &&
f23e8dec
JH
270 test_must_fail git merge --ff-only c2 c3 &&
271 git reset --hard c0 &&
272 git merge c3 &&
273 verify_head $c3
274'
275
276test_expect_success 'merges with merge.ff=only' '
277 git reset --hard c1 &&
278 test_tick &&
cee683b7 279 test_config merge.ff "only" &&
f23e8dec
JH
280 test_must_fail git merge c2 &&
281 test_must_fail git merge c3 &&
282 test_must_fail git merge c2 c3 &&
283 git reset --hard c0 &&
284 git merge c3 &&
285 verify_head $c3
13474835
BG
286'
287
a85d1b69
LH
288test_expect_success 'merge c0 with c1 (no-commit)' '
289 git reset --hard c0 &&
290 git merge --no-commit c1 &&
291 verify_merge file result.1 &&
292 verify_head $c1
293'
294
df516fb5 295test_debug 'git log --graph --decorate --oneline --all'
a85d1b69
LH
296
297test_expect_success 'merge c1 with c2 (no-commit)' '
298 git reset --hard c1 &&
299 git merge --no-commit c2 &&
300 verify_merge file result.1-5 &&
301 verify_head $c1 &&
302 verify_mergeheads $c2
303'
304
df516fb5 305test_debug 'git log --graph --decorate --oneline --all'
a85d1b69
LH
306
307test_expect_success 'merge c1 with c2 and c3 (no-commit)' '
308 git reset --hard c1 &&
309 git merge --no-commit c2 c3 &&
310 verify_merge file result.1-5-9 &&
311 verify_head $c1 &&
312 verify_mergeheads $c2 $c3
313'
314
df516fb5 315test_debug 'git log --graph --decorate --oneline --all'
a85d1b69
LH
316
317test_expect_success 'merge c0 with c1 (squash)' '
318 git reset --hard c0 &&
319 git merge --squash c1 &&
320 verify_merge file result.1 &&
321 verify_head $c0 &&
322 verify_no_mergehead &&
4c073457 323 test_cmp squash.1 .git/SQUASH_MSG
a85d1b69
LH
324'
325
df516fb5 326test_debug 'git log --graph --decorate --oneline --all'
a85d1b69 327
13474835
BG
328test_expect_success 'merge c0 with c1 (squash, ff-only)' '
329 git reset --hard c0 &&
330 git merge --squash --ff-only c1 &&
331 verify_merge file result.1 &&
332 verify_head $c0 &&
333 verify_no_mergehead &&
4c073457 334 test_cmp squash.1 .git/SQUASH_MSG
13474835
BG
335'
336
df516fb5 337test_debug 'git log --graph --decorate --oneline --all'
13474835 338
a85d1b69
LH
339test_expect_success 'merge c1 with c2 (squash)' '
340 git reset --hard c1 &&
341 git merge --squash c2 &&
342 verify_merge file result.1-5 &&
343 verify_head $c1 &&
344 verify_no_mergehead &&
4c073457 345 test_cmp squash.1-5 .git/SQUASH_MSG
a85d1b69
LH
346'
347
df516fb5 348test_debug 'git log --graph --decorate --oneline --all'
a85d1b69 349
f7e604ed 350test_expect_success 'unsuccessful merge of c1 with c2 (squash, ff-only)' '
13474835
BG
351 git reset --hard c1 &&
352 test_must_fail git merge --squash --ff-only c2
353'
354
df516fb5 355test_debug 'git log --graph --decorate --oneline --all'
13474835 356
a85d1b69
LH
357test_expect_success 'merge c1 with c2 and c3 (squash)' '
358 git reset --hard c1 &&
359 git merge --squash c2 c3 &&
360 verify_merge file result.1-5-9 &&
361 verify_head $c1 &&
362 verify_no_mergehead &&
4c073457 363 test_cmp squash.1-5-9 .git/SQUASH_MSG
a85d1b69
LH
364'
365
df516fb5 366test_debug 'git log --graph --decorate --oneline --all'
a85d1b69 367
aec7b362
LH
368test_expect_success 'merge c1 with c2 (no-commit in config)' '
369 git reset --hard c1 &&
cee683b7 370 test_config branch.master.mergeoptions "--no-commit" &&
aec7b362
LH
371 git merge c2 &&
372 verify_merge file result.1-5 &&
373 verify_head $c1 &&
374 verify_mergeheads $c2
375'
376
df516fb5 377test_debug 'git log --graph --decorate --oneline --all'
aec7b362 378
0d8fc3ef 379test_expect_success 'merge c1 with c2 (log in config)' '
0d8fc3ef
JH
380 git reset --hard c1 &&
381 git merge --log c2 &&
382 git show -s --pretty=tformat:%s%n%b >expect &&
383
cee683b7 384 test_config branch.master.mergeoptions "--log" &&
0d8fc3ef
JH
385 git reset --hard c1 &&
386 git merge c2 &&
387 git show -s --pretty=tformat:%s%n%b >actual &&
388
389 test_cmp expect actual
390'
391
392test_expect_success 'merge c1 with c2 (log in config gets overridden)' '
0d8fc3ef
JH
393 git reset --hard c1 &&
394 git merge c2 &&
395 git show -s --pretty=tformat:%s%n%b >expect &&
396
cee683b7
YD
397 test_config branch.master.mergeoptions "--no-log" &&
398 test_config merge.log "true" &&
0d8fc3ef
JH
399 git reset --hard c1 &&
400 git merge c2 &&
401 git show -s --pretty=tformat:%s%n%b >actual &&
402
403 test_cmp expect actual
404'
405
aec7b362
LH
406test_expect_success 'merge c1 with c2 (squash in config)' '
407 git reset --hard c1 &&
cee683b7 408 test_config branch.master.mergeoptions "--squash" &&
aec7b362
LH
409 git merge c2 &&
410 verify_merge file result.1-5 &&
411 verify_head $c1 &&
412 verify_no_mergehead &&
4c073457 413 test_cmp squash.1-5 .git/SQUASH_MSG
aec7b362
LH
414'
415
df516fb5 416test_debug 'git log --graph --decorate --oneline --all'
aec7b362 417
d8abe148 418test_expect_success 'override config option -n with --summary' '
aec7b362 419 git reset --hard c1 &&
cee683b7 420 test_config branch.master.mergeoptions "-n" &&
aec7b362
LH
421 test_tick &&
422 git merge --summary c2 >diffstat.txt &&
423 verify_merge file result.1-5 msg.1-5 &&
424 verify_parents $c1 $c2 &&
aadbe44f 425 if ! grep "^ file | *2 +-$" diffstat.txt
aec7b362 426 then
d8abe148
SG
427 echo "[OOPS] diffstat was not generated with --summary"
428 false
429 fi
430'
431
432test_expect_success 'override config option -n with --stat' '
433 git reset --hard c1 &&
cee683b7 434 test_config branch.master.mergeoptions "-n" &&
d8abe148
SG
435 test_tick &&
436 git merge --stat c2 >diffstat.txt &&
437 verify_merge file result.1-5 msg.1-5 &&
438 verify_parents $c1 $c2 &&
439 if ! grep "^ file | *2 +-$" diffstat.txt
440 then
441 echo "[OOPS] diffstat was not generated with --stat"
442 false
aec7b362
LH
443 fi
444'
445
df516fb5 446test_debug 'git log --graph --decorate --oneline --all'
aec7b362 447
d8abe148 448test_expect_success 'override config option --stat' '
aec7b362 449 git reset --hard c1 &&
cee683b7 450 test_config branch.master.mergeoptions "--stat" &&
aec7b362
LH
451 test_tick &&
452 git merge -n c2 >diffstat.txt &&
453 verify_merge file result.1-5 msg.1-5 &&
454 verify_parents $c1 $c2 &&
aadbe44f 455 if grep "^ file | *2 +-$" diffstat.txt
aec7b362
LH
456 then
457 echo "[OOPS] diffstat was generated"
458 false
459 fi
460'
461
df516fb5 462test_debug 'git log --graph --decorate --oneline --all'
aec7b362 463
d08af0ad
LH
464test_expect_success 'merge c1 with c2 (override --no-commit)' '
465 git reset --hard c1 &&
cee683b7 466 test_config branch.master.mergeoptions "--no-commit" &&
d08af0ad
LH
467 test_tick &&
468 git merge --commit c2 &&
469 verify_merge file result.1-5 msg.1-5 &&
470 verify_parents $c1 $c2
471'
472
df516fb5 473test_debug 'git log --graph --decorate --oneline --all'
d08af0ad
LH
474
475test_expect_success 'merge c1 with c2 (override --squash)' '
476 git reset --hard c1 &&
cee683b7 477 test_config branch.master.mergeoptions "--squash" &&
d08af0ad
LH
478 test_tick &&
479 git merge --no-squash c2 &&
480 verify_merge file result.1-5 msg.1-5 &&
481 verify_parents $c1 $c2
482'
483
df516fb5 484test_debug 'git log --graph --decorate --oneline --all'
d08af0ad 485
d66424c4
LH
486test_expect_success 'merge c0 with c1 (no-ff)' '
487 git reset --hard c0 &&
488 test_tick &&
489 git merge --no-ff c1 &&
490 verify_merge file result.1 &&
491 verify_parents $c0 $c1
492'
493
df516fb5 494test_debug 'git log --graph --decorate --oneline --all'
d66424c4 495
f23e8dec
JH
496test_expect_success 'merge c0 with c1 (merge.ff=false)' '
497 git reset --hard c0 &&
cee683b7 498 test_config merge.ff "false" &&
f23e8dec
JH
499 test_tick &&
500 git merge c1 &&
f23e8dec
JH
501 verify_merge file result.1 &&
502 verify_parents $c0 $c1
503'
504test_debug 'git log --graph --decorate --oneline --all'
505
506test_expect_success 'combine branch.master.mergeoptions with merge.ff' '
507 git reset --hard c0 &&
cee683b7
YD
508 test_config branch.master.mergeoptions "--ff" &&
509 test_config merge.ff "false" &&
f23e8dec
JH
510 test_tick &&
511 git merge c1 &&
f23e8dec
JH
512 verify_merge file result.1 &&
513 verify_parents "$c0"
514'
515
8c5cea00
JN
516test_expect_success 'tolerate unknown values for merge.ff' '
517 git reset --hard c0 &&
cee683b7 518 test_config merge.ff "something-new" &&
8c5cea00
JN
519 test_tick &&
520 git merge c1 2>message &&
8c5cea00
JN
521 verify_head "$c1" &&
522 test_cmp empty message
523'
524
e6d1f76c 525test_expect_success 'combining --squash and --no-ff is refused' '
8c5cea00 526 git reset --hard c0 &&
e6d1f76c
GP
527 test_must_fail git merge --squash --no-ff c1 &&
528 test_must_fail git merge --no-ff --squash c1
529'
530
a54841e9
MV
531test_expect_success 'option --ff-only overwrites --no-ff' '
532 git merge --no-ff --ff-only c1 &&
533 test_must_fail git merge --no-ff --ff-only c2
534'
535
6d2d43dc 536test_expect_success 'option --no-ff overrides merge.ff=only config' '
a54841e9
MV
537 git reset --hard c0 &&
538 test_config merge.ff only &&
539 git merge --no-ff c1
13474835
BG
540'
541
d66424c4
LH
542test_expect_success 'merge c0 with c1 (ff overrides no-ff)' '
543 git reset --hard c0 &&
cee683b7 544 test_config branch.master.mergeoptions "--no-ff" &&
d66424c4
LH
545 git merge --ff c1 &&
546 verify_merge file result.1 &&
547 verify_head $c1
548'
549
efb779f8
SG
550test_expect_success 'merge log message' '
551 git reset --hard c0 &&
552 git merge --no-log c2 &&
553 git show -s --pretty=format:%b HEAD >msg.act &&
cee683b7
YD
554 test_cmp msg.nologff msg.act &&
555
556 git reset --hard c0 &&
557 test_config branch.master.mergeoptions "--no-ff" &&
558 git merge --no-log c2 &&
559 git show -s --pretty=format:%b HEAD >msg.act &&
560 test_cmp msg.nolognoff msg.act &&
4393c237 561
efb779f8
SG
562 git merge --log c3 &&
563 git show -s --pretty=format:%b HEAD >msg.act &&
4c073457 564 test_cmp msg.log msg.act &&
4393c237
JH
565
566 git reset --hard HEAD^ &&
cee683b7 567 test_config merge.log "yes" &&
4393c237
JH
568 git merge c3 &&
569 git show -s --pretty=format:%b HEAD >msg.act &&
4c073457 570 test_cmp msg.log msg.act
efb779f8
SG
571'
572
df516fb5 573test_debug 'git log --graph --decorate --oneline --all'
d66424c4 574
3d1dd472
SHJ
575test_expect_success 'merge c1 with c0, c2, c0, and c1' '
576 git reset --hard c1 &&
3d1dd472
SHJ
577 test_tick &&
578 git merge c0 c2 c0 c1 &&
579 verify_merge file result.1-5 &&
580 verify_parents $c1 $c2
581'
582
df516fb5 583test_debug 'git log --graph --decorate --oneline --all'
3d1dd472 584
711f6b29
JH
585test_expect_success 'merge c1 with c0, c2, c0, and c1' '
586 git reset --hard c1 &&
711f6b29
JH
587 test_tick &&
588 git merge c0 c2 c0 c1 &&
589 verify_merge file result.1-5 &&
590 verify_parents $c1 $c2
591'
592
df516fb5 593test_debug 'git log --graph --decorate --oneline --all'
711f6b29
JH
594
595test_expect_success 'merge c1 with c1 and c2' '
596 git reset --hard c1 &&
711f6b29
JH
597 test_tick &&
598 git merge c1 c2 &&
599 verify_merge file result.1-5 &&
600 verify_parents $c1 $c2
601'
602
df516fb5 603test_debug 'git log --graph --decorate --oneline --all'
711f6b29 604
9ca8f607
JH
605test_expect_success 'merge fast-forward in a dirty tree' '
606 git reset --hard c0 &&
607 mv file file1 &&
608 cat file1 >file &&
609 rm -f file1 &&
610 git merge c2
611'
612
df516fb5 613test_debug 'git log --graph --decorate --oneline --all'
9ca8f607 614
c9ea118e 615test_expect_success 'in-index merge' '
446247db 616 git reset --hard c0 &&
4c073457 617 git merge --no-ff -s resolve c1 >out &&
c9ea118e 618 test_i18ngrep "Wonderful." out &&
446247db
JH
619 verify_parents $c0 $c1
620'
621
df516fb5 622test_debug 'git log --graph --decorate --oneline --all'
446247db 623
668f26ff
MV
624test_expect_success 'refresh the index before merging' '
625 git reset --hard c1 &&
016e5ff2 626 cp file file.n && mv -f file.n file &&
668f26ff
MV
627 git merge c3
628'
629
b81f925f
JN
630cat >expected.branch <<\EOF
631Merge branch 'c5-branch' (early part)
632EOF
633cat >expected.tag <<\EOF
634Merge commit 'c5~1'
4e6d4bc0
MV
635EOF
636
637test_expect_success 'merge early part of c2' '
638 git reset --hard c3 &&
4c073457 639 echo c4 >c4.c &&
4e6d4bc0
MV
640 git add c4.c &&
641 git commit -m c4 &&
642 git tag c4 &&
4c073457 643 echo c5 >c5.c &&
4e6d4bc0
MV
644 git add c5.c &&
645 git commit -m c5 &&
646 git tag c5 &&
647 git reset --hard c3 &&
4c073457 648 echo c6 >c6.c &&
4e6d4bc0
MV
649 git add c6.c &&
650 git commit -m c6 &&
651 git tag c6 &&
b81f925f
JN
652 git branch -f c5-branch c5 &&
653 git merge c5-branch~1 &&
ad2f7255 654 git show -s --pretty=tformat:%s HEAD >actual.branch &&
b81f925f 655 git reset --keep HEAD^ &&
4e6d4bc0 656 git merge c5~1 &&
ad2f7255 657 git show -s --pretty=tformat:%s HEAD >actual.tag &&
b81f925f
JN
658 test_cmp expected.branch actual.branch &&
659 test_cmp expected.tag actual.tag
4e6d4bc0
MV
660'
661
df516fb5 662test_debug 'git log --graph --decorate --oneline --all'
668f26ff 663
cf10f9fd
MV
664test_expect_success 'merge --no-ff --no-commit && commit' '
665 git reset --hard c0 &&
666 git merge --no-ff --no-commit c1 &&
667 EDITOR=: git commit &&
668 verify_parents $c0 $c1
669'
670
df516fb5 671test_debug 'git log --graph --decorate --oneline --all'
cf10f9fd
MV
672
673test_expect_success 'amending no-ff merge commit' '
674 EDITOR=: git commit --amend &&
675 verify_parents $c0 $c1
676'
677
df516fb5 678test_debug 'git log --graph --decorate --oneline --all'
cf10f9fd 679
66f4b98a
JS
680cat >editor <<\EOF
681#!/bin/sh
682# Add a new message string that was not in the template
683(
684 echo "Merge work done on the side branch c1"
685 echo
686 cat <"$1"
687) >"$1.tmp" && mv "$1.tmp" "$1"
688# strip comments and blank lines from end of message
689sed -e '/^#/d' < "$1" | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' > expected
690EOF
691chmod 755 editor
692
693test_expect_success 'merge --no-ff --edit' '
694 git reset --hard c0 &&
695 EDITOR=./editor git merge --no-ff --edit c1 &&
696 verify_parents $c0 $c1 &&
697 git cat-file commit HEAD >raw &&
698 grep "work done on the side branch" raw &&
699 sed "1,/^$/d" >actual raw &&
9c5b2fab 700 test_cmp expected actual
66f4b98a
JS
701'
702
adcc94a0
JH
703test_expect_success 'merge annotated/signed tag w/o tracking' '
704 test_when_finished "rm -rf dst; git tag -d anno1" &&
705 git tag -a -m "anno c1" anno1 c1 &&
706 git init dst &&
707 git rev-parse c1 >dst/expect &&
708 (
709 # c0 fast-forwards to c1 but because this repository
710 # is not a "downstream" whose refs/tags follows along
711 # tag from the "upstream", this pull defaults to --no-ff
712 cd dst &&
713 git pull .. c0 &&
714 git pull .. anno1 &&
715 git rev-parse HEAD^2 >actual &&
716 test_cmp expect actual
717 )
718'
719
720test_expect_success 'merge annotated/signed tag w/ tracking' '
721 test_when_finished "rm -rf dst; git tag -d anno1" &&
722 git tag -a -m "anno c1" anno1 c1 &&
723 git init dst &&
724 git rev-parse c1 >dst/expect &&
725 (
726 # c0 fast-forwards to c1 and because this repository
727 # is a "downstream" whose refs/tags follows along
728 # tag from the "upstream", this pull defaults to --ff
729 cd dst &&
730 git remote add origin .. &&
731 git pull origin c0 &&
732 git fetch origin &&
733 git merge anno1 &&
734 git rev-parse HEAD >actual &&
735 test_cmp expect actual
736 )
737'
738
b5c9f1c1
JH
739test_expect_success GPG 'merge --ff-only tag' '
740 git reset --hard c0 &&
741 git commit --allow-empty -m "A newer commit" &&
742 git tag -s -m "A newer commit" signed &&
743 git reset --hard c0 &&
744
745 git merge --ff-only signed &&
746 git rev-parse signed^0 >expect &&
747 git rev-parse HEAD >actual &&
9c5b2fab 748 test_cmp expect actual
b5c9f1c1
JH
749'
750
3adab6f3
JH
751test_expect_success GPG 'merge --no-edit tag should skip editor' '
752 git reset --hard c0 &&
753 git commit --allow-empty -m "A newer commit" &&
754 git tag -f -s -m "A newer commit" signed &&
755 git reset --hard c0 &&
756
adcc94a0 757 EDITOR=false git merge --no-edit --no-ff signed &&
3adab6f3
JH
758 git rev-parse signed^0 >expect &&
759 git rev-parse HEAD^2 >actual &&
9c5b2fab 760 test_cmp expect actual
3adab6f3
JH
761'
762
e34f8027
JK
763test_expect_success 'set up mod-256 conflict scenario' '
764 # 256 near-identical stanzas...
765 for i in $(test_seq 1 256); do
766 for j in 1 2 3 4 5; do
767 echo $i-$j
768 done
769 done >file &&
770 git add file &&
771 git commit -m base &&
772
773 # one side changes the first line of each to "master"
774 sed s/-1/-master/ <file >tmp &&
775 mv tmp file &&
776 git commit -am master &&
777
778 # and the other to "side"; merging the two will
779 # yield 256 separate conflicts
780 git checkout -b side HEAD^ &&
781 sed s/-1/-side/ <file >tmp &&
782 mv tmp file &&
783 git commit -am side
784'
785
786test_expect_success 'merge detects mod-256 conflicts (recursive)' '
787 git reset --hard &&
788 test_must_fail git merge -s recursive master
789'
790
791test_expect_success 'merge detects mod-256 conflicts (resolve)' '
792 git reset --hard &&
793 test_must_fail git merge -s resolve master
794'
795
b84e65d4
JH
796test_expect_success 'merge nothing into void' '
797 git init void &&
798 (
799 cd void &&
800 git remote add up .. &&
801 git fetch up &&
802 test_must_fail git merge FETCH_HEAD
803 )
804'
805
367ff694
CP
806test_expect_success 'merge can be completed with --continue' '
807 git reset --hard c0 &&
808 git merge --no-ff --no-commit c1 &&
809 git merge --continue &&
810 verify_parents $c0 $c1
811'
812
9d89b355
MG
813write_script .git/FAKE_EDITOR <<EOF
814# kill -TERM command added below.
815EOF
816
817test_expect_success EXECKEEPSPID 'killed merge can be completed with --continue' '
818 git reset --hard c0 &&
819 ! "$SHELL_PATH" -c '\''
820 echo kill -TERM $$ >> .git/FAKE_EDITOR
821 GIT_EDITOR=.git/FAKE_EDITOR
822 export GIT_EDITOR
823 exec git merge --no-ff --edit c1'\'' &&
824 git merge --continue &&
825 verify_parents $c0 $c1
826'
827
a85d1b69 828test_done