3 # Copyright (c) 2007 Lars Hjemli
6 test_description
='git merge
8 Testing basic merge operations/option parsing.'
84 cat >result
.1-5-9 <<EOF
97 echo "Merge commit 'c2'" >msg
.1-5 &&
98 echo "Merge commit 'c2'; commit 'c3'" >msg
.1-5-9 &&
99 echo "Squashed commit of the following:" >squash
.1 &&
101 git log
--no-merges ^HEAD c1
>>squash
.1 &&
102 echo "Squashed commit of the following:" >squash
.1-5 &&
104 git log
--no-merges ^HEAD c2
>>squash
.1-5 &&
105 echo "Squashed commit of the following:" >squash
.1-5-9 &&
106 echo >>squash
.1-5-9 &&
107 git log
--no-merges ^HEAD c2 c3
>>squash
.1-5-9 &&
109 echo "* commit 'c3':" >msg.log
&&
110 echo " commit 3" >>msg.log
&&
115 if ! test_cmp
"$1" "$2"
123 verify_diff
"$2" "$1" "[OOPS] bad merge result" &&
124 if test $
(git ls-files
-u |
wc -l) -gt 0
126 echo "[OOPS] unmerged files"
129 if test_must_fail git
diff --exit-code
131 echo "[OOPS] working tree != index"
136 git show
-s --pretty=format
:%s HEAD
>msg.act
&&
137 verify_diff
"$3" msg.act
"[OOPS] bad merge message"
142 if test "$1" != "$(git rev-parse HEAD)"
144 echo "[OOPS] HEAD != $1"
153 if test "$1" != "$(git rev-parse HEAD^$i)"
155 echo "[OOPS] HEAD^$i != $1"
163 verify_mergeheads
() {
165 if ! test -f .git
/MERGE_HEAD
167 echo "[OOPS] MERGE_HEAD is missing"
172 head=$
(head -n $i .git
/MERGE_HEAD |
sed -ne \
$p)
173 if test "$1" != "$head"
175 echo "[OOPS] MERGE_HEAD $i != $1"
183 verify_no_mergehead
() {
184 if test -f .git
/MERGE_HEAD
186 echo "[OOPS] MERGE_HEAD exists"
192 test_expect_success
'setup' '
195 git commit -m "commit 0" &&
197 c0=$(git rev-parse HEAD) &&
201 git commit -m "commit 1" &&
203 c1=$(git rev-parse HEAD) &&
204 git reset --hard "$c0" &&
208 git commit -m "commit 2" &&
210 c2=$(git rev-parse HEAD) &&
211 git reset --hard "$c0" &&
215 git commit -m "commit 3" &&
217 c3=$(git rev-parse HEAD)
218 git reset --hard "$c0" &&
222 test_debug
'gitk --all'
224 test_expect_success
'test option parsing' '
225 test_must_fail git merge -$ c1 &&
226 test_must_fail git merge --no-such c1 &&
227 test_must_fail git merge -s foobar c1 &&
228 test_must_fail git merge -s=foobar c1 &&
229 test_must_fail git merge -m &&
230 test_must_fail git merge
233 test_expect_success
'reject non-strategy with a git-merge-foo name' '
234 test_must_fail git merge -s index c1
237 test_expect_success
'merge c0 with c1' '
238 git reset --hard c0 &&
240 verify_merge file result.1 &&
244 test_debug
'gitk --all'
246 test_expect_success
'merge c0 with c1 with --ff-only' '
247 git reset --hard c0 &&
248 git merge --ff-only c1 &&
249 git merge --ff-only HEAD c0 c1 &&
250 verify_merge file result.1 &&
254 test_debug
'gitk --all'
256 test_expect_success
'merge c1 with c2' '
257 git reset --hard c1 &&
260 verify_merge file result.1-5 msg.1-5 &&
261 verify_parents $c1 $c2
264 test_debug
'gitk --all'
266 test_expect_success
'merge c1 with c2 and c3' '
267 git reset --hard c1 &&
270 verify_merge file result.1-5-9 msg.1-5-9 &&
271 verify_parents $c1 $c2 $c3
274 test_debug
'gitk --all'
276 test_expect_success
'failing merges with --ff-only' '
277 git reset --hard c1 &&
279 test_must_fail git merge --ff-only c2 &&
280 test_must_fail git merge --ff-only c3 &&
281 test_must_fail git merge --ff-only c2 c3
284 test_expect_success
'merge c0 with c1 (no-commit)' '
285 git reset --hard c0 &&
286 git merge --no-commit c1 &&
287 verify_merge file result.1 &&
291 test_debug
'gitk --all'
293 test_expect_success
'merge c1 with c2 (no-commit)' '
294 git reset --hard c1 &&
295 git merge --no-commit c2 &&
296 verify_merge file result.1-5 &&
298 verify_mergeheads $c2
301 test_debug
'gitk --all'
303 test_expect_success
'merge c1 with c2 and c3 (no-commit)' '
304 git reset --hard c1 &&
305 git merge --no-commit c2 c3 &&
306 verify_merge file result.1-5-9 &&
308 verify_mergeheads $c2 $c3
311 test_debug
'gitk --all'
313 test_expect_success
'merge c0 with c1 (squash)' '
314 git reset --hard c0 &&
315 git merge --squash c1 &&
316 verify_merge file result.1 &&
318 verify_no_mergehead &&
319 verify_diff squash.1 .git/SQUASH_MSG "[OOPS] bad squash message"
322 test_debug
'gitk --all'
324 test_expect_success
'merge c0 with c1 (squash, ff-only)' '
325 git reset --hard c0 &&
326 git merge --squash --ff-only c1 &&
327 verify_merge file result.1 &&
329 verify_no_mergehead &&
330 verify_diff squash.1 .git/SQUASH_MSG "[OOPS] bad squash message"
333 test_debug
'gitk --all'
335 test_expect_success
'merge c1 with c2 (squash)' '
336 git reset --hard c1 &&
337 git merge --squash c2 &&
338 verify_merge file result.1-5 &&
340 verify_no_mergehead &&
341 verify_diff squash.1-5 .git/SQUASH_MSG "[OOPS] bad squash message"
344 test_debug
'gitk --all'
346 test_expect_success
'unsuccesful merge of c1 with c2 (squash, ff-only)' '
347 git reset --hard c1 &&
348 test_must_fail git merge --squash --ff-only c2
351 test_debug
'gitk --all'
353 test_expect_success
'merge c1 with c2 and c3 (squash)' '
354 git reset --hard c1 &&
355 git merge --squash c2 c3 &&
356 verify_merge file result.1-5-9 &&
358 verify_no_mergehead &&
359 verify_diff squash.1-5-9 .git/SQUASH_MSG "[OOPS] bad squash message"
362 test_debug
'gitk --all'
364 test_expect_success
'merge c1 with c2 (no-commit in config)' '
365 git reset --hard c1 &&
366 git config branch.master.mergeoptions "--no-commit" &&
368 verify_merge file result.1-5 &&
370 verify_mergeheads $c2
373 test_debug
'gitk --all'
375 test_expect_success
'merge c1 with c2 (squash in config)' '
376 git reset --hard c1 &&
377 git config branch.master.mergeoptions "--squash" &&
379 verify_merge file result.1-5 &&
381 verify_no_mergehead &&
382 verify_diff squash.1-5 .git/SQUASH_MSG "[OOPS] bad squash message"
385 test_debug
'gitk --all'
387 test_expect_success
'override config option -n with --summary' '
388 git reset --hard c1 &&
389 git config branch.master.mergeoptions "-n" &&
391 git merge --summary c2 >diffstat.txt &&
392 verify_merge file result.1-5 msg.1-5 &&
393 verify_parents $c1 $c2 &&
394 if ! grep "^ file | *2 +-$" diffstat.txt
396 echo "[OOPS] diffstat was not generated with --summary"
401 test_expect_success
'override config option -n with --stat' '
402 git reset --hard c1 &&
403 git config branch.master.mergeoptions "-n" &&
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
410 echo "[OOPS] diffstat was not generated with --stat"
415 test_debug
'gitk --all'
417 test_expect_success
'override config option --stat' '
418 git reset --hard c1 &&
419 git config branch.master.mergeoptions "--stat" &&
421 git merge -n c2 >diffstat.txt &&
422 verify_merge file result.1-5 msg.1-5 &&
423 verify_parents $c1 $c2 &&
424 if grep "^ file | *2 +-$" diffstat.txt
426 echo "[OOPS] diffstat was generated"
431 test_debug
'gitk --all'
433 test_expect_success
'merge c1 with c2 (override --no-commit)' '
434 git reset --hard c1 &&
435 git config branch.master.mergeoptions "--no-commit" &&
437 git merge --commit c2 &&
438 verify_merge file result.1-5 msg.1-5 &&
439 verify_parents $c1 $c2
442 test_debug
'gitk --all'
444 test_expect_success
'merge c1 with c2 (override --squash)' '
445 git reset --hard c1 &&
446 git config branch.master.mergeoptions "--squash" &&
448 git merge --no-squash c2 &&
449 verify_merge file result.1-5 msg.1-5 &&
450 verify_parents $c1 $c2
453 test_debug
'gitk --all'
455 test_expect_success
'merge c0 with c1 (no-ff)' '
456 git reset --hard c0 &&
457 git config branch.master.mergeoptions "" &&
459 git merge --no-ff c1 &&
460 verify_merge file result.1 &&
461 verify_parents $c0 $c1
464 test_debug
'gitk --all'
466 test_expect_success
'combining --squash and --no-ff is refused' '
467 test_must_fail git merge --squash --no-ff c1 &&
468 test_must_fail git merge --no-ff --squash c1
471 test_expect_success
'combining --ff-only and --no-ff is refused' '
472 test_must_fail git merge --ff-only --no-ff c1 &&
473 test_must_fail git merge --no-ff --ff-only c1
476 test_expect_success
'merge c0 with c1 (ff overrides no-ff)' '
477 git reset --hard c0 &&
478 git config branch.master.mergeoptions "--no-ff" &&
480 verify_merge file result.1 &&
484 test_expect_success
'merge log message' '
485 git reset --hard c0 &&
486 git merge --no-log c2 &&
487 git show -s --pretty=format:%b HEAD >msg.act &&
488 verify_diff msg.nolog msg.act "[OOPS] bad merge log message" &&
490 git merge --log c3 &&
491 git show -s --pretty=format:%b HEAD >msg.act &&
492 verify_diff msg.log msg.act "[OOPS] bad merge log message" &&
494 git reset --hard HEAD^ &&
495 git config merge.log yes &&
497 git show -s --pretty=format:%b HEAD >msg.act &&
498 verify_diff msg.log msg.act "[OOPS] bad merge log message"
501 test_debug
'gitk --all'
503 test_expect_success
'merge c1 with c0, c2, c0, and c1' '
504 git reset --hard c1 &&
505 git config branch.master.mergeoptions "" &&
507 git merge c0 c2 c0 c1 &&
508 verify_merge file result.1-5 &&
509 verify_parents $c1 $c2
512 test_debug
'gitk --all'
514 test_expect_success
'merge c1 with c0, c2, c0, and c1' '
515 git reset --hard c1 &&
516 git config branch.master.mergeoptions "" &&
518 git merge c0 c2 c0 c1 &&
519 verify_merge file result.1-5 &&
520 verify_parents $c1 $c2
523 test_debug
'gitk --all'
525 test_expect_success
'merge c1 with c1 and c2' '
526 git reset --hard c1 &&
527 git config branch.master.mergeoptions "" &&
530 verify_merge file result.1-5 &&
531 verify_parents $c1 $c2
534 test_debug
'gitk --all'
536 test_expect_success
'merge fast-forward in a dirty tree' '
537 git reset --hard c0 &&
544 test_debug
'gitk --all'
546 test_expect_success
'in-index merge' '
547 git reset --hard c0 &&
548 git merge --no-ff -s resolve c1 > out &&
549 grep "Wonderful." out &&
550 verify_parents $c0 $c1
553 test_debug
'gitk --all'
555 test_expect_success
'refresh the index before merging' '
556 git reset --hard c1 &&
557 cp file file.n && mv -f file.n file &&
561 cat >expected.branch
<<\EOF
562 Merge branch
'c5-branch' (early part
)
564 cat >expected.tag
<<\EOF
568 test_expect_success
'merge early part of c2' '
569 git reset --hard c3 &&
578 git reset --hard c3 &&
583 git branch -f c5-branch c5 &&
584 git merge c5-branch~1 &&
585 git show -s --pretty=format:%s HEAD >actual.branch &&
586 git reset --keep HEAD^ &&
588 git show -s --pretty=format:%s HEAD >actual.tag &&
589 test_cmp expected.branch actual.branch &&
590 test_cmp expected.tag actual.tag
593 test_debug
'gitk --all'
595 test_expect_success
'merge --no-ff --no-commit && commit' '
596 git reset --hard c0 &&
597 git merge --no-ff --no-commit c1 &&
598 EDITOR=: git commit &&
599 verify_parents $c0 $c1
602 test_debug
'gitk --all'
604 test_expect_success
'amending no-ff merge commit' '
605 EDITOR=: git commit --amend &&
606 verify_parents $c0 $c1
609 test_debug
'gitk --all'