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