blob: 9e27bbf902e275671cb80310630a8bedcaab353c [file] [log] [blame]
Lars Hjemlia85d1b62007-09-24 00:51:40 +02001#!/bin/sh
2#
3# Copyright (c) 2007 Lars Hjemli
4#
5
Nanako Shiraishi47a528a2008-09-03 17:59:33 +09006test_description='git merge
Lars Hjemlia85d1b62007-09-24 00:51:40 +02007
Jonathan Nieder4c073452010-08-17 01:53:56 -05008Testing basic merge operations/option parsing.
9
10! [c0] commit 0
11 ! [c1] commit 1
12 ! [c2] commit 2
13 ! [c3] commit 3
14 ! [c4] c4
15 ! [c5] c5
16 ! [c6] c6
17 * [master] Merge commit 'c1'
18--------
19 - [master] Merge commit 'c1'
20 + * [c1] commit 1
21 + [c6] c6
22 + [c5] c5
23 ++ [c4] c4
24 ++++ [c3] commit 3
25 + [c2] commit 2
26+++++++* [c0] commit 0
27'
Lars Hjemlia85d1b62007-09-24 00:51:40 +020028
29. ./test-lib.sh
Junio C Hamanob5c9f1c2012-02-05 16:22:12 -080030. "$TEST_DIRECTORY"/lib-gpg.sh
Lars Hjemlia85d1b62007-09-24 00:51:40 +020031
Jonathan Nieder73151df2011-05-06 15:58:52 -050032printf '%s\n' 1 2 3 4 5 6 7 8 9 >file
33printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >file.1
34printf '%s\n' 1 2 3 4 '5 X' 6 7 8 9 >file.5
35printf '%s\n' 1 2 3 4 5 6 7 8 '9 X' >file.9
36printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >result.1
37printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 9 >result.1-5
38printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 '9 X' >result.1-5-9
Junio C Hamano36a45b42011-05-16 16:46:23 -070039>empty
Lars Hjemlia85d1b62007-09-24 00:51:40 +020040
Jonathan Nieder73151df2011-05-06 15:58:52 -050041create_merge_msgs () {
Junio C Hamano57b58db2011-11-04 21:31:28 -070042 echo "Merge tag 'c2'" >msg.1-5 &&
43 echo "Merge tags 'c2' and 'c3'" >msg.1-5-9 &&
Jonathan Nieder73151df2011-05-06 15:58:52 -050044 {
45 echo "Squashed commit of the following:" &&
46 echo &&
47 git log --no-merges ^HEAD c1
48 } >squash.1 &&
49 {
50 echo "Squashed commit of the following:" &&
51 echo &&
52 git log --no-merges ^HEAD c2
53 } >squash.1-5 &&
54 {
55 echo "Squashed commit of the following:" &&
56 echo &&
57 git log --no-merges ^HEAD c2 c3
58 } >squash.1-5-9 &&
59 echo >msg.nolog &&
60 {
Junio C Hamano57b58db2011-11-04 21:31:28 -070061 echo "* tag 'c3':" &&
Jonathan Nieder73151df2011-05-06 15:58:52 -050062 echo " commit 3" &&
63 echo
64 } >msg.log
65}
Lars Hjemlia85d1b62007-09-24 00:51:40 +020066
Jonathan Nieder73151df2011-05-06 15:58:52 -050067verify_merge () {
68 test_cmp "$2" "$1" &&
69 git update-index --refresh &&
70 git diff --exit-code &&
71 if test -n "$3"
72 then
73 git show -s --pretty=format:%s HEAD >msg.act &&
74 test_cmp "$3" msg.act
75 fi
76}
Lars Hjemlia85d1b62007-09-24 00:51:40 +020077
Jonathan Nieder73151df2011-05-06 15:58:52 -050078verify_head () {
79 echo "$1" >head.expected &&
80 git rev-parse HEAD >head.actual &&
81 test_cmp head.expected head.actual
82}
Jonathan Nieder4c073452010-08-17 01:53:56 -050083
Jonathan Nieder73151df2011-05-06 15:58:52 -050084verify_parents () {
85 printf '%s\n' "$@" >parents.expected &&
86 >parents.actual &&
87 i=1 &&
88 while test $i -le $#
89 do
90 git rev-parse HEAD^$i >>parents.actual &&
91 i=$(expr $i + 1) ||
92 return 1
93 done &&
Jonathan Nieder3fc0dbf2011-05-06 16:00:21 -050094 test_must_fail git rev-parse --verify "HEAD^$i" &&
Jonathan Nieder73151df2011-05-06 15:58:52 -050095 test_cmp parents.expected parents.actual
96}
Lars Hjemlia85d1b62007-09-24 00:51:40 +020097
Jonathan Nieder73151df2011-05-06 15:58:52 -050098verify_mergeheads () {
99 printf '%s\n' "$@" >mergehead.expected &&
Junio C Hamano274a5c02011-11-07 14:45:10 -0800100 while read sha1 rest
101 do
102 git rev-parse $sha1
103 done <.git/MERGE_HEAD >mergehead.actual &&
104 test_cmp mergehead.expected mergehead.actual
Jonathan Nieder73151df2011-05-06 15:58:52 -0500105}
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200106
Jonathan Nieder73151df2011-05-06 15:58:52 -0500107verify_no_mergehead () {
108 ! test -e .git/MERGE_HEAD
109}
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200110
111test_expect_success 'setup' '
112 git add file &&
113 test_tick &&
114 git commit -m "commit 0" &&
115 git tag c0 &&
116 c0=$(git rev-parse HEAD) &&
117 cp file.1 file &&
118 git add file &&
119 test_tick &&
120 git commit -m "commit 1" &&
121 git tag c1 &&
122 c1=$(git rev-parse HEAD) &&
123 git reset --hard "$c0" &&
124 cp file.5 file &&
125 git add file &&
126 test_tick &&
127 git commit -m "commit 2" &&
128 git tag c2 &&
129 c2=$(git rev-parse HEAD) &&
130 git reset --hard "$c0" &&
131 cp file.9 file &&
132 git add file &&
133 test_tick &&
134 git commit -m "commit 3" &&
135 git tag c3 &&
136 c3=$(git rev-parse HEAD)
137 git reset --hard "$c0" &&
138 create_merge_msgs
139'
140
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500141test_debug 'git log --graph --decorate --oneline --all'
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200142
Michele Ballabio74f5b7f2008-07-20 14:34:47 +0200143test_expect_success 'test option parsing' '
Johannes Sixt01941bd2008-07-16 10:33:52 +0200144 test_must_fail git merge -$ c1 &&
145 test_must_fail git merge --no-such c1 &&
146 test_must_fail git merge -s foobar c1 &&
147 test_must_fail git merge -s=foobar c1 &&
148 test_must_fail git merge -m &&
149 test_must_fail git merge
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200150'
151
Nguyễn Thái Ngọc Duyda53eec2010-10-22 01:49:45 -0500152test_expect_success 'merge -h with invalid index' '
153 mkdir broken &&
154 (
155 cd broken &&
156 git init &&
157 >.git/index &&
158 test_expect_code 129 git merge -h 2>usage
159 ) &&
160 grep "[Uu]sage: git merge" broken/usage
161'
162
Miklos Vajnadce61e72008-07-30 01:17:01 +0200163test_expect_success 'reject non-strategy with a git-merge-foo name' '
164 test_must_fail git merge -s index c1
165'
166
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200167test_expect_success 'merge c0 with c1' '
Jonathan Niederff372c72010-08-17 01:56:13 -0500168 echo "OBJID HEAD@{0}: merge c1: Fast-forward" >reflog.expected &&
169
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200170 git reset --hard c0 &&
171 git merge c1 &&
172 verify_merge file result.1 &&
Jonathan Niederff372c72010-08-17 01:56:13 -0500173 verify_head "$c1" &&
174
175 git reflog -1 >reflog.actual &&
176 sed "s/$_x05[0-9a-f]*/OBJID/g" reflog.actual >reflog.fuzzy &&
177 test_cmp reflog.expected reflog.fuzzy
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200178'
179
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500180test_debug 'git log --graph --decorate --oneline --all'
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200181
Björn Gustavsson13474832009-10-29 23:08:31 +0100182test_expect_success 'merge c0 with c1 with --ff-only' '
183 git reset --hard c0 &&
184 git merge --ff-only c1 &&
185 git merge --ff-only HEAD c0 c1 &&
186 verify_merge file result.1 &&
187 verify_head "$c1"
188'
189
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500190test_debug 'git log --graph --decorate --oneline --all'
Björn Gustavsson13474832009-10-29 23:08:31 +0100191
Jonathan Nieder94d63ce2010-08-17 01:56:46 -0500192test_expect_success 'merge from unborn branch' '
193 git checkout -f master &&
194 test_might_fail git branch -D kid &&
195
196 echo "OBJID HEAD@{0}: initial pull" >reflog.expected &&
197
198 git checkout --orphan kid &&
199 test_when_finished "git checkout -f master" &&
200 git rm -fr . &&
201 test_tick &&
202 git merge --ff-only c1 &&
203 verify_merge file result.1 &&
204 verify_head "$c1" &&
205
206 git reflog -1 >reflog.actual &&
207 sed "s/$_x05[0-9a-f][0-9a-f]/OBJID/g" reflog.actual >reflog.fuzzy &&
208 test_cmp reflog.expected reflog.fuzzy
209'
210
211test_debug 'git log --graph --decorate --oneline --all'
212
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200213test_expect_success 'merge c1 with c2' '
214 git reset --hard c1 &&
215 test_tick &&
216 git merge c2 &&
217 verify_merge file result.1-5 msg.1-5 &&
218 verify_parents $c1 $c2
219'
220
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500221test_debug 'git log --graph --decorate --oneline --all'
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200222
223test_expect_success 'merge c1 with c2 and c3' '
224 git reset --hard c1 &&
225 test_tick &&
226 git merge c2 c3 &&
227 verify_merge file result.1-5-9 msg.1-5-9 &&
228 verify_parents $c1 $c2 $c3
229'
230
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500231test_debug 'git log --graph --decorate --oneline --all'
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200232
Junio C Hamanof23e8de2011-05-06 12:27:05 -0700233test_expect_success 'merges with --ff-only' '
Björn Gustavsson13474832009-10-29 23:08:31 +0100234 git reset --hard c1 &&
235 test_tick &&
236 test_must_fail git merge --ff-only c2 &&
237 test_must_fail git merge --ff-only c3 &&
Junio C Hamanof23e8de2011-05-06 12:27:05 -0700238 test_must_fail git merge --ff-only c2 c3 &&
239 git reset --hard c0 &&
240 git merge c3 &&
241 verify_head $c3
242'
243
244test_expect_success 'merges with merge.ff=only' '
245 git reset --hard c1 &&
246 test_tick &&
247 test_when_finished "git config --unset merge.ff" &&
248 git config merge.ff only &&
249 test_must_fail git merge c2 &&
250 test_must_fail git merge c3 &&
251 test_must_fail git merge c2 c3 &&
252 git reset --hard c0 &&
253 git merge c3 &&
254 verify_head $c3
Björn Gustavsson13474832009-10-29 23:08:31 +0100255'
256
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200257test_expect_success 'merge c0 with c1 (no-commit)' '
258 git reset --hard c0 &&
259 git merge --no-commit c1 &&
260 verify_merge file result.1 &&
261 verify_head $c1
262'
263
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500264test_debug 'git log --graph --decorate --oneline --all'
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200265
266test_expect_success 'merge c1 with c2 (no-commit)' '
267 git reset --hard c1 &&
268 git merge --no-commit c2 &&
269 verify_merge file result.1-5 &&
270 verify_head $c1 &&
271 verify_mergeheads $c2
272'
273
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500274test_debug 'git log --graph --decorate --oneline --all'
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200275
276test_expect_success 'merge c1 with c2 and c3 (no-commit)' '
277 git reset --hard c1 &&
278 git merge --no-commit c2 c3 &&
279 verify_merge file result.1-5-9 &&
280 verify_head $c1 &&
281 verify_mergeheads $c2 $c3
282'
283
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500284test_debug 'git log --graph --decorate --oneline --all'
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200285
286test_expect_success 'merge c0 with c1 (squash)' '
287 git reset --hard c0 &&
288 git merge --squash c1 &&
289 verify_merge file result.1 &&
290 verify_head $c0 &&
291 verify_no_mergehead &&
Jonathan Nieder4c073452010-08-17 01:53:56 -0500292 test_cmp squash.1 .git/SQUASH_MSG
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200293'
294
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500295test_debug 'git log --graph --decorate --oneline --all'
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200296
Björn Gustavsson13474832009-10-29 23:08:31 +0100297test_expect_success 'merge c0 with c1 (squash, ff-only)' '
298 git reset --hard c0 &&
299 git merge --squash --ff-only c1 &&
300 verify_merge file result.1 &&
301 verify_head $c0 &&
302 verify_no_mergehead &&
Jonathan Nieder4c073452010-08-17 01:53:56 -0500303 test_cmp squash.1 .git/SQUASH_MSG
Björn Gustavsson13474832009-10-29 23:08:31 +0100304'
305
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500306test_debug 'git log --graph --decorate --oneline --all'
Björn Gustavsson13474832009-10-29 23:08:31 +0100307
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200308test_expect_success 'merge c1 with c2 (squash)' '
309 git reset --hard c1 &&
310 git merge --squash c2 &&
311 verify_merge file result.1-5 &&
312 verify_head $c1 &&
313 verify_no_mergehead &&
Jonathan Nieder4c073452010-08-17 01:53:56 -0500314 test_cmp squash.1-5 .git/SQUASH_MSG
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200315'
316
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500317test_debug 'git log --graph --decorate --oneline --all'
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200318
Björn Gustavsson13474832009-10-29 23:08:31 +0100319test_expect_success 'unsuccesful merge of c1 with c2 (squash, ff-only)' '
320 git reset --hard c1 &&
321 test_must_fail git merge --squash --ff-only c2
322'
323
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500324test_debug 'git log --graph --decorate --oneline --all'
Björn Gustavsson13474832009-10-29 23:08:31 +0100325
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200326test_expect_success 'merge c1 with c2 and c3 (squash)' '
327 git reset --hard c1 &&
328 git merge --squash c2 c3 &&
329 verify_merge file result.1-5-9 &&
330 verify_head $c1 &&
331 verify_no_mergehead &&
Jonathan Nieder4c073452010-08-17 01:53:56 -0500332 test_cmp squash.1-5-9 .git/SQUASH_MSG
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200333'
334
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500335test_debug 'git log --graph --decorate --oneline --all'
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200336
Lars Hjemliaec7b362007-09-24 00:51:43 +0200337test_expect_success 'merge c1 with c2 (no-commit in config)' '
338 git reset --hard c1 &&
339 git config branch.master.mergeoptions "--no-commit" &&
340 git merge c2 &&
341 verify_merge file result.1-5 &&
342 verify_head $c1 &&
343 verify_mergeheads $c2
344'
345
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500346test_debug 'git log --graph --decorate --oneline --all'
Lars Hjemliaec7b362007-09-24 00:51:43 +0200347
Junio C Hamano0d8fc3e2011-05-04 17:42:51 -0700348test_expect_success 'merge c1 with c2 (log in config)' '
349 git config branch.master.mergeoptions "" &&
350 git reset --hard c1 &&
351 git merge --log c2 &&
352 git show -s --pretty=tformat:%s%n%b >expect &&
353
354 git config branch.master.mergeoptions --log &&
355 git reset --hard c1 &&
356 git merge c2 &&
357 git show -s --pretty=tformat:%s%n%b >actual &&
358
359 test_cmp expect actual
360'
361
362test_expect_success 'merge c1 with c2 (log in config gets overridden)' '
Junio C Hamano541d1fa2011-05-06 15:03:25 -0700363 test_when_finished "git config --remove-section branch.master" &&
364 test_when_finished "git config --remove-section merge" &&
365 test_might_fail git config --remove-section branch.master &&
366 test_might_fail git config --remove-section merge &&
367
Junio C Hamano0d8fc3e2011-05-04 17:42:51 -0700368 git reset --hard c1 &&
369 git merge c2 &&
370 git show -s --pretty=tformat:%s%n%b >expect &&
371
372 git config branch.master.mergeoptions "--no-log" &&
373 git config merge.log true &&
374 git reset --hard c1 &&
375 git merge c2 &&
376 git show -s --pretty=tformat:%s%n%b >actual &&
377
378 test_cmp expect actual
379'
380
Lars Hjemliaec7b362007-09-24 00:51:43 +0200381test_expect_success 'merge c1 with c2 (squash in config)' '
382 git reset --hard c1 &&
383 git config branch.master.mergeoptions "--squash" &&
384 git merge c2 &&
385 verify_merge file result.1-5 &&
386 verify_head $c1 &&
387 verify_no_mergehead &&
Jonathan Nieder4c073452010-08-17 01:53:56 -0500388 test_cmp squash.1-5 .git/SQUASH_MSG
Lars Hjemliaec7b362007-09-24 00:51:43 +0200389'
390
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500391test_debug 'git log --graph --decorate --oneline --all'
Lars Hjemliaec7b362007-09-24 00:51:43 +0200392
SZEDER Gábord8abe142008-04-06 03:23:43 +0200393test_expect_success 'override config option -n with --summary' '
Lars Hjemliaec7b362007-09-24 00:51:43 +0200394 git reset --hard c1 &&
395 git config branch.master.mergeoptions "-n" &&
396 test_tick &&
397 git merge --summary c2 >diffstat.txt &&
398 verify_merge file result.1-5 msg.1-5 &&
399 verify_parents $c1 $c2 &&
Jeff Kingaadbe442008-03-12 17:32:17 -0400400 if ! grep "^ file | *2 +-$" diffstat.txt
Lars Hjemliaec7b362007-09-24 00:51:43 +0200401 then
SZEDER Gábord8abe142008-04-06 03:23:43 +0200402 echo "[OOPS] diffstat was not generated with --summary"
403 false
404 fi
405'
406
407test_expect_success 'override config option -n with --stat' '
408 git reset --hard c1 &&
409 git config branch.master.mergeoptions "-n" &&
410 test_tick &&
411 git merge --stat c2 >diffstat.txt &&
412 verify_merge file result.1-5 msg.1-5 &&
413 verify_parents $c1 $c2 &&
414 if ! grep "^ file | *2 +-$" diffstat.txt
415 then
416 echo "[OOPS] diffstat was not generated with --stat"
417 false
Lars Hjemliaec7b362007-09-24 00:51:43 +0200418 fi
419'
420
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500421test_debug 'git log --graph --decorate --oneline --all'
Lars Hjemliaec7b362007-09-24 00:51:43 +0200422
SZEDER Gábord8abe142008-04-06 03:23:43 +0200423test_expect_success 'override config option --stat' '
Lars Hjemliaec7b362007-09-24 00:51:43 +0200424 git reset --hard c1 &&
SZEDER Gábord8abe142008-04-06 03:23:43 +0200425 git config branch.master.mergeoptions "--stat" &&
Lars Hjemliaec7b362007-09-24 00:51:43 +0200426 test_tick &&
427 git merge -n c2 >diffstat.txt &&
428 verify_merge file result.1-5 msg.1-5 &&
429 verify_parents $c1 $c2 &&
Jeff Kingaadbe442008-03-12 17:32:17 -0400430 if grep "^ file | *2 +-$" diffstat.txt
Lars Hjemliaec7b362007-09-24 00:51:43 +0200431 then
432 echo "[OOPS] diffstat was generated"
433 false
434 fi
435'
436
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500437test_debug 'git log --graph --decorate --oneline --all'
Lars Hjemliaec7b362007-09-24 00:51:43 +0200438
Lars Hjemlid08af0a2007-09-24 00:51:44 +0200439test_expect_success 'merge c1 with c2 (override --no-commit)' '
440 git reset --hard c1 &&
441 git config branch.master.mergeoptions "--no-commit" &&
442 test_tick &&
443 git merge --commit c2 &&
444 verify_merge file result.1-5 msg.1-5 &&
445 verify_parents $c1 $c2
446'
447
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500448test_debug 'git log --graph --decorate --oneline --all'
Lars Hjemlid08af0a2007-09-24 00:51:44 +0200449
450test_expect_success 'merge c1 with c2 (override --squash)' '
451 git reset --hard c1 &&
452 git config branch.master.mergeoptions "--squash" &&
453 test_tick &&
454 git merge --no-squash c2 &&
455 verify_merge file result.1-5 msg.1-5 &&
456 verify_parents $c1 $c2
457'
458
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500459test_debug 'git log --graph --decorate --oneline --all'
Lars Hjemlid08af0a2007-09-24 00:51:44 +0200460
Lars Hjemlid66424c2007-09-24 00:51:45 +0200461test_expect_success 'merge c0 with c1 (no-ff)' '
462 git reset --hard c0 &&
Gerrit Papee6d1f762008-03-03 09:22:03 +0000463 git config branch.master.mergeoptions "" &&
Lars Hjemlid66424c2007-09-24 00:51:45 +0200464 test_tick &&
465 git merge --no-ff c1 &&
466 verify_merge file result.1 &&
467 verify_parents $c0 $c1
468'
469
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500470test_debug 'git log --graph --decorate --oneline --all'
Lars Hjemlid66424c2007-09-24 00:51:45 +0200471
Junio C Hamanof23e8de2011-05-06 12:27:05 -0700472test_expect_success 'merge c0 with c1 (merge.ff=false)' '
473 git reset --hard c0 &&
474 git config merge.ff false &&
475 test_tick &&
476 git merge c1 &&
477 git config --remove-section merge &&
478 verify_merge file result.1 &&
479 verify_parents $c0 $c1
480'
481test_debug 'git log --graph --decorate --oneline --all'
482
483test_expect_success 'combine branch.master.mergeoptions with merge.ff' '
484 git reset --hard c0 &&
Jonathan Nieder8c5cea02011-05-06 16:59:47 -0500485 git config branch.master.mergeoptions --ff &&
486 git config merge.ff false &&
Junio C Hamanof23e8de2011-05-06 12:27:05 -0700487 test_tick &&
488 git merge c1 &&
489 git config --remove-section "branch.master" &&
490 git config --remove-section "merge" &&
491 verify_merge file result.1 &&
492 verify_parents "$c0"
493'
494
Jonathan Nieder8c5cea02011-05-06 16:59:47 -0500495test_expect_success 'tolerate unknown values for merge.ff' '
496 git reset --hard c0 &&
497 git config merge.ff something-new &&
498 test_tick &&
499 git merge c1 2>message &&
500 git config --remove-section "merge" &&
501 verify_head "$c1" &&
502 test_cmp empty message
503'
504
Gerrit Papee6d1f762008-03-03 09:22:03 +0000505test_expect_success 'combining --squash and --no-ff is refused' '
Jonathan Nieder8c5cea02011-05-06 16:59:47 -0500506 git reset --hard c0 &&
Gerrit Papee6d1f762008-03-03 09:22:03 +0000507 test_must_fail git merge --squash --no-ff c1 &&
508 test_must_fail git merge --no-ff --squash c1
509'
510
Björn Gustavsson13474832009-10-29 23:08:31 +0100511test_expect_success 'combining --ff-only and --no-ff is refused' '
512 test_must_fail git merge --ff-only --no-ff c1 &&
513 test_must_fail git merge --no-ff --ff-only c1
514'
515
Lars Hjemlid66424c2007-09-24 00:51:45 +0200516test_expect_success 'merge c0 with c1 (ff overrides no-ff)' '
517 git reset --hard c0 &&
518 git config branch.master.mergeoptions "--no-ff" &&
519 git merge --ff c1 &&
520 verify_merge file result.1 &&
521 verify_head $c1
522'
523
SZEDER Gáborefb779f2008-04-06 03:23:46 +0200524test_expect_success 'merge log message' '
525 git reset --hard c0 &&
526 git merge --no-log c2 &&
527 git show -s --pretty=format:%b HEAD >msg.act &&
Jonathan Nieder4c073452010-08-17 01:53:56 -0500528 test_cmp msg.nolog msg.act &&
Junio C Hamano4393c232008-07-10 00:50:59 -0700529
SZEDER Gáborefb779f2008-04-06 03:23:46 +0200530 git merge --log c3 &&
531 git show -s --pretty=format:%b HEAD >msg.act &&
Jonathan Nieder4c073452010-08-17 01:53:56 -0500532 test_cmp msg.log msg.act &&
Junio C Hamano4393c232008-07-10 00:50:59 -0700533
534 git reset --hard HEAD^ &&
535 git config merge.log yes &&
536 git merge c3 &&
537 git show -s --pretty=format:%b HEAD >msg.act &&
Jonathan Nieder4c073452010-08-17 01:53:56 -0500538 test_cmp msg.log msg.act
SZEDER Gáborefb779f2008-04-06 03:23:46 +0200539'
540
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500541test_debug 'git log --graph --decorate --oneline --all'
Lars Hjemlid66424c2007-09-24 00:51:45 +0200542
Sverre Hvammen Johansen3d1dd472008-07-13 08:13:55 +0000543test_expect_success 'merge c1 with c0, c2, c0, and c1' '
544 git reset --hard c1 &&
545 git config branch.master.mergeoptions "" &&
546 test_tick &&
547 git merge c0 c2 c0 c1 &&
548 verify_merge file result.1-5 &&
549 verify_parents $c1 $c2
550'
551
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500552test_debug 'git log --graph --decorate --oneline --all'
Sverre Hvammen Johansen3d1dd472008-07-13 08:13:55 +0000553
Junio C Hamano711f6b22008-07-14 00:09:41 -0700554test_expect_success 'merge c1 with c0, c2, c0, and c1' '
555 git reset --hard c1 &&
556 git config branch.master.mergeoptions "" &&
557 test_tick &&
558 git merge c0 c2 c0 c1 &&
559 verify_merge file result.1-5 &&
560 verify_parents $c1 $c2
561'
562
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500563test_debug 'git log --graph --decorate --oneline --all'
Junio C Hamano711f6b22008-07-14 00:09:41 -0700564
565test_expect_success 'merge c1 with c1 and c2' '
566 git reset --hard c1 &&
567 git config branch.master.mergeoptions "" &&
568 test_tick &&
569 git merge c1 c2 &&
570 verify_merge file result.1-5 &&
571 verify_parents $c1 $c2
572'
573
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500574test_debug 'git log --graph --decorate --oneline --all'
Junio C Hamano711f6b22008-07-14 00:09:41 -0700575
Junio C Hamano9ca8f602008-08-20 15:09:28 -0700576test_expect_success 'merge fast-forward in a dirty tree' '
577 git reset --hard c0 &&
578 mv file file1 &&
579 cat file1 >file &&
580 rm -f file1 &&
581 git merge c2
582'
583
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500584test_debug 'git log --graph --decorate --oneline --all'
Junio C Hamano9ca8f602008-08-20 15:09:28 -0700585
Junio C Hamanoc9ea1182011-04-14 14:36:14 -0700586test_expect_success 'in-index merge' '
Junio C Hamano446247d2008-08-23 12:56:57 -0700587 git reset --hard c0 &&
Jonathan Nieder4c073452010-08-17 01:53:56 -0500588 git merge --no-ff -s resolve c1 >out &&
Junio C Hamanoc9ea1182011-04-14 14:36:14 -0700589 test_i18ngrep "Wonderful." out &&
Junio C Hamano446247d2008-08-23 12:56:57 -0700590 verify_parents $c0 $c1
591'
592
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500593test_debug 'git log --graph --decorate --oneline --all'
Junio C Hamano446247d2008-08-23 12:56:57 -0700594
Miklos Vajna668f26f2008-10-03 15:02:31 +0200595test_expect_success 'refresh the index before merging' '
596 git reset --hard c1 &&
Junio C Hamano016e5ff2010-04-06 17:08:54 -0700597 cp file file.n && mv -f file.n file &&
Miklos Vajna668f26f2008-10-03 15:02:31 +0200598 git merge c3
599'
600
Jonathan Niederb81f9252010-08-17 01:52:48 -0500601cat >expected.branch <<\EOF
602Merge branch 'c5-branch' (early part)
603EOF
604cat >expected.tag <<\EOF
605Merge commit 'c5~1'
Miklos Vajna4e6d4bc2008-10-13 22:54:25 +0200606EOF
607
608test_expect_success 'merge early part of c2' '
609 git reset --hard c3 &&
Jonathan Nieder4c073452010-08-17 01:53:56 -0500610 echo c4 >c4.c &&
Miklos Vajna4e6d4bc2008-10-13 22:54:25 +0200611 git add c4.c &&
612 git commit -m c4 &&
613 git tag c4 &&
Jonathan Nieder4c073452010-08-17 01:53:56 -0500614 echo c5 >c5.c &&
Miklos Vajna4e6d4bc2008-10-13 22:54:25 +0200615 git add c5.c &&
616 git commit -m c5 &&
617 git tag c5 &&
618 git reset --hard c3 &&
Jonathan Nieder4c073452010-08-17 01:53:56 -0500619 echo c6 >c6.c &&
Miklos Vajna4e6d4bc2008-10-13 22:54:25 +0200620 git add c6.c &&
621 git commit -m c6 &&
622 git tag c6 &&
Jonathan Niederb81f9252010-08-17 01:52:48 -0500623 git branch -f c5-branch c5 &&
624 git merge c5-branch~1 &&
625 git show -s --pretty=format:%s HEAD >actual.branch &&
626 git reset --keep HEAD^ &&
Miklos Vajna4e6d4bc2008-10-13 22:54:25 +0200627 git merge c5~1 &&
Jonathan Niederb81f9252010-08-17 01:52:48 -0500628 git show -s --pretty=format:%s HEAD >actual.tag &&
629 test_cmp expected.branch actual.branch &&
630 test_cmp expected.tag actual.tag
Miklos Vajna4e6d4bc2008-10-13 22:54:25 +0200631'
632
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500633test_debug 'git log --graph --decorate --oneline --all'
Miklos Vajna668f26f2008-10-03 15:02:31 +0200634
Miklos Vajnacf10f9f2008-10-03 14:04:47 +0200635test_expect_success 'merge --no-ff --no-commit && commit' '
636 git reset --hard c0 &&
637 git merge --no-ff --no-commit c1 &&
638 EDITOR=: git commit &&
639 verify_parents $c0 $c1
640'
641
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500642test_debug 'git log --graph --decorate --oneline --all'
Miklos Vajnacf10f9f2008-10-03 14:04:47 +0200643
644test_expect_success 'amending no-ff merge commit' '
645 EDITOR=: git commit --amend &&
646 verify_parents $c0 $c1
647'
648
Jonathan Niederdf516fb2010-08-17 01:54:59 -0500649test_debug 'git log --graph --decorate --oneline --all'
Miklos Vajnacf10f9f2008-10-03 14:04:47 +0200650
Jay Soffian66f4b982011-10-08 14:39:52 -0400651cat >editor <<\EOF
652#!/bin/sh
653# Add a new message string that was not in the template
654(
655 echo "Merge work done on the side branch c1"
656 echo
657 cat <"$1"
658) >"$1.tmp" && mv "$1.tmp" "$1"
659# strip comments and blank lines from end of message
660sed -e '/^#/d' < "$1" | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' > expected
661EOF
662chmod 755 editor
663
664test_expect_success 'merge --no-ff --edit' '
665 git reset --hard c0 &&
666 EDITOR=./editor git merge --no-ff --edit c1 &&
667 verify_parents $c0 $c1 &&
668 git cat-file commit HEAD >raw &&
669 grep "work done on the side branch" raw &&
670 sed "1,/^$/d" >actual raw &&
671 test_cmp actual expected
672'
673
Junio C Hamanob5c9f1c2012-02-05 16:22:12 -0800674test_expect_success GPG 'merge --ff-only tag' '
675 git reset --hard c0 &&
676 git commit --allow-empty -m "A newer commit" &&
677 git tag -s -m "A newer commit" signed &&
678 git reset --hard c0 &&
679
680 git merge --ff-only signed &&
681 git rev-parse signed^0 >expect &&
682 git rev-parse HEAD >actual &&
683 test_cmp actual expect
684'
685
Junio C Hamano3adab6f2012-02-09 13:30:52 -0800686test_expect_success GPG 'merge --no-edit tag should skip editor' '
687 git reset --hard c0 &&
688 git commit --allow-empty -m "A newer commit" &&
689 git tag -f -s -m "A newer commit" signed &&
690 git reset --hard c0 &&
691
692 EDITOR=false git merge --no-edit signed &&
693 git rev-parse signed^0 >expect &&
694 git rev-parse HEAD^2 >actual &&
695 test_cmp actual expect
696'
697
Lars Hjemlia85d1b62007-09-24 00:51:40 +0200698test_done