]>
Commit | Line | Data |
---|---|---|
a85d1b69 LH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Lars Hjemli | |
4 | # | |
5 | ||
47a528ad | 6 | test_description='git merge |
a85d1b69 | 7 | |
4c073457 JN |
8 | Testing basic merge operations/option parsing. |
9 | ||
10 | ! [c0] commit 0 | |
11 | ! [c1] commit 1 | |
12 | ! [c2] commit 2 | |
13 | ! [c3] commit 3 | |
14 | ! [c4] c4 | |
15 | ! [c5] c5 | |
16 | ! [c6] c6 | |
17 | * [master] Merge commit 'c1' | |
18 | -------- | |
19 | - [master] Merge commit 'c1' | |
20 | + * [c1] commit 1 | |
21 | + [c6] c6 | |
22 | + [c5] c5 | |
23 | ++ [c4] c4 | |
24 | ++++ [c3] commit 3 | |
25 | + [c2] commit 2 | |
26 | +++++++* [c0] commit 0 | |
27 | ' | |
a85d1b69 LH |
28 | |
29 | . ./test-lib.sh | |
b5c9f1c1 | 30 | . "$TEST_DIRECTORY"/lib-gpg.sh |
a85d1b69 | 31 | |
73151df0 JN |
32 | printf '%s\n' 1 2 3 4 5 6 7 8 9 >file |
33 | printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >file.1 | |
34 | printf '%s\n' 1 2 3 4 '5 X' 6 7 8 9 >file.5 | |
35 | printf '%s\n' 1 2 3 4 5 6 7 8 '9 X' >file.9 | |
36 | printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >result.1 | |
37 | printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 9 >result.1-5 | |
38 | printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 '9 X' >result.1-5-9 | |
36a45b4f | 39 | >empty |
4c073457 | 40 | |
73151df0 | 41 | create_merge_msgs () { |
57b58db7 JH |
42 | echo "Merge tag 'c2'" >msg.1-5 && |
43 | echo "Merge tags 'c2' and 'c3'" >msg.1-5-9 && | |
73151df0 JN |
44 | { |
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 && | |
cee683b7 YD |
59 | : >msg.nologff && |
60 | echo >msg.nolognoff && | |
73151df0 | 61 | { |
57b58db7 | 62 | echo "* tag 'c3':" && |
73151df0 JN |
63 | echo " commit 3" && |
64 | echo | |
65 | } >msg.log | |
66 | } | |
4c073457 | 67 | |
73151df0 JN |
68 | verify_merge () { |
69 | test_cmp "$2" "$1" && | |
70 | git update-index --refresh && | |
71 | git diff --exit-code && | |
72 | if test -n "$3" | |
73 | then | |
74 | git show -s --pretty=format:%s HEAD >msg.act && | |
75 | test_cmp "$3" msg.act | |
76 | fi | |
77 | } | |
4c073457 | 78 | |
73151df0 JN |
79 | verify_head () { |
80 | echo "$1" >head.expected && | |
81 | git rev-parse HEAD >head.actual && | |
82 | test_cmp head.expected head.actual | |
83 | } | |
4c073457 | 84 | |
73151df0 JN |
85 | verify_parents () { |
86 | printf '%s\n' "$@" >parents.expected && | |
87 | >parents.actual && | |
88 | i=1 && | |
89 | while test $i -le $# | |
90 | do | |
91 | git rev-parse HEAD^$i >>parents.actual && | |
92 | i=$(expr $i + 1) || | |
93 | return 1 | |
94 | done && | |
3fc0dbf0 | 95 | test_must_fail git rev-parse --verify "HEAD^$i" && |
73151df0 JN |
96 | test_cmp parents.expected parents.actual |
97 | } | |
a85d1b69 | 98 | |
73151df0 JN |
99 | verify_mergeheads () { |
100 | printf '%s\n' "$@" >mergehead.expected && | |
274a5c06 JH |
101 | while read sha1 rest |
102 | do | |
103 | git rev-parse $sha1 | |
104 | done <.git/MERGE_HEAD >mergehead.actual && | |
105 | test_cmp mergehead.expected mergehead.actual | |
73151df0 | 106 | } |
a85d1b69 | 107 | |
73151df0 JN |
108 | verify_no_mergehead () { |
109 | ! test -e .git/MERGE_HEAD | |
110 | } | |
a85d1b69 LH |
111 | |
112 | test_expect_success 'setup' ' | |
113 | git add file && | |
114 | test_tick && | |
115 | git commit -m "commit 0" && | |
116 | git tag c0 && | |
117 | c0=$(git rev-parse HEAD) && | |
118 | cp file.1 file && | |
119 | git add file && | |
120 | test_tick && | |
121 | git commit -m "commit 1" && | |
122 | git tag c1 && | |
123 | c1=$(git rev-parse HEAD) && | |
124 | git reset --hard "$c0" && | |
125 | cp file.5 file && | |
126 | git add file && | |
127 | test_tick && | |
128 | git commit -m "commit 2" && | |
129 | git tag c2 && | |
130 | c2=$(git rev-parse HEAD) && | |
131 | git reset --hard "$c0" && | |
132 | cp file.9 file && | |
133 | git add file && | |
134 | test_tick && | |
135 | git commit -m "commit 3" && | |
136 | git tag c3 && | |
137 | c3=$(git rev-parse HEAD) | |
138 | git reset --hard "$c0" && | |
139 | create_merge_msgs | |
140 | ' | |
141 | ||
df516fb5 | 142 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 | 143 | |
74f5b7fb | 144 | test_expect_success 'test option parsing' ' |
01941bd5 JS |
145 | test_must_fail git merge -$ c1 && |
146 | test_must_fail git merge --no-such c1 && | |
147 | test_must_fail git merge -s foobar c1 && | |
148 | test_must_fail git merge -s=foobar c1 && | |
149 | test_must_fail git merge -m && | |
150 | test_must_fail git merge | |
a85d1b69 LH |
151 | ' |
152 | ||
da53eec6 NTND |
153 | test_expect_success 'merge -h with invalid index' ' |
154 | mkdir broken && | |
155 | ( | |
156 | cd broken && | |
157 | git init && | |
158 | >.git/index && | |
159 | test_expect_code 129 git merge -h 2>usage | |
160 | ) && | |
9a001381 | 161 | test_i18ngrep "[Uu]sage: git merge" broken/usage |
da53eec6 NTND |
162 | ' |
163 | ||
dce61e72 MV |
164 | test_expect_success 'reject non-strategy with a git-merge-foo name' ' |
165 | test_must_fail git merge -s index c1 | |
166 | ' | |
167 | ||
a85d1b69 | 168 | test_expect_success 'merge c0 with c1' ' |
ff372c78 JN |
169 | echo "OBJID HEAD@{0}: merge c1: Fast-forward" >reflog.expected && |
170 | ||
a85d1b69 LH |
171 | git reset --hard c0 && |
172 | git merge c1 && | |
173 | verify_merge file result.1 && | |
ff372c78 JN |
174 | verify_head "$c1" && |
175 | ||
176 | git reflog -1 >reflog.actual && | |
177 | sed "s/$_x05[0-9a-f]*/OBJID/g" reflog.actual >reflog.fuzzy && | |
178 | test_cmp reflog.expected reflog.fuzzy | |
a85d1b69 LH |
179 | ' |
180 | ||
df516fb5 | 181 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 | 182 | |
13474835 BG |
183 | test_expect_success 'merge c0 with c1 with --ff-only' ' |
184 | git reset --hard c0 && | |
185 | git merge --ff-only c1 && | |
186 | git merge --ff-only HEAD c0 c1 && | |
187 | verify_merge file result.1 && | |
188 | verify_head "$c1" | |
189 | ' | |
190 | ||
df516fb5 | 191 | test_debug 'git log --graph --decorate --oneline --all' |
94d63ce2 JN |
192 | |
193 | test_expect_success 'merge from unborn branch' ' | |
194 | git checkout -f master && | |
195 | test_might_fail git branch -D kid && | |
196 | ||
197 | echo "OBJID HEAD@{0}: initial pull" >reflog.expected && | |
198 | ||
199 | git checkout --orphan kid && | |
200 | test_when_finished "git checkout -f master" && | |
201 | git rm -fr . && | |
202 | test_tick && | |
203 | git merge --ff-only c1 && | |
204 | verify_merge file result.1 && | |
205 | verify_head "$c1" && | |
206 | ||
207 | git reflog -1 >reflog.actual && | |
208 | sed "s/$_x05[0-9a-f][0-9a-f]/OBJID/g" reflog.actual >reflog.fuzzy && | |
209 | test_cmp reflog.expected reflog.fuzzy | |
210 | ' | |
211 | ||
212 | test_debug 'git log --graph --decorate --oneline --all' | |
13474835 | 213 | |
a85d1b69 LH |
214 | test_expect_success 'merge c1 with c2' ' |
215 | git reset --hard c1 && | |
216 | test_tick && | |
217 | git merge c2 && | |
218 | verify_merge file result.1-5 msg.1-5 && | |
219 | verify_parents $c1 $c2 | |
220 | ' | |
221 | ||
df516fb5 | 222 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 LH |
223 | |
224 | test_expect_success 'merge c1 with c2 and c3' ' | |
225 | git reset --hard c1 && | |
226 | test_tick && | |
227 | git merge c2 c3 && | |
228 | verify_merge file result.1-5-9 msg.1-5-9 && | |
229 | verify_parents $c1 $c2 $c3 | |
230 | ' | |
231 | ||
df516fb5 | 232 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 | 233 | |
f23e8dec | 234 | test_expect_success 'merges with --ff-only' ' |
13474835 BG |
235 | git reset --hard c1 && |
236 | test_tick && | |
237 | test_must_fail git merge --ff-only c2 && | |
238 | test_must_fail git merge --ff-only c3 && | |
f23e8dec JH |
239 | test_must_fail git merge --ff-only c2 c3 && |
240 | git reset --hard c0 && | |
241 | git merge c3 && | |
242 | verify_head $c3 | |
243 | ' | |
244 | ||
245 | test_expect_success 'merges with merge.ff=only' ' | |
246 | git reset --hard c1 && | |
247 | test_tick && | |
cee683b7 | 248 | test_config merge.ff "only" && |
f23e8dec JH |
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 | |
13474835 BG |
255 | ' |
256 | ||
a85d1b69 LH |
257 | test_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 | ||
df516fb5 | 264 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 LH |
265 | |
266 | test_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 | ||
df516fb5 | 274 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 LH |
275 | |
276 | test_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 | ||
df516fb5 | 284 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 LH |
285 | |
286 | test_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 && | |
4c073457 | 292 | test_cmp squash.1 .git/SQUASH_MSG |
a85d1b69 LH |
293 | ' |
294 | ||
df516fb5 | 295 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 | 296 | |
13474835 BG |
297 | test_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 && | |
4c073457 | 303 | test_cmp squash.1 .git/SQUASH_MSG |
13474835 BG |
304 | ' |
305 | ||
df516fb5 | 306 | test_debug 'git log --graph --decorate --oneline --all' |
13474835 | 307 | |
a85d1b69 LH |
308 | test_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 && | |
4c073457 | 314 | test_cmp squash.1-5 .git/SQUASH_MSG |
a85d1b69 LH |
315 | ' |
316 | ||
df516fb5 | 317 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 | 318 | |
f7e604ed | 319 | test_expect_success 'unsuccessful merge of c1 with c2 (squash, ff-only)' ' |
13474835 BG |
320 | git reset --hard c1 && |
321 | test_must_fail git merge --squash --ff-only c2 | |
322 | ' | |
323 | ||
df516fb5 | 324 | test_debug 'git log --graph --decorate --oneline --all' |
13474835 | 325 | |
a85d1b69 LH |
326 | test_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 && | |
4c073457 | 332 | test_cmp squash.1-5-9 .git/SQUASH_MSG |
a85d1b69 LH |
333 | ' |
334 | ||
df516fb5 | 335 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 | 336 | |
aec7b362 LH |
337 | test_expect_success 'merge c1 with c2 (no-commit in config)' ' |
338 | git reset --hard c1 && | |
cee683b7 | 339 | test_config branch.master.mergeoptions "--no-commit" && |
aec7b362 LH |
340 | git merge c2 && |
341 | verify_merge file result.1-5 && | |
342 | verify_head $c1 && | |
343 | verify_mergeheads $c2 | |
344 | ' | |
345 | ||
df516fb5 | 346 | test_debug 'git log --graph --decorate --oneline --all' |
aec7b362 | 347 | |
0d8fc3ef | 348 | test_expect_success 'merge c1 with c2 (log in config)' ' |
0d8fc3ef JH |
349 | git reset --hard c1 && |
350 | git merge --log c2 && | |
351 | git show -s --pretty=tformat:%s%n%b >expect && | |
352 | ||
cee683b7 | 353 | test_config branch.master.mergeoptions "--log" && |
0d8fc3ef JH |
354 | git reset --hard c1 && |
355 | git merge c2 && | |
356 | git show -s --pretty=tformat:%s%n%b >actual && | |
357 | ||
358 | test_cmp expect actual | |
359 | ' | |
360 | ||
361 | test_expect_success 'merge c1 with c2 (log in config gets overridden)' ' | |
0d8fc3ef JH |
362 | git reset --hard c1 && |
363 | git merge c2 && | |
364 | git show -s --pretty=tformat:%s%n%b >expect && | |
365 | ||
cee683b7 YD |
366 | test_config branch.master.mergeoptions "--no-log" && |
367 | test_config merge.log "true" && | |
0d8fc3ef JH |
368 | git reset --hard c1 && |
369 | git merge c2 && | |
370 | git show -s --pretty=tformat:%s%n%b >actual && | |
371 | ||
372 | test_cmp expect actual | |
373 | ' | |
374 | ||
aec7b362 LH |
375 | test_expect_success 'merge c1 with c2 (squash in config)' ' |
376 | git reset --hard c1 && | |
cee683b7 | 377 | test_config branch.master.mergeoptions "--squash" && |
aec7b362 LH |
378 | git merge c2 && |
379 | verify_merge file result.1-5 && | |
380 | verify_head $c1 && | |
381 | verify_no_mergehead && | |
4c073457 | 382 | test_cmp squash.1-5 .git/SQUASH_MSG |
aec7b362 LH |
383 | ' |
384 | ||
df516fb5 | 385 | test_debug 'git log --graph --decorate --oneline --all' |
aec7b362 | 386 | |
d8abe148 | 387 | test_expect_success 'override config option -n with --summary' ' |
aec7b362 | 388 | git reset --hard c1 && |
cee683b7 | 389 | test_config branch.master.mergeoptions "-n" && |
aec7b362 LH |
390 | test_tick && |
391 | git merge --summary c2 >diffstat.txt && | |
392 | verify_merge file result.1-5 msg.1-5 && | |
393 | verify_parents $c1 $c2 && | |
aadbe44f | 394 | if ! grep "^ file | *2 +-$" diffstat.txt |
aec7b362 | 395 | then |
d8abe148 SG |
396 | echo "[OOPS] diffstat was not generated with --summary" |
397 | false | |
398 | fi | |
399 | ' | |
400 | ||
401 | test_expect_success 'override config option -n with --stat' ' | |
402 | git reset --hard c1 && | |
cee683b7 | 403 | test_config branch.master.mergeoptions "-n" && |
d8abe148 SG |
404 | test_tick && |
405 | git merge --stat c2 >diffstat.txt && | |
406 | verify_merge file result.1-5 msg.1-5 && | |
407 | verify_parents $c1 $c2 && | |
408 | if ! grep "^ file | *2 +-$" diffstat.txt | |
409 | then | |
410 | echo "[OOPS] diffstat was not generated with --stat" | |
411 | false | |
aec7b362 LH |
412 | fi |
413 | ' | |
414 | ||
df516fb5 | 415 | test_debug 'git log --graph --decorate --oneline --all' |
aec7b362 | 416 | |
d8abe148 | 417 | test_expect_success 'override config option --stat' ' |
aec7b362 | 418 | git reset --hard c1 && |
cee683b7 | 419 | test_config branch.master.mergeoptions "--stat" && |
aec7b362 LH |
420 | test_tick && |
421 | git merge -n c2 >diffstat.txt && | |
422 | verify_merge file result.1-5 msg.1-5 && | |
423 | verify_parents $c1 $c2 && | |
aadbe44f | 424 | if grep "^ file | *2 +-$" diffstat.txt |
aec7b362 LH |
425 | then |
426 | echo "[OOPS] diffstat was generated" | |
427 | false | |
428 | fi | |
429 | ' | |
430 | ||
df516fb5 | 431 | test_debug 'git log --graph --decorate --oneline --all' |
aec7b362 | 432 | |
d08af0ad LH |
433 | test_expect_success 'merge c1 with c2 (override --no-commit)' ' |
434 | git reset --hard c1 && | |
cee683b7 | 435 | test_config branch.master.mergeoptions "--no-commit" && |
d08af0ad LH |
436 | test_tick && |
437 | git merge --commit c2 && | |
438 | verify_merge file result.1-5 msg.1-5 && | |
439 | verify_parents $c1 $c2 | |
440 | ' | |
441 | ||
df516fb5 | 442 | test_debug 'git log --graph --decorate --oneline --all' |
d08af0ad LH |
443 | |
444 | test_expect_success 'merge c1 with c2 (override --squash)' ' | |
445 | git reset --hard c1 && | |
cee683b7 | 446 | test_config branch.master.mergeoptions "--squash" && |
d08af0ad LH |
447 | test_tick && |
448 | git merge --no-squash c2 && | |
449 | verify_merge file result.1-5 msg.1-5 && | |
450 | verify_parents $c1 $c2 | |
451 | ' | |
452 | ||
df516fb5 | 453 | test_debug 'git log --graph --decorate --oneline --all' |
d08af0ad | 454 | |
d66424c4 LH |
455 | test_expect_success 'merge c0 with c1 (no-ff)' ' |
456 | git reset --hard c0 && | |
457 | test_tick && | |
458 | git merge --no-ff c1 && | |
459 | verify_merge file result.1 && | |
460 | verify_parents $c0 $c1 | |
461 | ' | |
462 | ||
df516fb5 | 463 | test_debug 'git log --graph --decorate --oneline --all' |
d66424c4 | 464 | |
f23e8dec JH |
465 | test_expect_success 'merge c0 with c1 (merge.ff=false)' ' |
466 | git reset --hard c0 && | |
cee683b7 | 467 | test_config merge.ff "false" && |
f23e8dec JH |
468 | test_tick && |
469 | git merge c1 && | |
f23e8dec JH |
470 | verify_merge file result.1 && |
471 | verify_parents $c0 $c1 | |
472 | ' | |
473 | test_debug 'git log --graph --decorate --oneline --all' | |
474 | ||
475 | test_expect_success 'combine branch.master.mergeoptions with merge.ff' ' | |
476 | git reset --hard c0 && | |
cee683b7 YD |
477 | test_config branch.master.mergeoptions "--ff" && |
478 | test_config merge.ff "false" && | |
f23e8dec JH |
479 | test_tick && |
480 | git merge c1 && | |
f23e8dec JH |
481 | verify_merge file result.1 && |
482 | verify_parents "$c0" | |
483 | ' | |
484 | ||
8c5cea00 JN |
485 | test_expect_success 'tolerate unknown values for merge.ff' ' |
486 | git reset --hard c0 && | |
cee683b7 | 487 | test_config merge.ff "something-new" && |
8c5cea00 JN |
488 | test_tick && |
489 | git merge c1 2>message && | |
8c5cea00 JN |
490 | verify_head "$c1" && |
491 | test_cmp empty message | |
492 | ' | |
493 | ||
e6d1f76c | 494 | test_expect_success 'combining --squash and --no-ff is refused' ' |
8c5cea00 | 495 | git reset --hard c0 && |
e6d1f76c GP |
496 | test_must_fail git merge --squash --no-ff c1 && |
497 | test_must_fail git merge --no-ff --squash c1 | |
498 | ' | |
499 | ||
a54841e9 MV |
500 | test_expect_success 'option --ff-only overwrites --no-ff' ' |
501 | git merge --no-ff --ff-only c1 && | |
502 | test_must_fail git merge --no-ff --ff-only c2 | |
503 | ' | |
504 | ||
6d2d43dc | 505 | test_expect_success 'option --no-ff overrides merge.ff=only config' ' |
a54841e9 MV |
506 | git reset --hard c0 && |
507 | test_config merge.ff only && | |
508 | git merge --no-ff c1 | |
13474835 BG |
509 | ' |
510 | ||
d66424c4 LH |
511 | test_expect_success 'merge c0 with c1 (ff overrides no-ff)' ' |
512 | git reset --hard c0 && | |
cee683b7 | 513 | test_config branch.master.mergeoptions "--no-ff" && |
d66424c4 LH |
514 | git merge --ff c1 && |
515 | verify_merge file result.1 && | |
516 | verify_head $c1 | |
517 | ' | |
518 | ||
efb779f8 SG |
519 | test_expect_success 'merge log message' ' |
520 | git reset --hard c0 && | |
521 | git merge --no-log c2 && | |
522 | git show -s --pretty=format:%b HEAD >msg.act && | |
cee683b7 YD |
523 | test_cmp msg.nologff msg.act && |
524 | ||
525 | git reset --hard c0 && | |
526 | test_config branch.master.mergeoptions "--no-ff" && | |
527 | git merge --no-log c2 && | |
528 | git show -s --pretty=format:%b HEAD >msg.act && | |
529 | test_cmp msg.nolognoff msg.act && | |
4393c237 | 530 | |
efb779f8 SG |
531 | git merge --log c3 && |
532 | git show -s --pretty=format:%b HEAD >msg.act && | |
4c073457 | 533 | test_cmp msg.log msg.act && |
4393c237 JH |
534 | |
535 | git reset --hard HEAD^ && | |
cee683b7 | 536 | test_config merge.log "yes" && |
4393c237 JH |
537 | git merge c3 && |
538 | git show -s --pretty=format:%b HEAD >msg.act && | |
4c073457 | 539 | test_cmp msg.log msg.act |
efb779f8 SG |
540 | ' |
541 | ||
df516fb5 | 542 | test_debug 'git log --graph --decorate --oneline --all' |
d66424c4 | 543 | |
3d1dd472 SHJ |
544 | test_expect_success 'merge c1 with c0, c2, c0, and c1' ' |
545 | git reset --hard c1 && | |
3d1dd472 SHJ |
546 | test_tick && |
547 | git merge c0 c2 c0 c1 && | |
548 | verify_merge file result.1-5 && | |
549 | verify_parents $c1 $c2 | |
550 | ' | |
551 | ||
df516fb5 | 552 | test_debug 'git log --graph --decorate --oneline --all' |
3d1dd472 | 553 | |
711f6b29 JH |
554 | test_expect_success 'merge c1 with c0, c2, c0, and c1' ' |
555 | git reset --hard c1 && | |
711f6b29 JH |
556 | test_tick && |
557 | git merge c0 c2 c0 c1 && | |
558 | verify_merge file result.1-5 && | |
559 | verify_parents $c1 $c2 | |
560 | ' | |
561 | ||
df516fb5 | 562 | test_debug 'git log --graph --decorate --oneline --all' |
711f6b29 JH |
563 | |
564 | test_expect_success 'merge c1 with c1 and c2' ' | |
565 | git reset --hard c1 && | |
711f6b29 JH |
566 | test_tick && |
567 | git merge c1 c2 && | |
568 | verify_merge file result.1-5 && | |
569 | verify_parents $c1 $c2 | |
570 | ' | |
571 | ||
df516fb5 | 572 | test_debug 'git log --graph --decorate --oneline --all' |
711f6b29 | 573 | |
9ca8f607 JH |
574 | test_expect_success 'merge fast-forward in a dirty tree' ' |
575 | git reset --hard c0 && | |
576 | mv file file1 && | |
577 | cat file1 >file && | |
578 | rm -f file1 && | |
579 | git merge c2 | |
580 | ' | |
581 | ||
df516fb5 | 582 | test_debug 'git log --graph --decorate --oneline --all' |
9ca8f607 | 583 | |
c9ea118e | 584 | test_expect_success 'in-index merge' ' |
446247db | 585 | git reset --hard c0 && |
4c073457 | 586 | git merge --no-ff -s resolve c1 >out && |
c9ea118e | 587 | test_i18ngrep "Wonderful." out && |
446247db JH |
588 | verify_parents $c0 $c1 |
589 | ' | |
590 | ||
df516fb5 | 591 | test_debug 'git log --graph --decorate --oneline --all' |
446247db | 592 | |
668f26ff MV |
593 | test_expect_success 'refresh the index before merging' ' |
594 | git reset --hard c1 && | |
016e5ff2 | 595 | cp file file.n && mv -f file.n file && |
668f26ff MV |
596 | git merge c3 |
597 | ' | |
598 | ||
b81f925f JN |
599 | cat >expected.branch <<\EOF |
600 | Merge branch 'c5-branch' (early part) | |
601 | EOF | |
602 | cat >expected.tag <<\EOF | |
603 | Merge commit 'c5~1' | |
4e6d4bc0 MV |
604 | EOF |
605 | ||
606 | test_expect_success 'merge early part of c2' ' | |
607 | git reset --hard c3 && | |
4c073457 | 608 | echo c4 >c4.c && |
4e6d4bc0 MV |
609 | git add c4.c && |
610 | git commit -m c4 && | |
611 | git tag c4 && | |
4c073457 | 612 | echo c5 >c5.c && |
4e6d4bc0 MV |
613 | git add c5.c && |
614 | git commit -m c5 && | |
615 | git tag c5 && | |
616 | git reset --hard c3 && | |
4c073457 | 617 | echo c6 >c6.c && |
4e6d4bc0 MV |
618 | git add c6.c && |
619 | git commit -m c6 && | |
620 | git tag c6 && | |
b81f925f JN |
621 | git branch -f c5-branch c5 && |
622 | git merge c5-branch~1 && | |
623 | git show -s --pretty=format:%s HEAD >actual.branch && | |
624 | git reset --keep HEAD^ && | |
4e6d4bc0 | 625 | git merge c5~1 && |
b81f925f JN |
626 | git show -s --pretty=format:%s HEAD >actual.tag && |
627 | test_cmp expected.branch actual.branch && | |
628 | test_cmp expected.tag actual.tag | |
4e6d4bc0 MV |
629 | ' |
630 | ||
df516fb5 | 631 | test_debug 'git log --graph --decorate --oneline --all' |
668f26ff | 632 | |
cf10f9fd MV |
633 | test_expect_success 'merge --no-ff --no-commit && commit' ' |
634 | git reset --hard c0 && | |
635 | git merge --no-ff --no-commit c1 && | |
636 | EDITOR=: git commit && | |
637 | verify_parents $c0 $c1 | |
638 | ' | |
639 | ||
df516fb5 | 640 | test_debug 'git log --graph --decorate --oneline --all' |
cf10f9fd MV |
641 | |
642 | test_expect_success 'amending no-ff merge commit' ' | |
643 | EDITOR=: git commit --amend && | |
644 | verify_parents $c0 $c1 | |
645 | ' | |
646 | ||
df516fb5 | 647 | test_debug 'git log --graph --decorate --oneline --all' |
cf10f9fd | 648 | |
66f4b98a JS |
649 | cat >editor <<\EOF |
650 | #!/bin/sh | |
651 | # Add a new message string that was not in the template | |
652 | ( | |
653 | echo "Merge work done on the side branch c1" | |
654 | echo | |
655 | cat <"$1" | |
656 | ) >"$1.tmp" && mv "$1.tmp" "$1" | |
657 | # strip comments and blank lines from end of message | |
658 | sed -e '/^#/d' < "$1" | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' > expected | |
659 | EOF | |
660 | chmod 755 editor | |
661 | ||
662 | test_expect_success 'merge --no-ff --edit' ' | |
663 | git reset --hard c0 && | |
664 | EDITOR=./editor git merge --no-ff --edit c1 && | |
665 | verify_parents $c0 $c1 && | |
666 | git cat-file commit HEAD >raw && | |
667 | grep "work done on the side branch" raw && | |
668 | sed "1,/^$/d" >actual raw && | |
669 | test_cmp actual expected | |
670 | ' | |
671 | ||
b5c9f1c1 JH |
672 | test_expect_success GPG 'merge --ff-only tag' ' |
673 | git reset --hard c0 && | |
674 | git commit --allow-empty -m "A newer commit" && | |
675 | git tag -s -m "A newer commit" signed && | |
676 | git reset --hard c0 && | |
677 | ||
678 | git merge --ff-only signed && | |
679 | git rev-parse signed^0 >expect && | |
680 | git rev-parse HEAD >actual && | |
681 | test_cmp actual expect | |
682 | ' | |
683 | ||
3adab6f3 JH |
684 | test_expect_success GPG 'merge --no-edit tag should skip editor' ' |
685 | git reset --hard c0 && | |
686 | git commit --allow-empty -m "A newer commit" && | |
687 | git tag -f -s -m "A newer commit" signed && | |
688 | git reset --hard c0 && | |
689 | ||
690 | EDITOR=false git merge --no-edit signed && | |
691 | git rev-parse signed^0 >expect && | |
692 | git rev-parse HEAD^2 >actual && | |
693 | test_cmp actual expect | |
694 | ' | |
695 | ||
a85d1b69 | 696 | test_done |