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