]>
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 | |
b64c1e07 | 36 | printf '%s\n' 1 2 3 4 5 6 7 8 '9 Y' >file.9y |
73151df0 JN |
37 | printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >result.1 |
38 | printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 9 >result.1-5 | |
39 | printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 '9 X' >result.1-5-9 | |
b64c1e07 | 40 | printf '%s\n' 1 2 3 4 5 6 7 8 '9 Z' >result.9z |
36a45b4f | 41 | >empty |
4c073457 | 42 | |
73151df0 | 43 | create_merge_msgs () { |
57b58db7 JH |
44 | echo "Merge tag 'c2'" >msg.1-5 && |
45 | echo "Merge tags 'c2' and 'c3'" >msg.1-5-9 && | |
73151df0 JN |
46 | { |
47 | echo "Squashed commit of the following:" && | |
48 | echo && | |
49 | git log --no-merges ^HEAD c1 | |
50 | } >squash.1 && | |
51 | { | |
52 | echo "Squashed commit of the following:" && | |
53 | echo && | |
54 | git log --no-merges ^HEAD c2 | |
55 | } >squash.1-5 && | |
56 | { | |
57 | echo "Squashed commit of the following:" && | |
58 | echo && | |
59 | git log --no-merges ^HEAD c2 c3 | |
60 | } >squash.1-5-9 && | |
cee683b7 | 61 | : >msg.nologff && |
ad2f7255 | 62 | : >msg.nolognoff && |
73151df0 | 63 | { |
57b58db7 | 64 | echo "* tag 'c3':" && |
ad2f7255 | 65 | echo " commit 3" |
73151df0 JN |
66 | } >msg.log |
67 | } | |
4c073457 | 68 | |
73151df0 JN |
69 | verify_merge () { |
70 | test_cmp "$2" "$1" && | |
71 | git update-index --refresh && | |
72 | git diff --exit-code && | |
73 | if test -n "$3" | |
74 | then | |
ad2f7255 | 75 | git show -s --pretty=tformat:%s HEAD >msg.act && |
73151df0 JN |
76 | test_cmp "$3" msg.act |
77 | fi | |
78 | } | |
4c073457 | 79 | |
73151df0 JN |
80 | verify_head () { |
81 | echo "$1" >head.expected && | |
82 | git rev-parse HEAD >head.actual && | |
83 | test_cmp head.expected head.actual | |
84 | } | |
4c073457 | 85 | |
73151df0 JN |
86 | verify_parents () { |
87 | printf '%s\n' "$@" >parents.expected && | |
88 | >parents.actual && | |
89 | i=1 && | |
90 | while test $i -le $# | |
91 | do | |
92 | git rev-parse HEAD^$i >>parents.actual && | |
93 | i=$(expr $i + 1) || | |
94 | return 1 | |
95 | done && | |
3fc0dbf0 | 96 | test_must_fail git rev-parse --verify "HEAD^$i" && |
73151df0 JN |
97 | test_cmp parents.expected parents.actual |
98 | } | |
a85d1b69 | 99 | |
73151df0 JN |
100 | verify_mergeheads () { |
101 | printf '%s\n' "$@" >mergehead.expected && | |
274a5c06 JH |
102 | while read sha1 rest |
103 | do | |
104 | git rev-parse $sha1 | |
105 | done <.git/MERGE_HEAD >mergehead.actual && | |
106 | test_cmp mergehead.expected mergehead.actual | |
73151df0 | 107 | } |
a85d1b69 | 108 | |
73151df0 JN |
109 | verify_no_mergehead () { |
110 | ! test -e .git/MERGE_HEAD | |
111 | } | |
a85d1b69 LH |
112 | |
113 | test_expect_success 'setup' ' | |
114 | git add file && | |
115 | test_tick && | |
116 | git commit -m "commit 0" && | |
117 | git tag c0 && | |
118 | c0=$(git rev-parse HEAD) && | |
119 | cp file.1 file && | |
120 | git add file && | |
121 | test_tick && | |
122 | git commit -m "commit 1" && | |
123 | git tag c1 && | |
124 | c1=$(git rev-parse HEAD) && | |
125 | git reset --hard "$c0" && | |
126 | cp file.5 file && | |
127 | git add file && | |
128 | test_tick && | |
129 | git commit -m "commit 2" && | |
130 | git tag c2 && | |
131 | c2=$(git rev-parse HEAD) && | |
132 | git reset --hard "$c0" && | |
b64c1e07 SS |
133 | cp file.9y file && |
134 | git add file && | |
135 | test_tick && | |
136 | git commit -m "commit 7" && | |
137 | git tag c7 && | |
138 | git reset --hard "$c0" && | |
a85d1b69 LH |
139 | cp file.9 file && |
140 | git add file && | |
141 | test_tick && | |
142 | git commit -m "commit 3" && | |
143 | git tag c3 && | |
99094a7a | 144 | c3=$(git rev-parse HEAD) && |
a85d1b69 LH |
145 | git reset --hard "$c0" && |
146 | create_merge_msgs | |
147 | ' | |
148 | ||
df516fb5 | 149 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 | 150 | |
74f5b7fb | 151 | test_expect_success 'test option parsing' ' |
01941bd5 JS |
152 | test_must_fail git merge -$ c1 && |
153 | test_must_fail git merge --no-such c1 && | |
154 | test_must_fail git merge -s foobar c1 && | |
155 | test_must_fail git merge -s=foobar c1 && | |
156 | test_must_fail git merge -m && | |
042e290d CP |
157 | test_must_fail git merge --abort foobar && |
158 | test_must_fail git merge --abort --quiet && | |
367ff694 CP |
159 | test_must_fail git merge --continue foobar && |
160 | test_must_fail git merge --continue --quiet && | |
01941bd5 | 161 | test_must_fail git merge |
a85d1b69 LH |
162 | ' |
163 | ||
da53eec6 NTND |
164 | test_expect_success 'merge -h with invalid index' ' |
165 | mkdir broken && | |
166 | ( | |
167 | cd broken && | |
168 | git init && | |
169 | >.git/index && | |
170 | test_expect_code 129 git merge -h 2>usage | |
171 | ) && | |
9a001381 | 172 | test_i18ngrep "[Uu]sage: git merge" broken/usage |
da53eec6 NTND |
173 | ' |
174 | ||
dce61e72 MV |
175 | test_expect_success 'reject non-strategy with a git-merge-foo name' ' |
176 | test_must_fail git merge -s index c1 | |
177 | ' | |
178 | ||
a85d1b69 | 179 | test_expect_success 'merge c0 with c1' ' |
ff372c78 JN |
180 | echo "OBJID HEAD@{0}: merge c1: Fast-forward" >reflog.expected && |
181 | ||
a85d1b69 LH |
182 | git reset --hard c0 && |
183 | git merge c1 && | |
184 | verify_merge file result.1 && | |
ff372c78 JN |
185 | verify_head "$c1" && |
186 | ||
187 | git reflog -1 >reflog.actual && | |
188 | sed "s/$_x05[0-9a-f]*/OBJID/g" reflog.actual >reflog.fuzzy && | |
189 | test_cmp reflog.expected reflog.fuzzy | |
a85d1b69 LH |
190 | ' |
191 | ||
df516fb5 | 192 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 | 193 | |
13474835 BG |
194 | test_expect_success 'merge c0 with c1 with --ff-only' ' |
195 | git reset --hard c0 && | |
196 | git merge --ff-only c1 && | |
197 | git merge --ff-only HEAD c0 c1 && | |
198 | verify_merge file result.1 && | |
199 | verify_head "$c1" | |
200 | ' | |
201 | ||
df516fb5 | 202 | test_debug 'git log --graph --decorate --oneline --all' |
94d63ce2 JN |
203 | |
204 | test_expect_success 'merge from unborn branch' ' | |
205 | git checkout -f master && | |
206 | test_might_fail git branch -D kid && | |
207 | ||
208 | echo "OBJID HEAD@{0}: initial pull" >reflog.expected && | |
209 | ||
210 | git checkout --orphan kid && | |
211 | test_when_finished "git checkout -f master" && | |
212 | git rm -fr . && | |
213 | test_tick && | |
214 | git merge --ff-only c1 && | |
215 | verify_merge file result.1 && | |
216 | verify_head "$c1" && | |
217 | ||
218 | git reflog -1 >reflog.actual && | |
219 | sed "s/$_x05[0-9a-f][0-9a-f]/OBJID/g" reflog.actual >reflog.fuzzy && | |
220 | test_cmp reflog.expected reflog.fuzzy | |
221 | ' | |
222 | ||
223 | test_debug 'git log --graph --decorate --oneline --all' | |
13474835 | 224 | |
a85d1b69 LH |
225 | test_expect_success 'merge c1 with c2' ' |
226 | git reset --hard c1 && | |
227 | test_tick && | |
228 | git merge c2 && | |
229 | verify_merge file result.1-5 msg.1-5 && | |
230 | verify_parents $c1 $c2 | |
231 | ' | |
232 | ||
b64c1e07 SS |
233 | test_expect_success 'merge --squash c3 with c7' ' |
234 | git reset --hard c3 && | |
235 | test_must_fail git merge --squash c7 && | |
236 | cat result.9z >file && | |
237 | git commit --no-edit -a && | |
238 | ||
239 | { | |
240 | cat <<-EOF | |
241 | Squashed commit of the following: | |
242 | ||
243 | $(git show -s c7) | |
244 | ||
245 | # Conflicts: | |
246 | # file | |
247 | EOF | |
248 | } >expect && | |
249 | git cat-file commit HEAD | sed -e '1,/^$/d' >actual && | |
250 | test_cmp expect actual | |
251 | ' | |
252 | ||
df516fb5 | 253 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 LH |
254 | |
255 | test_expect_success 'merge c1 with c2 and c3' ' | |
256 | git reset --hard c1 && | |
257 | test_tick && | |
258 | git merge c2 c3 && | |
259 | verify_merge file result.1-5-9 msg.1-5-9 && | |
260 | verify_parents $c1 $c2 $c3 | |
261 | ' | |
262 | ||
df516fb5 | 263 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 | 264 | |
f23e8dec | 265 | test_expect_success 'merges with --ff-only' ' |
13474835 BG |
266 | git reset --hard c1 && |
267 | test_tick && | |
268 | test_must_fail git merge --ff-only c2 && | |
269 | test_must_fail git merge --ff-only c3 && | |
f23e8dec JH |
270 | test_must_fail git merge --ff-only c2 c3 && |
271 | git reset --hard c0 && | |
272 | git merge c3 && | |
273 | verify_head $c3 | |
274 | ' | |
275 | ||
276 | test_expect_success 'merges with merge.ff=only' ' | |
277 | git reset --hard c1 && | |
278 | test_tick && | |
cee683b7 | 279 | test_config merge.ff "only" && |
f23e8dec JH |
280 | test_must_fail git merge c2 && |
281 | test_must_fail git merge c3 && | |
282 | test_must_fail git merge c2 c3 && | |
283 | git reset --hard c0 && | |
284 | git merge c3 && | |
285 | verify_head $c3 | |
13474835 BG |
286 | ' |
287 | ||
a85d1b69 LH |
288 | test_expect_success 'merge c0 with c1 (no-commit)' ' |
289 | git reset --hard c0 && | |
290 | git merge --no-commit c1 && | |
291 | verify_merge file result.1 && | |
292 | verify_head $c1 | |
293 | ' | |
294 | ||
df516fb5 | 295 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 LH |
296 | |
297 | test_expect_success 'merge c1 with c2 (no-commit)' ' | |
298 | git reset --hard c1 && | |
299 | git merge --no-commit c2 && | |
300 | verify_merge file result.1-5 && | |
301 | verify_head $c1 && | |
302 | verify_mergeheads $c2 | |
303 | ' | |
304 | ||
df516fb5 | 305 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 LH |
306 | |
307 | test_expect_success 'merge c1 with c2 and c3 (no-commit)' ' | |
308 | git reset --hard c1 && | |
309 | git merge --no-commit c2 c3 && | |
310 | verify_merge file result.1-5-9 && | |
311 | verify_head $c1 && | |
312 | verify_mergeheads $c2 $c3 | |
313 | ' | |
314 | ||
df516fb5 | 315 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 LH |
316 | |
317 | test_expect_success 'merge c0 with c1 (squash)' ' | |
318 | git reset --hard c0 && | |
319 | git merge --squash c1 && | |
320 | verify_merge file result.1 && | |
321 | verify_head $c0 && | |
322 | verify_no_mergehead && | |
4c073457 | 323 | test_cmp squash.1 .git/SQUASH_MSG |
a85d1b69 LH |
324 | ' |
325 | ||
df516fb5 | 326 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 | 327 | |
13474835 BG |
328 | test_expect_success 'merge c0 with c1 (squash, ff-only)' ' |
329 | git reset --hard c0 && | |
330 | git merge --squash --ff-only c1 && | |
331 | verify_merge file result.1 && | |
332 | verify_head $c0 && | |
333 | verify_no_mergehead && | |
4c073457 | 334 | test_cmp squash.1 .git/SQUASH_MSG |
13474835 BG |
335 | ' |
336 | ||
df516fb5 | 337 | test_debug 'git log --graph --decorate --oneline --all' |
13474835 | 338 | |
a85d1b69 LH |
339 | test_expect_success 'merge c1 with c2 (squash)' ' |
340 | git reset --hard c1 && | |
341 | git merge --squash c2 && | |
342 | verify_merge file result.1-5 && | |
343 | verify_head $c1 && | |
344 | verify_no_mergehead && | |
4c073457 | 345 | test_cmp squash.1-5 .git/SQUASH_MSG |
a85d1b69 LH |
346 | ' |
347 | ||
df516fb5 | 348 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 | 349 | |
f7e604ed | 350 | test_expect_success 'unsuccessful merge of c1 with c2 (squash, ff-only)' ' |
13474835 BG |
351 | git reset --hard c1 && |
352 | test_must_fail git merge --squash --ff-only c2 | |
353 | ' | |
354 | ||
df516fb5 | 355 | test_debug 'git log --graph --decorate --oneline --all' |
13474835 | 356 | |
a85d1b69 LH |
357 | test_expect_success 'merge c1 with c2 and c3 (squash)' ' |
358 | git reset --hard c1 && | |
359 | git merge --squash c2 c3 && | |
360 | verify_merge file result.1-5-9 && | |
361 | verify_head $c1 && | |
362 | verify_no_mergehead && | |
4c073457 | 363 | test_cmp squash.1-5-9 .git/SQUASH_MSG |
a85d1b69 LH |
364 | ' |
365 | ||
df516fb5 | 366 | test_debug 'git log --graph --decorate --oneline --all' |
a85d1b69 | 367 | |
aec7b362 LH |
368 | test_expect_success 'merge c1 with c2 (no-commit in config)' ' |
369 | git reset --hard c1 && | |
cee683b7 | 370 | test_config branch.master.mergeoptions "--no-commit" && |
aec7b362 LH |
371 | git merge c2 && |
372 | verify_merge file result.1-5 && | |
373 | verify_head $c1 && | |
374 | verify_mergeheads $c2 | |
375 | ' | |
376 | ||
df516fb5 | 377 | test_debug 'git log --graph --decorate --oneline --all' |
aec7b362 | 378 | |
0d8fc3ef | 379 | test_expect_success 'merge c1 with c2 (log in config)' ' |
0d8fc3ef JH |
380 | git reset --hard c1 && |
381 | git merge --log c2 && | |
382 | git show -s --pretty=tformat:%s%n%b >expect && | |
383 | ||
cee683b7 | 384 | test_config branch.master.mergeoptions "--log" && |
0d8fc3ef JH |
385 | git reset --hard c1 && |
386 | git merge c2 && | |
387 | git show -s --pretty=tformat:%s%n%b >actual && | |
388 | ||
389 | test_cmp expect actual | |
390 | ' | |
391 | ||
392 | test_expect_success 'merge c1 with c2 (log in config gets overridden)' ' | |
0d8fc3ef JH |
393 | git reset --hard c1 && |
394 | git merge c2 && | |
395 | git show -s --pretty=tformat:%s%n%b >expect && | |
396 | ||
cee683b7 YD |
397 | test_config branch.master.mergeoptions "--no-log" && |
398 | test_config merge.log "true" && | |
0d8fc3ef JH |
399 | git reset --hard c1 && |
400 | git merge c2 && | |
401 | git show -s --pretty=tformat:%s%n%b >actual && | |
402 | ||
403 | test_cmp expect actual | |
404 | ' | |
405 | ||
aec7b362 LH |
406 | test_expect_success 'merge c1 with c2 (squash in config)' ' |
407 | git reset --hard c1 && | |
cee683b7 | 408 | test_config branch.master.mergeoptions "--squash" && |
aec7b362 LH |
409 | git merge c2 && |
410 | verify_merge file result.1-5 && | |
411 | verify_head $c1 && | |
412 | verify_no_mergehead && | |
4c073457 | 413 | test_cmp squash.1-5 .git/SQUASH_MSG |
aec7b362 LH |
414 | ' |
415 | ||
df516fb5 | 416 | test_debug 'git log --graph --decorate --oneline --all' |
aec7b362 | 417 | |
d8abe148 | 418 | test_expect_success 'override config option -n with --summary' ' |
aec7b362 | 419 | git reset --hard c1 && |
cee683b7 | 420 | test_config branch.master.mergeoptions "-n" && |
aec7b362 LH |
421 | test_tick && |
422 | git merge --summary c2 >diffstat.txt && | |
423 | verify_merge file result.1-5 msg.1-5 && | |
424 | verify_parents $c1 $c2 && | |
aadbe44f | 425 | if ! grep "^ file | *2 +-$" diffstat.txt |
aec7b362 | 426 | then |
d8abe148 SG |
427 | echo "[OOPS] diffstat was not generated with --summary" |
428 | false | |
429 | fi | |
430 | ' | |
431 | ||
432 | test_expect_success 'override config option -n with --stat' ' | |
433 | git reset --hard c1 && | |
cee683b7 | 434 | test_config branch.master.mergeoptions "-n" && |
d8abe148 SG |
435 | test_tick && |
436 | git merge --stat c2 >diffstat.txt && | |
437 | verify_merge file result.1-5 msg.1-5 && | |
438 | verify_parents $c1 $c2 && | |
439 | if ! grep "^ file | *2 +-$" diffstat.txt | |
440 | then | |
441 | echo "[OOPS] diffstat was not generated with --stat" | |
442 | false | |
aec7b362 LH |
443 | fi |
444 | ' | |
445 | ||
df516fb5 | 446 | test_debug 'git log --graph --decorate --oneline --all' |
aec7b362 | 447 | |
d8abe148 | 448 | test_expect_success 'override config option --stat' ' |
aec7b362 | 449 | git reset --hard c1 && |
cee683b7 | 450 | test_config branch.master.mergeoptions "--stat" && |
aec7b362 LH |
451 | test_tick && |
452 | git merge -n c2 >diffstat.txt && | |
453 | verify_merge file result.1-5 msg.1-5 && | |
454 | verify_parents $c1 $c2 && | |
aadbe44f | 455 | if grep "^ file | *2 +-$" diffstat.txt |
aec7b362 LH |
456 | then |
457 | echo "[OOPS] diffstat was generated" | |
458 | false | |
459 | fi | |
460 | ' | |
461 | ||
df516fb5 | 462 | test_debug 'git log --graph --decorate --oneline --all' |
aec7b362 | 463 | |
d08af0ad LH |
464 | test_expect_success 'merge c1 with c2 (override --no-commit)' ' |
465 | git reset --hard c1 && | |
cee683b7 | 466 | test_config branch.master.mergeoptions "--no-commit" && |
d08af0ad LH |
467 | test_tick && |
468 | git merge --commit c2 && | |
469 | verify_merge file result.1-5 msg.1-5 && | |
470 | verify_parents $c1 $c2 | |
471 | ' | |
472 | ||
df516fb5 | 473 | test_debug 'git log --graph --decorate --oneline --all' |
d08af0ad LH |
474 | |
475 | test_expect_success 'merge c1 with c2 (override --squash)' ' | |
476 | git reset --hard c1 && | |
cee683b7 | 477 | test_config branch.master.mergeoptions "--squash" && |
d08af0ad LH |
478 | test_tick && |
479 | git merge --no-squash c2 && | |
480 | verify_merge file result.1-5 msg.1-5 && | |
481 | verify_parents $c1 $c2 | |
482 | ' | |
483 | ||
df516fb5 | 484 | test_debug 'git log --graph --decorate --oneline --all' |
d08af0ad | 485 | |
d66424c4 LH |
486 | test_expect_success 'merge c0 with c1 (no-ff)' ' |
487 | git reset --hard c0 && | |
488 | test_tick && | |
489 | git merge --no-ff c1 && | |
490 | verify_merge file result.1 && | |
491 | verify_parents $c0 $c1 | |
492 | ' | |
493 | ||
df516fb5 | 494 | test_debug 'git log --graph --decorate --oneline --all' |
d66424c4 | 495 | |
f23e8dec JH |
496 | test_expect_success 'merge c0 with c1 (merge.ff=false)' ' |
497 | git reset --hard c0 && | |
cee683b7 | 498 | test_config merge.ff "false" && |
f23e8dec JH |
499 | test_tick && |
500 | git merge c1 && | |
f23e8dec JH |
501 | verify_merge file result.1 && |
502 | verify_parents $c0 $c1 | |
503 | ' | |
504 | test_debug 'git log --graph --decorate --oneline --all' | |
505 | ||
506 | test_expect_success 'combine branch.master.mergeoptions with merge.ff' ' | |
507 | git reset --hard c0 && | |
cee683b7 YD |
508 | test_config branch.master.mergeoptions "--ff" && |
509 | test_config merge.ff "false" && | |
f23e8dec JH |
510 | test_tick && |
511 | git merge c1 && | |
f23e8dec JH |
512 | verify_merge file result.1 && |
513 | verify_parents "$c0" | |
514 | ' | |
515 | ||
8c5cea00 JN |
516 | test_expect_success 'tolerate unknown values for merge.ff' ' |
517 | git reset --hard c0 && | |
cee683b7 | 518 | test_config merge.ff "something-new" && |
8c5cea00 JN |
519 | test_tick && |
520 | git merge c1 2>message && | |
8c5cea00 JN |
521 | verify_head "$c1" && |
522 | test_cmp empty message | |
523 | ' | |
524 | ||
e6d1f76c | 525 | test_expect_success 'combining --squash and --no-ff is refused' ' |
8c5cea00 | 526 | git reset --hard c0 && |
e6d1f76c GP |
527 | test_must_fail git merge --squash --no-ff c1 && |
528 | test_must_fail git merge --no-ff --squash c1 | |
529 | ' | |
530 | ||
a54841e9 MV |
531 | test_expect_success 'option --ff-only overwrites --no-ff' ' |
532 | git merge --no-ff --ff-only c1 && | |
533 | test_must_fail git merge --no-ff --ff-only c2 | |
534 | ' | |
535 | ||
6d2d43dc | 536 | test_expect_success 'option --no-ff overrides merge.ff=only config' ' |
a54841e9 MV |
537 | git reset --hard c0 && |
538 | test_config merge.ff only && | |
539 | git merge --no-ff c1 | |
13474835 BG |
540 | ' |
541 | ||
d66424c4 LH |
542 | test_expect_success 'merge c0 with c1 (ff overrides no-ff)' ' |
543 | git reset --hard c0 && | |
cee683b7 | 544 | test_config branch.master.mergeoptions "--no-ff" && |
d66424c4 LH |
545 | git merge --ff c1 && |
546 | verify_merge file result.1 && | |
547 | verify_head $c1 | |
548 | ' | |
549 | ||
efb779f8 SG |
550 | test_expect_success 'merge log message' ' |
551 | git reset --hard c0 && | |
552 | git merge --no-log c2 && | |
553 | git show -s --pretty=format:%b HEAD >msg.act && | |
cee683b7 YD |
554 | test_cmp msg.nologff msg.act && |
555 | ||
556 | git reset --hard c0 && | |
557 | test_config branch.master.mergeoptions "--no-ff" && | |
558 | git merge --no-log c2 && | |
559 | git show -s --pretty=format:%b HEAD >msg.act && | |
560 | test_cmp msg.nolognoff msg.act && | |
4393c237 | 561 | |
efb779f8 SG |
562 | git merge --log c3 && |
563 | git show -s --pretty=format:%b HEAD >msg.act && | |
4c073457 | 564 | test_cmp msg.log msg.act && |
4393c237 JH |
565 | |
566 | git reset --hard HEAD^ && | |
cee683b7 | 567 | test_config merge.log "yes" && |
4393c237 JH |
568 | git merge c3 && |
569 | git show -s --pretty=format:%b HEAD >msg.act && | |
4c073457 | 570 | test_cmp msg.log msg.act |
efb779f8 SG |
571 | ' |
572 | ||
df516fb5 | 573 | test_debug 'git log --graph --decorate --oneline --all' |
d66424c4 | 574 | |
3d1dd472 SHJ |
575 | test_expect_success 'merge c1 with c0, c2, c0, and c1' ' |
576 | git reset --hard c1 && | |
3d1dd472 SHJ |
577 | test_tick && |
578 | git merge c0 c2 c0 c1 && | |
579 | verify_merge file result.1-5 && | |
580 | verify_parents $c1 $c2 | |
581 | ' | |
582 | ||
df516fb5 | 583 | test_debug 'git log --graph --decorate --oneline --all' |
3d1dd472 | 584 | |
711f6b29 JH |
585 | test_expect_success 'merge c1 with c0, c2, c0, and c1' ' |
586 | git reset --hard c1 && | |
711f6b29 JH |
587 | test_tick && |
588 | git merge c0 c2 c0 c1 && | |
589 | verify_merge file result.1-5 && | |
590 | verify_parents $c1 $c2 | |
591 | ' | |
592 | ||
df516fb5 | 593 | test_debug 'git log --graph --decorate --oneline --all' |
711f6b29 JH |
594 | |
595 | test_expect_success 'merge c1 with c1 and c2' ' | |
596 | git reset --hard c1 && | |
711f6b29 JH |
597 | test_tick && |
598 | git merge c1 c2 && | |
599 | verify_merge file result.1-5 && | |
600 | verify_parents $c1 $c2 | |
601 | ' | |
602 | ||
df516fb5 | 603 | test_debug 'git log --graph --decorate --oneline --all' |
711f6b29 | 604 | |
9ca8f607 JH |
605 | test_expect_success 'merge fast-forward in a dirty tree' ' |
606 | git reset --hard c0 && | |
607 | mv file file1 && | |
608 | cat file1 >file && | |
609 | rm -f file1 && | |
610 | git merge c2 | |
611 | ' | |
612 | ||
df516fb5 | 613 | test_debug 'git log --graph --decorate --oneline --all' |
9ca8f607 | 614 | |
c9ea118e | 615 | test_expect_success 'in-index merge' ' |
446247db | 616 | git reset --hard c0 && |
4c073457 | 617 | git merge --no-ff -s resolve c1 >out && |
c9ea118e | 618 | test_i18ngrep "Wonderful." out && |
446247db JH |
619 | verify_parents $c0 $c1 |
620 | ' | |
621 | ||
df516fb5 | 622 | test_debug 'git log --graph --decorate --oneline --all' |
446247db | 623 | |
668f26ff MV |
624 | test_expect_success 'refresh the index before merging' ' |
625 | git reset --hard c1 && | |
016e5ff2 | 626 | cp file file.n && mv -f file.n file && |
668f26ff MV |
627 | git merge c3 |
628 | ' | |
629 | ||
b81f925f JN |
630 | cat >expected.branch <<\EOF |
631 | Merge branch 'c5-branch' (early part) | |
632 | EOF | |
633 | cat >expected.tag <<\EOF | |
634 | Merge commit 'c5~1' | |
4e6d4bc0 MV |
635 | EOF |
636 | ||
637 | test_expect_success 'merge early part of c2' ' | |
638 | git reset --hard c3 && | |
4c073457 | 639 | echo c4 >c4.c && |
4e6d4bc0 MV |
640 | git add c4.c && |
641 | git commit -m c4 && | |
642 | git tag c4 && | |
4c073457 | 643 | echo c5 >c5.c && |
4e6d4bc0 MV |
644 | git add c5.c && |
645 | git commit -m c5 && | |
646 | git tag c5 && | |
647 | git reset --hard c3 && | |
4c073457 | 648 | echo c6 >c6.c && |
4e6d4bc0 MV |
649 | git add c6.c && |
650 | git commit -m c6 && | |
651 | git tag c6 && | |
b81f925f JN |
652 | git branch -f c5-branch c5 && |
653 | git merge c5-branch~1 && | |
ad2f7255 | 654 | git show -s --pretty=tformat:%s HEAD >actual.branch && |
b81f925f | 655 | git reset --keep HEAD^ && |
4e6d4bc0 | 656 | git merge c5~1 && |
ad2f7255 | 657 | git show -s --pretty=tformat:%s HEAD >actual.tag && |
b81f925f JN |
658 | test_cmp expected.branch actual.branch && |
659 | test_cmp expected.tag actual.tag | |
4e6d4bc0 MV |
660 | ' |
661 | ||
df516fb5 | 662 | test_debug 'git log --graph --decorate --oneline --all' |
668f26ff | 663 | |
cf10f9fd MV |
664 | test_expect_success 'merge --no-ff --no-commit && commit' ' |
665 | git reset --hard c0 && | |
666 | git merge --no-ff --no-commit c1 && | |
667 | EDITOR=: git commit && | |
668 | verify_parents $c0 $c1 | |
669 | ' | |
670 | ||
df516fb5 | 671 | test_debug 'git log --graph --decorate --oneline --all' |
cf10f9fd MV |
672 | |
673 | test_expect_success 'amending no-ff merge commit' ' | |
674 | EDITOR=: git commit --amend && | |
675 | verify_parents $c0 $c1 | |
676 | ' | |
677 | ||
df516fb5 | 678 | test_debug 'git log --graph --decorate --oneline --all' |
cf10f9fd | 679 | |
66f4b98a JS |
680 | cat >editor <<\EOF |
681 | #!/bin/sh | |
682 | # Add a new message string that was not in the template | |
683 | ( | |
684 | echo "Merge work done on the side branch c1" | |
685 | echo | |
686 | cat <"$1" | |
687 | ) >"$1.tmp" && mv "$1.tmp" "$1" | |
688 | # strip comments and blank lines from end of message | |
689 | sed -e '/^#/d' < "$1" | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' > expected | |
690 | EOF | |
691 | chmod 755 editor | |
692 | ||
693 | test_expect_success 'merge --no-ff --edit' ' | |
694 | git reset --hard c0 && | |
695 | EDITOR=./editor git merge --no-ff --edit c1 && | |
696 | verify_parents $c0 $c1 && | |
697 | git cat-file commit HEAD >raw && | |
698 | grep "work done on the side branch" raw && | |
699 | sed "1,/^$/d" >actual raw && | |
9c5b2fab | 700 | test_cmp expected actual |
66f4b98a JS |
701 | ' |
702 | ||
b5c9f1c1 JH |
703 | test_expect_success GPG 'merge --ff-only tag' ' |
704 | git reset --hard c0 && | |
705 | git commit --allow-empty -m "A newer commit" && | |
706 | git tag -s -m "A newer commit" signed && | |
707 | git reset --hard c0 && | |
708 | ||
709 | git merge --ff-only signed && | |
710 | git rev-parse signed^0 >expect && | |
711 | git rev-parse HEAD >actual && | |
9c5b2fab | 712 | test_cmp expect actual |
b5c9f1c1 JH |
713 | ' |
714 | ||
3adab6f3 JH |
715 | test_expect_success GPG 'merge --no-edit tag should skip editor' ' |
716 | git reset --hard c0 && | |
717 | git commit --allow-empty -m "A newer commit" && | |
718 | git tag -f -s -m "A newer commit" signed && | |
719 | git reset --hard c0 && | |
720 | ||
721 | EDITOR=false git merge --no-edit signed && | |
722 | git rev-parse signed^0 >expect && | |
723 | git rev-parse HEAD^2 >actual && | |
9c5b2fab | 724 | test_cmp expect actual |
3adab6f3 JH |
725 | ' |
726 | ||
e34f8027 JK |
727 | test_expect_success 'set up mod-256 conflict scenario' ' |
728 | # 256 near-identical stanzas... | |
729 | for i in $(test_seq 1 256); do | |
730 | for j in 1 2 3 4 5; do | |
731 | echo $i-$j | |
732 | done | |
733 | done >file && | |
734 | git add file && | |
735 | git commit -m base && | |
736 | ||
737 | # one side changes the first line of each to "master" | |
738 | sed s/-1/-master/ <file >tmp && | |
739 | mv tmp file && | |
740 | git commit -am master && | |
741 | ||
742 | # and the other to "side"; merging the two will | |
743 | # yield 256 separate conflicts | |
744 | git checkout -b side HEAD^ && | |
745 | sed s/-1/-side/ <file >tmp && | |
746 | mv tmp file && | |
747 | git commit -am side | |
748 | ' | |
749 | ||
750 | test_expect_success 'merge detects mod-256 conflicts (recursive)' ' | |
751 | git reset --hard && | |
752 | test_must_fail git merge -s recursive master | |
753 | ' | |
754 | ||
755 | test_expect_success 'merge detects mod-256 conflicts (resolve)' ' | |
756 | git reset --hard && | |
757 | test_must_fail git merge -s resolve master | |
758 | ' | |
759 | ||
b84e65d4 JH |
760 | test_expect_success 'merge nothing into void' ' |
761 | git init void && | |
762 | ( | |
763 | cd void && | |
764 | git remote add up .. && | |
765 | git fetch up && | |
766 | test_must_fail git merge FETCH_HEAD | |
767 | ) | |
768 | ' | |
769 | ||
367ff694 CP |
770 | test_expect_success 'merge can be completed with --continue' ' |
771 | git reset --hard c0 && | |
772 | git merge --no-ff --no-commit c1 && | |
773 | git merge --continue && | |
774 | verify_parents $c0 $c1 | |
775 | ' | |
776 | ||
9d89b355 MG |
777 | write_script .git/FAKE_EDITOR <<EOF |
778 | # kill -TERM command added below. | |
779 | EOF | |
780 | ||
781 | test_expect_success EXECKEEPSPID 'killed merge can be completed with --continue' ' | |
782 | git reset --hard c0 && | |
783 | ! "$SHELL_PATH" -c '\'' | |
784 | echo kill -TERM $$ >> .git/FAKE_EDITOR | |
785 | GIT_EDITOR=.git/FAKE_EDITOR | |
786 | export GIT_EDITOR | |
787 | exec git merge --no-ff --edit c1'\'' && | |
788 | git merge --continue && | |
789 | verify_parents $c0 $c1 | |
790 | ' | |
791 | ||
a85d1b69 | 792 | test_done |