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