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