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