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
30 . "$TEST_DIRECTORY"/lib-gpg.sh
32 test_write_lines 1 2 3 4 5 6 7 8 9 >file
34 test_write_lines '1 X' 2 3 4 5 6 7 8 9 >file.1
35 test_write_lines 1 2 '3 X' 4 5 6 7 8 9 >file.3
36 test_write_lines 1 2 3 4 '5 X' 6 7 8 9 >file.5
37 test_write_lines 1 2 3 4 5 6 7 8 '9 X' >file.9
38 test_write_lines 1 2 3 4 5 6 7 8 '9 Y' >file.9y
39 test_write_lines '1 X' 2 3 4 5 6 7 8 9 >result.1
40 test_write_lines '1 X' 2 3 4 '5 X' 6 7 8 9 >result.1-5
41 test_write_lines '1 X' 2 3 4 5 6 7 8 '9 X' >result.1-9
42 test_write_lines '1 X' 2 3 4 '5 X' 6 7 8 '9 X' >result.1-5-9
43 test_write_lines '1 X' 2 '3 X' 4 '5 X' 6 7 8 '9 X' >result.1-3-5-9
44 test_write_lines 1 2 3 4 5 6 7 8 '9 Z' >result.9z
46 create_merge_msgs () {
47 echo "Merge tag 'c2'" >msg.1-5 &&
48 echo "Merge tags 'c2' and 'c3'" >msg.1-5-9 &&
50 echo "Squashed commit of the following:" &&
52 git log --no-merges ^HEAD c1
55 echo "Squashed commit of the following:" &&
57 git log --no-merges ^HEAD c2
60 echo "Squashed commit of the following:" &&
62 git log --no-merges ^HEAD c2 c3
72 git update-index --refresh &&
73 git diff --exit-code &&
76 git show -s --pretty=tformat:%s HEAD >msg.act &&
82 echo "$1" >head.expected &&
83 git rev-parse HEAD >head.actual &&
84 test_cmp head.expected head.actual
88 test_write_lines "$@" >parents.expected &&
93 git rev-parse HEAD^$i >>parents.actual &&
97 test_must_fail git rev-parse --verify "HEAD^$i" &&
98 test_cmp parents.expected parents.actual
101 verify_mergeheads () {
102 test_write_lines "$@" >mergehead.expected &&
106 done <.git/MERGE_HEAD >mergehead.actual &&
107 test_cmp mergehead.expected mergehead.actual
110 verify_no_mergehead () {
111 ! test -e .git/MERGE_HEAD
114 test_expect_success 'setup' '
117 git commit -m "commit 0" &&
119 c0=$(git rev-parse HEAD) &&
123 git commit -m "commit 1" &&
125 c1=$(git rev-parse HEAD) &&
126 git reset --hard "$c0" &&
130 git commit -m "commit 2" &&
132 c2=$(git rev-parse HEAD) &&
133 git reset --hard "$c0" &&
137 git commit -m "commit 7" &&
139 git reset --hard "$c0" &&
143 git commit -m "commit 3" &&
145 c3=$(git rev-parse HEAD) &&
146 git reset --hard "$c0" &&
150 test_debug 'git log --graph --decorate --oneline --all'
152 test_expect_success 'test option parsing' '
153 test_must_fail git merge -$ c1 &&
154 test_must_fail git merge --no-such c1 &&
155 test_must_fail git merge -s foobar c1 &&
156 test_must_fail git merge -s=foobar c1 &&
157 test_must_fail git merge -m &&
158 test_must_fail git merge --abort foobar &&
159 test_must_fail git merge --abort --quiet &&
160 test_must_fail git merge --continue foobar &&
161 test_must_fail git merge --continue --quiet &&
162 test_must_fail git merge
165 test_expect_success 'merge -h with invalid index' '
171 test_expect_code 129 git merge -h 2>usage
173 test_i18ngrep "[Uu]sage: git merge" broken/usage
176 test_expect_success 'reject non-strategy with a git-merge-foo name' '
177 test_must_fail git merge -s index c1
180 test_expect_success 'merge c0 with c1' '
181 echo "OBJID HEAD@{0}: merge c1: Fast-forward" >reflog.expected &&
183 git reset --hard c0 &&
185 verify_merge file result.1 &&
188 git reflog -1 >reflog.actual &&
189 sed "s/$_x05[0-9a-f]*/OBJID/g" reflog.actual >reflog.fuzzy &&
190 test_cmp reflog.expected reflog.fuzzy
193 test_debug 'git log --graph --decorate --oneline --all'
195 test_expect_success 'merge c0 with c1 with --ff-only' '
196 git reset --hard c0 &&
197 git merge --ff-only c1 &&
198 git merge --ff-only HEAD c0 c1 &&
199 verify_merge file result.1 &&
203 test_debug 'git log --graph --decorate --oneline --all'
205 test_expect_success 'merge from unborn branch' '
206 git checkout -f master &&
207 test_might_fail git branch -D kid &&
209 echo "OBJID HEAD@{0}: initial pull" >reflog.expected &&
211 git checkout --orphan kid &&
212 test_when_finished "git checkout -f master" &&
215 git merge --ff-only c1 &&
216 verify_merge file result.1 &&
219 git reflog -1 >reflog.actual &&
220 sed "s/$_x05[0-9a-f][0-9a-f]/OBJID/g" reflog.actual >reflog.fuzzy &&
221 test_cmp reflog.expected reflog.fuzzy
224 test_debug 'git log --graph --decorate --oneline --all'
226 test_expect_success 'merge c1 with c2' '
227 git reset --hard c1 &&
230 verify_merge file result.1-5 msg.1-5 &&
231 verify_parents $c1 $c2
234 test_expect_success 'merge --squash c3 with c7' '
235 git reset --hard c3 &&
236 test_must_fail git merge --squash c7 &&
237 cat result.9z >file &&
238 git commit --no-edit -a &&
240 cat >expect <<-EOF &&
241 Squashed commit of the following:
248 git cat-file commit HEAD >raw &&
249 sed -e '1,/^$/d' raw >actual &&
250 test_cmp expect actual
253 test_expect_success 'merge c3 with c7 with commit.cleanup = scissors' '
254 git config commit.cleanup scissors &&
255 git reset --hard c3 &&
256 test_must_fail git merge c7 &&
257 cat result.9z >file &&
258 git commit --no-edit -a &&
260 cat >expect <<-\EOF &&
261 Merge tag '"'"'c7'"'"'
263 # ------------------------ >8 ------------------------
264 # Do not modify or remove the line above.
265 # Everything below it will be ignored.
270 git cat-file commit HEAD >raw &&
271 sed -e '1,/^$/d' raw >actual &&
272 test_i18ncmp expect actual
275 test_expect_success 'merge c3 with c7 with --squash commit.cleanup = scissors' '
276 git config commit.cleanup scissors &&
277 git reset --hard c3 &&
278 test_must_fail git merge --squash c7 &&
279 cat result.9z >file &&
280 git commit --no-edit -a &&
282 cat >expect <<-EOF &&
283 Squashed commit of the following:
287 # ------------------------ >8 ------------------------
288 # Do not modify or remove the line above.
289 # Everything below it will be ignored.
294 git cat-file commit HEAD >raw &&
295 sed -e '1,/^$/d' raw >actual &&
296 test_i18ncmp expect actual
299 test_debug 'git log --graph --decorate --oneline --all'
301 test_expect_success 'merge c1 with c2 and c3' '
302 git reset --hard c1 &&
305 verify_merge file result.1-5-9 msg.1-5-9 &&
306 verify_parents $c1 $c2 $c3
309 test_debug 'git log --graph --decorate --oneline --all'
311 test_expect_success 'merges with --ff-only' '
312 git reset --hard c1 &&
314 test_must_fail git merge --ff-only c2 &&
315 test_must_fail git merge --ff-only c3 &&
316 test_must_fail git merge --ff-only c2 c3 &&
317 git reset --hard c0 &&
322 test_expect_success 'merges with merge.ff=only' '
323 git reset --hard c1 &&
325 test_config merge.ff "only" &&
326 test_must_fail git merge c2 &&
327 test_must_fail git merge c3 &&
328 test_must_fail git merge c2 c3 &&
329 git reset --hard c0 &&
334 test_expect_success 'merge c0 with c1 (no-commit)' '
335 git reset --hard c0 &&
336 git merge --no-commit c1 &&
337 verify_merge file result.1 &&
341 test_debug 'git log --graph --decorate --oneline --all'
343 test_expect_success 'merge c1 with c2 (no-commit)' '
344 git reset --hard c1 &&
345 git merge --no-commit c2 &&
346 verify_merge file result.1-5 &&
348 verify_mergeheads $c2
351 test_debug 'git log --graph --decorate --oneline --all'
353 test_expect_success 'merge c1 with c2 and c3 (no-commit)' '
354 git reset --hard c1 &&
355 git merge --no-commit c2 c3 &&
356 verify_merge file result.1-5-9 &&
358 verify_mergeheads $c2 $c3
361 test_debug 'git log --graph --decorate --oneline --all'
363 test_expect_success 'merge c0 with c1 (squash)' '
364 git reset --hard c0 &&
365 git merge --squash c1 &&
366 verify_merge file result.1 &&
368 verify_no_mergehead &&
369 test_cmp squash.1 .git/SQUASH_MSG
372 test_debug 'git log --graph --decorate --oneline --all'
374 test_expect_success 'merge c0 with c1 (squash, ff-only)' '
375 git reset --hard c0 &&
376 git merge --squash --ff-only c1 &&
377 verify_merge file result.1 &&
379 verify_no_mergehead &&
380 test_cmp squash.1 .git/SQUASH_MSG
383 test_debug 'git log --graph --decorate --oneline --all'
385 test_expect_success 'merge c1 with c2 (squash)' '
386 git reset --hard c1 &&
387 git merge --squash c2 &&
388 verify_merge file result.1-5 &&
390 verify_no_mergehead &&
391 test_cmp squash.1-5 .git/SQUASH_MSG
394 test_debug 'git log --graph --decorate --oneline --all'
396 test_expect_success 'unsuccessful merge of c1 with c2 (squash, ff-only)' '
397 git reset --hard c1 &&
398 test_must_fail git merge --squash --ff-only c2
401 test_debug 'git log --graph --decorate --oneline --all'
403 test_expect_success 'merge c1 with c2 and c3 (squash)' '
404 git reset --hard c1 &&
405 git merge --squash c2 c3 &&
406 verify_merge file result.1-5-9 &&
408 verify_no_mergehead &&
409 test_cmp squash.1-5-9 .git/SQUASH_MSG
412 test_debug 'git log --graph --decorate --oneline --all'
414 test_expect_success 'merge c1 with c2 (no-commit in config)' '
415 git reset --hard c1 &&
416 test_config branch.master.mergeoptions "--no-commit" &&
418 verify_merge file result.1-5 &&
420 verify_mergeheads $c2
423 test_debug 'git log --graph --decorate --oneline --all'
425 test_expect_success 'merge c1 with c2 (log in config)' '
426 git reset --hard c1 &&
427 git merge --log c2 &&
428 git show -s --pretty=tformat:%s%n%b >expect &&
430 test_config branch.master.mergeoptions "--log" &&
431 git reset --hard c1 &&
433 git show -s --pretty=tformat:%s%n%b >actual &&
435 test_cmp expect actual
438 test_expect_success 'merge c1 with c2 (log in config gets overridden)' '
439 git reset --hard c1 &&
441 git show -s --pretty=tformat:%s%n%b >expect &&
443 test_config branch.master.mergeoptions "--no-log" &&
444 test_config merge.log "true" &&
445 git reset --hard c1 &&
447 git show -s --pretty=tformat:%s%n%b >actual &&
449 test_cmp expect actual
452 test_expect_success 'merge c1 with c2 (squash in config)' '
453 git reset --hard c1 &&
454 test_config branch.master.mergeoptions "--squash" &&
456 verify_merge file result.1-5 &&
458 verify_no_mergehead &&
459 test_cmp squash.1-5 .git/SQUASH_MSG
462 test_debug 'git log --graph --decorate --oneline --all'
464 test_expect_success 'override config option -n with --summary' '
465 git reset --hard c1 &&
466 test_config branch.master.mergeoptions "-n" &&
468 git merge --summary c2 >diffstat.txt &&
469 verify_merge file result.1-5 msg.1-5 &&
470 verify_parents $c1 $c2 &&
471 if ! grep "^ file | *2 +-$" diffstat.txt
473 echo "[OOPS] diffstat was not generated with --summary"
478 test_expect_success 'override config option -n with --stat' '
479 git reset --hard c1 &&
480 test_config branch.master.mergeoptions "-n" &&
482 git merge --stat c2 >diffstat.txt &&
483 verify_merge file result.1-5 msg.1-5 &&
484 verify_parents $c1 $c2 &&
485 if ! grep "^ file | *2 +-$" diffstat.txt
487 echo "[OOPS] diffstat was not generated with --stat"
492 test_debug 'git log --graph --decorate --oneline --all'
494 test_expect_success 'override config option --stat' '
495 git reset --hard c1 &&
496 test_config branch.master.mergeoptions "--stat" &&
498 git merge -n c2 >diffstat.txt &&
499 verify_merge file result.1-5 msg.1-5 &&
500 verify_parents $c1 $c2 &&
501 if grep "^ file | *2 +-$" diffstat.txt
503 echo "[OOPS] diffstat was generated"
508 test_debug 'git log --graph --decorate --oneline --all'
510 test_expect_success 'merge c1 with c2 (override --no-commit)' '
511 git reset --hard c1 &&
512 test_config branch.master.mergeoptions "--no-commit" &&
514 git merge --commit c2 &&
515 verify_merge file result.1-5 msg.1-5 &&
516 verify_parents $c1 $c2
519 test_debug 'git log --graph --decorate --oneline --all'
521 test_expect_success 'merge c1 with c2 (override --squash)' '
522 git reset --hard c1 &&
523 test_config branch.master.mergeoptions "--squash" &&
525 git merge --no-squash c2 &&
526 verify_merge file result.1-5 msg.1-5 &&
527 verify_parents $c1 $c2
530 test_debug 'git log --graph --decorate --oneline --all'
532 test_expect_success 'merge c0 with c1 (no-ff)' '
533 git reset --hard c0 &&
535 git merge --no-ff c1 &&
536 verify_merge file result.1 &&
537 verify_parents $c0 $c1
540 test_debug 'git log --graph --decorate --oneline --all'
542 test_expect_success 'merge c0 with c1 (merge.ff=false)' '
543 git reset --hard c0 &&
544 test_config merge.ff "false" &&
547 verify_merge file result.1 &&
548 verify_parents $c0 $c1
550 test_debug 'git log --graph --decorate --oneline --all'
552 test_expect_success 'combine branch.master.mergeoptions with merge.ff' '
553 git reset --hard c0 &&
554 test_config branch.master.mergeoptions "--ff" &&
555 test_config merge.ff "false" &&
558 verify_merge file result.1 &&
562 test_expect_success 'tolerate unknown values for merge.ff' '
563 git reset --hard c0 &&
564 test_config merge.ff "something-new" &&
566 git merge c1 2>message &&
568 test_must_be_empty message
571 test_expect_success 'combining --squash and --no-ff is refused' '
572 git reset --hard c0 &&
573 test_must_fail git merge --squash --no-ff c1 &&
574 test_must_fail git merge --no-ff --squash c1
577 test_expect_success 'combining --squash and --commit is refused' '
578 git reset --hard c0 &&
579 test_must_fail git merge --squash --commit c1 &&
580 test_must_fail git merge --commit --squash c1
583 test_expect_success 'option --ff-only overwrites --no-ff' '
584 git merge --no-ff --ff-only c1 &&
585 test_must_fail git merge --no-ff --ff-only c2
588 test_expect_success 'option --no-ff overrides merge.ff=only config' '
589 git reset --hard c0 &&
590 test_config merge.ff only &&
594 test_expect_success 'merge c0 with c1 (ff overrides no-ff)' '
595 git reset --hard c0 &&
596 test_config branch.master.mergeoptions "--no-ff" &&
598 verify_merge file result.1 &&
602 test_expect_success 'merge log message' '
603 git reset --hard c0 &&
604 git merge --no-log c2 &&
605 git show -s --pretty=format:%b HEAD >msg.act &&
606 test_must_be_empty msg.act &&
608 git reset --hard c0 &&
609 test_config branch.master.mergeoptions "--no-ff" &&
610 git merge --no-log c2 &&
611 git show -s --pretty=format:%b HEAD >msg.act &&
612 test_must_be_empty msg.act &&
614 git merge --log c3 &&
615 git show -s --pretty=format:%b HEAD >msg.act &&
616 test_cmp msg.log msg.act &&
618 git reset --hard HEAD^ &&
619 test_config merge.log "yes" &&
621 git show -s --pretty=format:%b HEAD >msg.act &&
622 test_cmp msg.log msg.act
625 test_debug 'git log --graph --decorate --oneline --all'
627 test_expect_success 'merge c1 with c0, c2, c0, and c1' '
628 git reset --hard c1 &&
630 git merge c0 c2 c0 c1 &&
631 verify_merge file result.1-5 &&
632 verify_parents $c1 $c2
635 test_debug 'git log --graph --decorate --oneline --all'
637 test_expect_success 'merge c1 with c0, c2, c0, and c1' '
638 git reset --hard c1 &&
640 git merge c0 c2 c0 c1 &&
641 verify_merge file result.1-5 &&
642 verify_parents $c1 $c2
645 test_debug 'git log --graph --decorate --oneline --all'
647 test_expect_success 'merge c1 with c1 and c2' '
648 git reset --hard c1 &&
651 verify_merge file result.1-5 &&
652 verify_parents $c1 $c2
655 test_debug 'git log --graph --decorate --oneline --all'
657 test_expect_success 'merge fast-forward in a dirty tree' '
658 git reset --hard c0 &&
665 test_debug 'git log --graph --decorate --oneline --all'
667 test_expect_success 'in-index merge' '
668 git reset --hard c0 &&
669 git merge --no-ff -s resolve c1 >out &&
670 test_i18ngrep "Wonderful." out &&
671 verify_parents $c0 $c1
674 test_debug 'git log --graph --decorate --oneline --all'
676 test_expect_success 'refresh the index before merging' '
677 git reset --hard c1 &&
678 cp file file.n && mv -f file.n file &&
682 test_expect_success 'merge with --autostash' '
683 git reset --hard c1 &&
684 git merge-file file file.orig file.9 &&
685 git merge --autostash c2 2>err &&
686 test_i18ngrep "Applied autostash." err &&
687 git show HEAD:file >merge-result &&
688 test_cmp result.1-5 merge-result &&
689 test_cmp result.1-5-9 file
692 test_expect_success 'merge with merge.autoStash' '
693 test_config merge.autoStash true &&
694 git reset --hard c1 &&
695 git merge-file file file.orig file.9 &&
696 git merge c2 2>err &&
697 test_i18ngrep "Applied autostash." err &&
698 git show HEAD:file >merge-result &&
699 test_cmp result.1-5 merge-result &&
700 test_cmp result.1-5-9 file
703 test_expect_success 'fast-forward merge with --autostash' '
704 git reset --hard c0 &&
705 git merge-file file file.orig file.5 &&
706 git merge --autostash c1 2>err &&
707 test_i18ngrep "Applied autostash." err &&
708 test_cmp result.1-5 file
711 test_expect_success 'octopus merge with --autostash' '
712 git reset --hard c1 &&
713 git merge-file file file.orig file.3 &&
714 git merge --autostash c2 c3 2>err &&
715 test_i18ngrep "Applied autostash." err &&
716 git show HEAD:file >merge-result &&
717 test_cmp result.1-5-9 merge-result &&
718 test_cmp result.1-3-5-9 file
721 test_expect_success 'conflicted merge with --autostash, --abort restores stash' '
722 git reset --hard c3 &&
724 test_must_fail git merge --autostash c7 &&
725 git merge --abort 2>err &&
726 test_i18ngrep "Applied autostash." err &&
730 test_expect_success 'completed merge (git commit) with --no-commit and --autostash' '
731 git reset --hard c1 &&
732 git merge-file file file.orig file.9 &&
734 git merge --no-commit --autostash c2 &&
735 git stash show -p MERGE_AUTOSTASH >actual &&
736 test_cmp expect actual &&
738 test_i18ngrep "Applied autostash." err &&
739 git show HEAD:file >merge-result &&
740 test_cmp result.1-5 merge-result &&
741 test_cmp result.1-5-9 file
744 test_expect_success 'completed merge (git merge --continue) with --no-commit and --autostash' '
745 git reset --hard c1 &&
746 git merge-file file file.orig file.9 &&
748 git merge --no-commit --autostash c2 &&
749 git stash show -p MERGE_AUTOSTASH >actual &&
750 test_cmp expect actual &&
751 git merge --continue 2>err &&
752 test_i18ngrep "Applied autostash." err &&
753 git show HEAD:file >merge-result &&
754 test_cmp result.1-5 merge-result &&
755 test_cmp result.1-5-9 file
758 test_expect_success 'aborted merge (merge --abort) with --no-commit and --autostash' '
759 git reset --hard c1 &&
760 git merge-file file file.orig file.9 &&
762 git merge --no-commit --autostash c2 &&
763 git stash show -p MERGE_AUTOSTASH >actual &&
764 test_cmp expect actual &&
765 git merge --abort 2>err &&
766 test_i18ngrep "Applied autostash." err &&
768 test_cmp expect actual
771 test_expect_success 'aborted merge (reset --hard) with --no-commit and --autostash' '
772 git reset --hard c1 &&
773 git merge-file file file.orig file.9 &&
775 git merge --no-commit --autostash c2 &&
776 git stash show -p MERGE_AUTOSTASH >actual &&
777 test_cmp expect actual &&
778 git reset --hard 2>err &&
779 test_i18ngrep "Autostash exists; creating a new stash entry." err &&
783 test_expect_success 'quit merge with --no-commit and --autostash' '
784 git reset --hard c1 &&
785 git merge-file file file.orig file.9 &&
787 git merge --no-commit --autostash c2 &&
788 git stash show -p MERGE_AUTOSTASH >actual &&
789 test_cmp expect actual &&
790 git diff HEAD >expect &&
791 git merge --quit 2>err &&
792 test_i18ngrep "Autostash exists; creating a new stash entry." err &&
793 git diff HEAD >actual &&
794 test_cmp expect actual
797 test_expect_success 'merge with conflicted --autostash changes' '
798 git reset --hard c1 &&
799 git merge-file file file.orig file.9y &&
801 test_when_finished "test_might_fail git stash drop" &&
802 git merge --autostash c3 2>err &&
803 test_i18ngrep "Applying autostash resulted in conflicts." err &&
804 git show HEAD:file >merge-result &&
805 test_cmp result.1-9 merge-result &&
806 git stash show -p >actual &&
807 test_cmp expect actual
810 cat >expected.branch <<\EOF
811 Merge branch 'c5-branch' (early part)
813 cat >expected.tag <<\EOF
817 test_expect_success 'merge early part of c2' '
818 git reset --hard c3 &&
827 git reset --hard c3 &&
832 git branch -f c5-branch c5 &&
833 git merge c5-branch~1 &&
834 git show -s --pretty=tformat:%s HEAD >actual.branch &&
835 git reset --keep HEAD^ &&
837 git show -s --pretty=tformat:%s HEAD >actual.tag &&
838 test_cmp expected.branch actual.branch &&
839 test_cmp expected.tag actual.tag
842 test_debug 'git log --graph --decorate --oneline --all'
844 test_expect_success 'merge --no-ff --no-commit && commit' '
845 git reset --hard c0 &&
846 git merge --no-ff --no-commit c1 &&
847 EDITOR=: git commit &&
848 verify_parents $c0 $c1
851 test_debug 'git log --graph --decorate --oneline --all'
853 test_expect_success 'amending no-ff merge commit' '
854 EDITOR=: git commit --amend &&
855 verify_parents $c0 $c1
858 test_debug 'git log --graph --decorate --oneline --all'
862 # Add a new message string that was not in the template
864 echo "Merge work done on the side branch c1"
867 ) >"$1.tmp" && mv "$1.tmp" "$1"
868 # strip comments and blank lines from end of message
869 sed -e '/^#/d' "$1" | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' >expected
873 test_expect_success 'merge --no-ff --edit' '
874 git reset --hard c0 &&
875 EDITOR=./editor git merge --no-ff --edit c1 &&
876 verify_parents $c0 $c1 &&
877 git cat-file commit HEAD >raw &&
878 grep "work done on the side branch" raw &&
879 sed "1,/^$/d" >actual raw &&
880 test_cmp expected actual
883 test_expect_success 'merge annotated/signed tag w/o tracking' '
884 test_when_finished "rm -rf dst; git tag -d anno1" &&
885 git tag -a -m "anno c1" anno1 c1 &&
887 git rev-parse c1 >dst/expect &&
889 # c0 fast-forwards to c1 but because this repository
890 # is not a "downstream" whose refs/tags follows along
891 # tag from the "upstream", this pull defaults to --no-ff
895 git rev-parse HEAD^2 >actual &&
896 test_cmp expect actual
900 test_expect_success 'merge annotated/signed tag w/ tracking' '
901 test_when_finished "rm -rf dst; git tag -d anno1" &&
902 git tag -a -m "anno c1" anno1 c1 &&
904 git rev-parse c1 >dst/expect &&
906 # c0 fast-forwards to c1 and because this repository
907 # is a "downstream" whose refs/tags follows along
908 # tag from the "upstream", this pull defaults to --ff
910 git remote add origin .. &&
911 git pull origin c0 &&
914 git rev-parse HEAD >actual &&
915 test_cmp expect actual
919 test_expect_success GPG 'merge --ff-only tag' '
920 git reset --hard c0 &&
921 git commit --allow-empty -m "A newer commit" &&
922 git tag -s -m "A newer commit" signed &&
923 git reset --hard c0 &&
925 git merge --ff-only signed &&
926 git rev-parse signed^0 >expect &&
927 git rev-parse HEAD >actual &&
928 test_cmp expect actual
931 test_expect_success GPG 'merge --no-edit tag should skip editor' '
932 git reset --hard c0 &&
933 git commit --allow-empty -m "A newer commit" &&
934 git tag -f -s -m "A newer commit" signed &&
935 git reset --hard c0 &&
937 EDITOR=false git merge --no-edit --no-ff signed &&
938 git rev-parse signed^0 >expect &&
939 git rev-parse HEAD^2 >actual &&
940 test_cmp expect actual
943 test_expect_success 'set up mod-256 conflict scenario' '
944 # 256 near-identical stanzas...
945 for i in $(test_seq 1 256); do
946 for j in 1 2 3 4 5; do
951 git commit -m base &&
953 # one side changes the first line of each to "master"
954 sed s/-1/-master/ file >tmp &&
956 git commit -am master &&
958 # and the other to "side"; merging the two will
959 # yield 256 separate conflicts
960 git checkout -b side HEAD^ &&
961 sed s/-1/-side/ file >tmp &&
966 test_expect_success 'merge detects mod-256 conflicts (recursive)' '
968 test_must_fail git merge -s recursive master
971 test_expect_success 'merge detects mod-256 conflicts (resolve)' '
973 test_must_fail git merge -s resolve master
976 test_expect_success 'merge nothing into void' '
980 git remote add up .. &&
982 test_must_fail git merge FETCH_HEAD
986 test_expect_success 'merge can be completed with --continue' '
987 git reset --hard c0 &&
988 git merge --no-ff --no-commit c1 &&
989 git merge --continue &&
990 verify_parents $c0 $c1
993 write_script .git/FAKE_EDITOR <<EOF
994 # kill -TERM command added below.
997 test_expect_success EXECKEEPSPID 'killed merge can be completed with --continue' '
998 git reset --hard c0 &&
999 ! "$SHELL_PATH" -c '\''
1000 echo kill -TERM $$ >>.git/FAKE_EDITOR
1001 GIT_EDITOR=.git/FAKE_EDITOR
1003 exec git merge --no-ff --edit c1'\'' &&
1004 git merge --continue &&
1005 verify_parents $c0 $c1
1008 test_expect_success 'merge --quit' '
1009 git init merge-quit &&
1013 echo one >>base.t &&
1014 git commit -am one &&
1016 git checkout base &&
1017 echo two >>base.t &&
1018 git commit -am two &&
1019 test_must_fail git -c rerere.enabled=true merge one &&
1020 test_path_is_file .git/MERGE_HEAD &&
1021 test_path_is_file .git/MERGE_MODE &&
1022 test_path_is_file .git/MERGE_MSG &&
1023 git rerere status >rerere.before &&
1025 test_path_is_missing .git/MERGE_HEAD &&
1026 test_path_is_missing .git/MERGE_MODE &&
1027 test_path_is_missing .git/MERGE_MSG &&
1028 git rerere status >rerere.after &&
1029 test_must_be_empty rerere.after &&
1030 ! test_cmp rerere.after rerere.before
1034 test_expect_success 'merge suggests matching remote refname' '
1035 git commit --allow-empty -m not-local &&
1036 git update-ref refs/remotes/origin/not-local HEAD &&
1037 git reset --hard HEAD^ &&
1039 # This is white-box testing hackery; we happen to know
1040 # that reading packed refs is more picky about the memory
1041 # ownership of strings we pass to for_each_ref() callbacks.
1042 git pack-refs --all --prune &&
1044 test_must_fail git merge not-local 2>stderr &&
1045 grep origin/not-local stderr
1048 test_expect_success 'suggested names are not ambiguous' '
1049 git update-ref refs/heads/origin/not-local HEAD &&
1050 test_must_fail git merge not-local 2>stderr &&
1051 grep remotes/origin/not-local stderr