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