3 # Copyright (c) 2007 Lars Hjemli
6 test_description
='git merge
8 Testing basic merge operations/option parsing.
17 * [master] Merge commit 'c1
'
19 - [master] Merge commit 'c1
'
26 +++++++* [c0] commit 0
31 printf '%s\n' 1 2 3 4 5 6 7 8 9 >file
32 printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >file.1
33 printf '%s\n' 1 2 3 4 '5 X' 6 7 8 9 >file.5
34 printf '%s\n' 1 2 3 4 5 6 7 8 '9 X' >file.9
35 printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >result
.1
36 printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 9 >result
.1-5
37 printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 '9 X' >result
.1-5-9
39 create_merge_msgs
() {
40 echo "Merge commit 'c2'" >msg
.1-5 &&
41 echo "Merge commit 'c2'; commit 'c3'" >msg
.1-5-9 &&
43 echo "Squashed commit of the following:" &&
45 git log
--no-merges ^HEAD c1
48 echo "Squashed commit of the following:" &&
50 git log
--no-merges ^HEAD c2
53 echo "Squashed commit of the following:" &&
55 git log
--no-merges ^HEAD c2 c3
59 echo "* commit 'c3':" &&
67 git update-index
--refresh &&
68 git
diff --exit-code &&
71 git show
-s --pretty=format
:%s HEAD
>msg.act
&&
77 echo "$1" >head.expected
&&
78 git rev-parse HEAD
>head.actual
&&
79 test_cmp
head.expected
head.actual
83 printf '%s\n' "$@" >parents.expected
&&
88 git rev-parse HEAD^
$i >>parents.actual
&&
92 test_must_fail git rev-parse
--verify "HEAD^$i" &&
93 test_cmp parents.expected parents.actual
96 verify_mergeheads
() {
97 printf '%s\n' "$@" >mergehead.expected
&&
98 test_cmp mergehead.expected .git
/MERGE_HEAD
101 verify_no_mergehead
() {
102 ! test -e .git
/MERGE_HEAD
105 test_expect_success
'setup' '
108 git commit -m "commit 0" &&
110 c0=$(git rev-parse HEAD) &&
114 git commit -m "commit 1" &&
116 c1=$(git rev-parse HEAD) &&
117 git reset --hard "$c0" &&
121 git commit -m "commit 2" &&
123 c2=$(git rev-parse HEAD) &&
124 git reset --hard "$c0" &&
128 git commit -m "commit 3" &&
130 c3=$(git rev-parse HEAD)
131 git reset --hard "$c0" &&
135 test_debug
'git log --graph --decorate --oneline --all'
137 test_expect_success
'test option parsing' '
138 test_must_fail git merge -$ c1 &&
139 test_must_fail git merge --no-such c1 &&
140 test_must_fail git merge -s foobar c1 &&
141 test_must_fail git merge -s=foobar c1 &&
142 test_must_fail git merge -m &&
143 test_must_fail git merge
146 test_expect_success
'merge -h with invalid index' '
152 test_expect_code 129 git merge -h 2>usage
154 grep "[Uu]sage: git merge" broken/usage
157 test_expect_success
'reject non-strategy with a git-merge-foo name' '
158 test_must_fail git merge -s index c1
161 test_expect_success
'merge c0 with c1' '
162 echo "OBJID HEAD@{0}: merge c1: Fast-forward" >reflog.expected &&
164 git reset --hard c0 &&
166 verify_merge file result.1 &&
169 git reflog -1 >reflog.actual &&
170 sed "s/$_x05[0-9a-f]*/OBJID/g" reflog.actual >reflog.fuzzy &&
171 test_cmp reflog.expected reflog.fuzzy
174 test_debug
'git log --graph --decorate --oneline --all'
176 test_expect_success
'merge c0 with c1 with --ff-only' '
177 git reset --hard c0 &&
178 git merge --ff-only c1 &&
179 git merge --ff-only HEAD c0 c1 &&
180 verify_merge file result.1 &&
184 test_debug
'git log --graph --decorate --oneline --all'
186 test_expect_success
'merge from unborn branch' '
187 git checkout -f master &&
188 test_might_fail git branch -D kid &&
190 echo "OBJID HEAD@{0}: initial pull" >reflog.expected &&
192 git checkout --orphan kid &&
193 test_when_finished "git checkout -f master" &&
196 git merge --ff-only c1 &&
197 verify_merge file result.1 &&
200 git reflog -1 >reflog.actual &&
201 sed "s/$_x05[0-9a-f][0-9a-f]/OBJID/g" reflog.actual >reflog.fuzzy &&
202 test_cmp reflog.expected reflog.fuzzy
205 test_debug
'git log --graph --decorate --oneline --all'
207 test_expect_success
'merge c1 with c2' '
208 git reset --hard c1 &&
211 verify_merge file result.1-5 msg.1-5 &&
212 verify_parents $c1 $c2
215 test_debug
'git log --graph --decorate --oneline --all'
217 test_expect_success
'merge c1 with c2 and c3' '
218 git reset --hard c1 &&
221 verify_merge file result.1-5-9 msg.1-5-9 &&
222 verify_parents $c1 $c2 $c3
225 test_debug
'git log --graph --decorate --oneline --all'
227 test_expect_success
'failing merges with --ff-only' '
228 git reset --hard c1 &&
230 test_must_fail git merge --ff-only c2 &&
231 test_must_fail git merge --ff-only c3 &&
232 test_must_fail git merge --ff-only c2 c3
235 test_expect_success
'merge c0 with c1 (no-commit)' '
236 git reset --hard c0 &&
237 git merge --no-commit c1 &&
238 verify_merge file result.1 &&
242 test_debug
'git log --graph --decorate --oneline --all'
244 test_expect_success
'merge c1 with c2 (no-commit)' '
245 git reset --hard c1 &&
246 git merge --no-commit c2 &&
247 verify_merge file result.1-5 &&
249 verify_mergeheads $c2
252 test_debug
'git log --graph --decorate --oneline --all'
254 test_expect_success
'merge c1 with c2 and c3 (no-commit)' '
255 git reset --hard c1 &&
256 git merge --no-commit c2 c3 &&
257 verify_merge file result.1-5-9 &&
259 verify_mergeheads $c2 $c3
262 test_debug
'git log --graph --decorate --oneline --all'
264 test_expect_success
'merge c0 with c1 (squash)' '
265 git reset --hard c0 &&
266 git merge --squash c1 &&
267 verify_merge file result.1 &&
269 verify_no_mergehead &&
270 test_cmp squash.1 .git/SQUASH_MSG
273 test_debug
'git log --graph --decorate --oneline --all'
275 test_expect_success
'merge c0 with c1 (squash, ff-only)' '
276 git reset --hard c0 &&
277 git merge --squash --ff-only c1 &&
278 verify_merge file result.1 &&
280 verify_no_mergehead &&
281 test_cmp squash.1 .git/SQUASH_MSG
284 test_debug
'git log --graph --decorate --oneline --all'
286 test_expect_success
'merge c1 with c2 (squash)' '
287 git reset --hard c1 &&
288 git merge --squash c2 &&
289 verify_merge file result.1-5 &&
291 verify_no_mergehead &&
292 test_cmp squash.1-5 .git/SQUASH_MSG
295 test_debug
'git log --graph --decorate --oneline --all'
297 test_expect_success
'unsuccesful merge of c1 with c2 (squash, ff-only)' '
298 git reset --hard c1 &&
299 test_must_fail git merge --squash --ff-only c2
302 test_debug
'git log --graph --decorate --oneline --all'
304 test_expect_success
'merge c1 with c2 and c3 (squash)' '
305 git reset --hard c1 &&
306 git merge --squash c2 c3 &&
307 verify_merge file result.1-5-9 &&
309 verify_no_mergehead &&
310 test_cmp squash.1-5-9 .git/SQUASH_MSG
313 test_debug
'git log --graph --decorate --oneline --all'
315 test_expect_success
'merge c1 with c2 (no-commit in config)' '
316 git reset --hard c1 &&
317 git config branch.master.mergeoptions "--no-commit" &&
319 verify_merge file result.1-5 &&
321 verify_mergeheads $c2
324 test_debug
'git log --graph --decorate --oneline --all'
326 test_expect_success
'merge c1 with c2 (squash in config)' '
327 git reset --hard c1 &&
328 git config branch.master.mergeoptions "--squash" &&
330 verify_merge file result.1-5 &&
332 verify_no_mergehead &&
333 test_cmp squash.1-5 .git/SQUASH_MSG
336 test_debug
'git log --graph --decorate --oneline --all'
338 test_expect_success
'override config option -n with --summary' '
339 git reset --hard c1 &&
340 git config branch.master.mergeoptions "-n" &&
342 git merge --summary c2 >diffstat.txt &&
343 verify_merge file result.1-5 msg.1-5 &&
344 verify_parents $c1 $c2 &&
345 if ! grep "^ file | *2 +-$" diffstat.txt
347 echo "[OOPS] diffstat was not generated with --summary"
352 test_expect_success
'override config option -n with --stat' '
353 git reset --hard c1 &&
354 git config branch.master.mergeoptions "-n" &&
356 git merge --stat c2 >diffstat.txt &&
357 verify_merge file result.1-5 msg.1-5 &&
358 verify_parents $c1 $c2 &&
359 if ! grep "^ file | *2 +-$" diffstat.txt
361 echo "[OOPS] diffstat was not generated with --stat"
366 test_debug
'git log --graph --decorate --oneline --all'
368 test_expect_success
'override config option --stat' '
369 git reset --hard c1 &&
370 git config branch.master.mergeoptions "--stat" &&
372 git merge -n c2 >diffstat.txt &&
373 verify_merge file result.1-5 msg.1-5 &&
374 verify_parents $c1 $c2 &&
375 if grep "^ file | *2 +-$" diffstat.txt
377 echo "[OOPS] diffstat was generated"
382 test_debug
'git log --graph --decorate --oneline --all'
384 test_expect_success
'merge c1 with c2 (override --no-commit)' '
385 git reset --hard c1 &&
386 git config branch.master.mergeoptions "--no-commit" &&
388 git merge --commit c2 &&
389 verify_merge file result.1-5 msg.1-5 &&
390 verify_parents $c1 $c2
393 test_debug
'git log --graph --decorate --oneline --all'
395 test_expect_success
'merge c1 with c2 (override --squash)' '
396 git reset --hard c1 &&
397 git config branch.master.mergeoptions "--squash" &&
399 git merge --no-squash c2 &&
400 verify_merge file result.1-5 msg.1-5 &&
401 verify_parents $c1 $c2
404 test_debug
'git log --graph --decorate --oneline --all'
406 test_expect_success
'merge c0 with c1 (no-ff)' '
407 git reset --hard c0 &&
408 git config branch.master.mergeoptions "" &&
410 git merge --no-ff c1 &&
411 verify_merge file result.1 &&
412 verify_parents $c0 $c1
415 test_debug
'git log --graph --decorate --oneline --all'
417 test_expect_success
'combining --squash and --no-ff is refused' '
418 test_must_fail git merge --squash --no-ff c1 &&
419 test_must_fail git merge --no-ff --squash c1
422 test_expect_success
'combining --ff-only and --no-ff is refused' '
423 test_must_fail git merge --ff-only --no-ff c1 &&
424 test_must_fail git merge --no-ff --ff-only c1
427 test_expect_success
'merge c0 with c1 (ff overrides no-ff)' '
428 git reset --hard c0 &&
429 git config branch.master.mergeoptions "--no-ff" &&
431 verify_merge file result.1 &&
435 test_expect_success
'merge log message' '
436 git reset --hard c0 &&
437 git merge --no-log c2 &&
438 git show -s --pretty=format:%b HEAD >msg.act &&
439 test_cmp msg.nolog msg.act &&
441 git merge --log c3 &&
442 git show -s --pretty=format:%b HEAD >msg.act &&
443 test_cmp msg.log msg.act &&
445 git reset --hard HEAD^ &&
446 git config merge.log yes &&
448 git show -s --pretty=format:%b HEAD >msg.act &&
449 test_cmp msg.log msg.act
452 test_debug
'git log --graph --decorate --oneline --all'
454 test_expect_success
'merge c1 with c0, c2, c0, and c1' '
455 git reset --hard c1 &&
456 git config branch.master.mergeoptions "" &&
458 git merge c0 c2 c0 c1 &&
459 verify_merge file result.1-5 &&
460 verify_parents $c1 $c2
463 test_debug
'git log --graph --decorate --oneline --all'
465 test_expect_success
'merge c1 with c0, c2, c0, and c1' '
466 git reset --hard c1 &&
467 git config branch.master.mergeoptions "" &&
469 git merge c0 c2 c0 c1 &&
470 verify_merge file result.1-5 &&
471 verify_parents $c1 $c2
474 test_debug
'git log --graph --decorate --oneline --all'
476 test_expect_success
'merge c1 with c1 and c2' '
477 git reset --hard c1 &&
478 git config branch.master.mergeoptions "" &&
481 verify_merge file result.1-5 &&
482 verify_parents $c1 $c2
485 test_debug
'git log --graph --decorate --oneline --all'
487 test_expect_success
'merge fast-forward in a dirty tree' '
488 git reset --hard c0 &&
495 test_debug
'git log --graph --decorate --oneline --all'
497 test_expect_success
'in-index merge' '
498 git reset --hard c0 &&
499 git merge --no-ff -s resolve c1 >out &&
500 test_i18ngrep "Wonderful." out &&
501 verify_parents $c0 $c1
504 test_debug
'git log --graph --decorate --oneline --all'
506 test_expect_success
'refresh the index before merging' '
507 git reset --hard c1 &&
508 cp file file.n && mv -f file.n file &&
512 cat >expected.branch
<<\EOF
513 Merge branch
'c5-branch' (early part
)
515 cat >expected.tag
<<\EOF
519 test_expect_success
'merge early part of c2' '
520 git reset --hard c3 &&
529 git reset --hard c3 &&
534 git branch -f c5-branch c5 &&
535 git merge c5-branch~1 &&
536 git show -s --pretty=format:%s HEAD >actual.branch &&
537 git reset --keep HEAD^ &&
539 git show -s --pretty=format:%s HEAD >actual.tag &&
540 test_cmp expected.branch actual.branch &&
541 test_cmp expected.tag actual.tag
544 test_debug
'git log --graph --decorate --oneline --all'
546 test_expect_success
'merge --no-ff --no-commit && commit' '
547 git reset --hard c0 &&
548 git merge --no-ff --no-commit c1 &&
549 EDITOR=: git commit &&
550 verify_parents $c0 $c1
553 test_debug
'git log --graph --decorate --oneline --all'
555 test_expect_success
'amending no-ff merge commit' '
556 EDITOR=: git commit --amend &&
557 verify_parents $c0 $c1
560 test_debug
'git log --graph --decorate --oneline --all'