3 # Copyright (c) 2007 Lars Hjemli
6 test_description
='git merge
8 Testing basic merge operations/option parsing.
17 * [main] Merge commit 'c1
'
19 - [main] Merge commit 'c1
'
26 +++++++* [c0] commit 0
29 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
30 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
33 .
"$TEST_DIRECTORY"/lib-gpg.sh
35 test_write_lines
1 2 3 4 5 6 7 8 9 >file
37 test_write_lines
'1 X' 2 3 4 5 6 7 8 9 >file.1
38 test_write_lines
1 2 '3 X' 4 5 6 7 8 9 >file.3
39 test_write_lines
1 2 3 4 '5 X' 6 7 8 9 >file.5
40 test_write_lines
1 2 3 4 5 6 7 8 '9 X' >file.9
41 test_write_lines
1 2 3 4 5 6 7 8 '9 Y' >file.9y
42 test_write_lines
'1 X' 2 3 4 5 6 7 8 9 >result
.1
43 test_write_lines
'1 X' 2 3 4 '5 X' 6 7 8 9 >result
.1-5
44 test_write_lines
'1 X' 2 3 4 5 6 7 8 '9 X' >result
.1-9
45 test_write_lines
'1 X' 2 3 4 '5 X' 6 7 8 '9 X' >result
.1-5-9
46 test_write_lines
'1 X' 2 '3 X' 4 '5 X' 6 7 8 '9 X' >result
.1-3-5-9
47 test_write_lines
1 2 3 4 5 6 7 8 '9 Z' >result
.9z
49 create_merge_msgs
() {
50 echo "Merge tag 'c2'" >msg
.1-5 &&
51 echo "Merge tags 'c2' and 'c3'" >msg
.1-5-9 &&
53 echo "Squashed commit of the following:" &&
55 git log
--no-merges ^HEAD c1
58 echo "Squashed commit of the following:" &&
60 git log
--no-merges ^HEAD c2
63 echo "Squashed commit of the following:" &&
65 git log
--no-merges ^HEAD c2 c3
75 git update-index
--refresh &&
76 git
diff --exit-code &&
79 git show
-s --pretty=tformat
:%s HEAD
>msg.act
&&
85 echo "$1" >head.expected
&&
86 git rev-parse HEAD
>head.actual
&&
87 test_cmp
head.expected
head.actual
91 test_write_lines
"$@" >parents.expected
&&
96 git rev-parse HEAD^
$i >>parents.actual
&&
100 test_must_fail git rev-parse
--verify "HEAD^$i" &&
101 test_cmp parents.expected parents.actual
104 verify_mergeheads
() {
105 test_write_lines
"$@" >mergehead.expected
&&
109 done <.git
/MERGE_HEAD
>mergehead.actual
&&
110 test_cmp mergehead.expected mergehead.actual
113 verify_no_mergehead
() {
114 ! test -e .git
/MERGE_HEAD
117 test_expect_success
'setup' '
120 git commit -m "commit 0" &&
122 c0=$(git rev-parse HEAD) &&
128 git commit -m "commit 1" &&
130 c1=$(git rev-parse HEAD) &&
131 git reset --hard "$c0" &&
135 git commit -m "commit 2" &&
137 c2=$(git rev-parse HEAD) &&
138 git reset --hard "$c0" &&
142 git commit -m "commit 7" &&
144 git reset --hard "$c0" &&
148 git commit -m "commit 3" &&
150 c3=$(git rev-parse HEAD) &&
151 git reset --hard "$c0" &&
155 test_debug
'git log --graph --decorate --oneline --all'
157 test_expect_success
'test option parsing' '
158 test_must_fail git merge -$ c1 &&
159 test_must_fail git merge --no-such c1 &&
160 test_must_fail git merge -s foobar c1 &&
161 test_must_fail git merge -s=foobar c1 &&
162 test_must_fail git merge -m &&
163 test_must_fail git merge --abort foobar &&
164 test_must_fail git merge --abort --quiet &&
165 test_must_fail git merge --continue foobar &&
166 test_must_fail git merge --continue --quiet &&
167 test_must_fail git merge
170 test_expect_success
'merge -h with invalid index' '
176 test_expect_code 129 git merge -h 2>usage
178 test_i18ngrep "[Uu]sage: git merge" broken/usage
181 test_expect_success
'reject non-strategy with a git-merge-foo name' '
182 test_must_fail git merge -s index c1
185 test_expect_success
'merge c0 with c1' '
186 echo "OBJID HEAD@{0}: merge c1: Fast-forward" >reflog.expected &&
188 git reset --hard c0 &&
190 verify_merge file result.1 &&
193 git reflog -1 >reflog.actual &&
194 sed "s/$_x05[0-9a-f]*/OBJID/g" reflog.actual >reflog.fuzzy &&
195 test_cmp reflog.expected reflog.fuzzy
198 test_debug
'git log --graph --decorate --oneline --all'
200 test_expect_success
'merge c0 with c1 with --ff-only' '
201 git reset --hard c0 &&
202 git merge --ff-only c1 &&
203 git merge --ff-only HEAD c0 c1 &&
204 verify_merge file result.1 &&
208 test_debug
'git log --graph --decorate --oneline --all'
210 test_expect_success
'merge from unborn branch' '
211 git checkout -f main &&
212 test_might_fail git branch -D kid &&
214 echo "OBJID HEAD@{0}: initial pull" >reflog.expected &&
216 git checkout --orphan kid &&
217 test_when_finished "git checkout -f main" &&
220 git merge --ff-only c1 &&
221 verify_merge file result.1 &&
224 git reflog -1 >reflog.actual &&
225 sed "s/$_x05[0-9a-f][0-9a-f]/OBJID/g" reflog.actual >reflog.fuzzy &&
226 test_cmp reflog.expected reflog.fuzzy
229 test_debug
'git log --graph --decorate --oneline --all'
231 test_expect_success
'merge c1 with c2' '
232 git reset --hard c1 &&
235 verify_merge file result.1-5 msg.1-5 &&
236 verify_parents $c1 $c2
239 test_expect_success
'merge --squash c3 with c7' '
240 git reset --hard c3 &&
241 test_must_fail git merge --squash c7 &&
242 cat result.9z >file &&
243 git commit --no-edit -a &&
245 cat >expect <<-EOF &&
246 Squashed commit of the following:
253 git cat-file commit HEAD >raw &&
254 sed -e "1,/^$/d" raw >actual &&
255 test_cmp expect actual
258 test_expect_success
'merge c3 with c7 with commit.cleanup = scissors' '
259 git config commit.cleanup scissors &&
260 git reset --hard c3 &&
261 test_must_fail git merge c7 &&
262 cat result.9z >file &&
263 git commit --no-edit -a &&
265 cat >expect <<-\EOF &&
266 Merge tag '"'"'c7'"'"'
268 # ------------------------ >8 ------------------------
269 # Do not modify or remove the line above.
270 # Everything below it will be ignored.
275 git cat-file commit HEAD >raw &&
276 sed -e "1,/^$/d" raw >actual &&
277 test_cmp expect actual
280 test_expect_success
'merge c3 with c7 with --squash commit.cleanup = scissors' '
281 git config commit.cleanup scissors &&
282 git reset --hard c3 &&
283 test_must_fail git merge --squash c7 &&
284 cat result.9z >file &&
285 git commit --no-edit -a &&
287 cat >expect <<-EOF &&
288 Squashed commit of the following:
292 # ------------------------ >8 ------------------------
293 # Do not modify or remove the line above.
294 # Everything below it will be ignored.
299 git cat-file commit HEAD >raw &&
300 sed -e "1,/^$/d" raw >actual &&
301 test_cmp expect actual
304 test_debug
'git log --graph --decorate --oneline --all'
306 test_expect_success
'merge c1 with c2 and c3' '
307 git reset --hard c1 &&
310 verify_merge file result.1-5-9 msg.1-5-9 &&
311 verify_parents $c1 $c2 $c3
314 test_debug
'git log --graph --decorate --oneline --all'
316 test_expect_success
'merges with --ff-only' '
317 git reset --hard c1 &&
319 test_must_fail git merge --ff-only c2 &&
320 test_must_fail git merge --ff-only c3 &&
321 test_must_fail git merge --ff-only c2 c3 &&
322 git reset --hard c0 &&
327 test_expect_success
'merges with merge.ff=only' '
328 git reset --hard c1 &&
330 test_config merge.ff "only" &&
331 test_must_fail git merge c2 &&
332 test_must_fail git merge c3 &&
333 test_must_fail git merge c2 c3 &&
334 git reset --hard c0 &&
339 test_expect_success
'merge c0 with c1 (no-commit)' '
340 git reset --hard c0 &&
341 git merge --no-commit c1 &&
342 verify_merge file result.1 &&
346 test_debug
'git log --graph --decorate --oneline --all'
348 test_expect_success
'merge c1 with c2 (no-commit)' '
349 git reset --hard c1 &&
350 git merge --no-commit c2 &&
351 verify_merge file result.1-5 &&
353 verify_mergeheads $c2
356 test_debug
'git log --graph --decorate --oneline --all'
358 test_expect_success
'merge c1 with c2 and c3 (no-commit)' '
359 git reset --hard c1 &&
360 git merge --no-commit c2 c3 &&
361 verify_merge file result.1-5-9 &&
363 verify_mergeheads $c2 $c3
366 test_debug
'git log --graph --decorate --oneline --all'
368 test_expect_success
'merge c0 with c1 (squash)' '
369 git reset --hard c0 &&
370 git merge --squash c1 &&
371 verify_merge file result.1 &&
373 verify_no_mergehead &&
374 test_cmp squash.1 .git/SQUASH_MSG
377 test_debug
'git log --graph --decorate --oneline --all'
379 test_expect_success
'merge c0 with c1 (squash, ff-only)' '
380 git reset --hard c0 &&
381 git merge --squash --ff-only c1 &&
382 verify_merge file result.1 &&
384 verify_no_mergehead &&
385 test_cmp squash.1 .git/SQUASH_MSG
388 test_debug
'git log --graph --decorate --oneline --all'
390 test_expect_success
'merge c1 with c2 (squash)' '
391 git reset --hard c1 &&
392 git merge --squash c2 &&
393 verify_merge file result.1-5 &&
395 verify_no_mergehead &&
396 test_cmp squash.1-5 .git/SQUASH_MSG
399 test_debug
'git log --graph --decorate --oneline --all'
401 test_expect_success
'unsuccessful merge of c1 with c2 (squash, ff-only)' '
402 git reset --hard c1 &&
403 test_must_fail git merge --squash --ff-only c2
406 test_debug
'git log --graph --decorate --oneline --all'
408 test_expect_success
'merge c1 with c2 and c3 (squash)' '
409 git reset --hard c1 &&
410 git merge --squash c2 c3 &&
411 verify_merge file result.1-5-9 &&
413 verify_no_mergehead &&
414 test_cmp squash.1-5-9 .git/SQUASH_MSG
417 test_debug
'git log --graph --decorate --oneline --all'
419 test_expect_success
'merge c1 with c2 (no-commit in config)' '
420 git reset --hard c1 &&
421 test_config branch.main.mergeoptions "--no-commit" &&
423 verify_merge file result.1-5 &&
425 verify_mergeheads $c2
428 test_debug
'git log --graph --decorate --oneline --all'
430 test_expect_success
'merge c1 with c2 (log in config)' '
431 git reset --hard c1 &&
432 git merge --log c2 &&
433 git show -s --pretty=tformat:%s%n%b >expect &&
435 test_config branch.main.mergeoptions "--log" &&
436 git reset --hard c1 &&
438 git show -s --pretty=tformat:%s%n%b >actual &&
440 test_cmp expect actual
443 test_expect_success
'merge c1 with c2 (log in config gets overridden)' '
444 git reset --hard c1 &&
446 git show -s --pretty=tformat:%s%n%b >expect &&
448 test_config branch.main.mergeoptions "--no-log" &&
449 test_config merge.log "true" &&
450 git reset --hard c1 &&
452 git show -s --pretty=tformat:%s%n%b >actual &&
454 test_cmp expect actual
457 test_expect_success
'merge c1 with c2 (squash in config)' '
458 git reset --hard c1 &&
459 test_config branch.main.mergeoptions "--squash" &&
461 verify_merge file result.1-5 &&
463 verify_no_mergehead &&
464 test_cmp squash.1-5 .git/SQUASH_MSG
467 test_debug
'git log --graph --decorate --oneline --all'
469 test_expect_success
'override config option -n with --summary' '
470 git reset --hard c1 &&
471 test_config branch.main.mergeoptions "-n" &&
473 git merge --summary c2 >diffstat.txt &&
474 verify_merge file result.1-5 msg.1-5 &&
475 verify_parents $c1 $c2 &&
476 if ! grep "^ file | *2 +-$" diffstat.txt
478 echo "[OOPS] diffstat was not generated with --summary"
483 test_expect_success
'override config option -n with --stat' '
484 git reset --hard c1 &&
485 test_config branch.main.mergeoptions "-n" &&
487 git merge --stat c2 >diffstat.txt &&
488 verify_merge file result.1-5 msg.1-5 &&
489 verify_parents $c1 $c2 &&
490 if ! grep "^ file | *2 +-$" diffstat.txt
492 echo "[OOPS] diffstat was not generated with --stat"
497 test_debug
'git log --graph --decorate --oneline --all'
499 test_expect_success
'override config option --stat' '
500 git reset --hard c1 &&
501 test_config branch.main.mergeoptions "--stat" &&
503 git merge -n c2 >diffstat.txt &&
504 verify_merge file result.1-5 msg.1-5 &&
505 verify_parents $c1 $c2 &&
506 if grep "^ file | *2 +-$" diffstat.txt
508 echo "[OOPS] diffstat was generated"
513 test_debug
'git log --graph --decorate --oneline --all'
515 test_expect_success
'merge c1 with c2 (override --no-commit)' '
516 git reset --hard c1 &&
517 test_config branch.main.mergeoptions "--no-commit" &&
519 git merge --commit c2 &&
520 verify_merge file result.1-5 msg.1-5 &&
521 verify_parents $c1 $c2
524 test_debug
'git log --graph --decorate --oneline --all'
526 test_expect_success
'merge c1 with c2 (override --squash)' '
527 git reset --hard c1 &&
528 test_config branch.main.mergeoptions "--squash" &&
530 git merge --no-squash c2 &&
531 verify_merge file result.1-5 msg.1-5 &&
532 verify_parents $c1 $c2
535 test_debug
'git log --graph --decorate --oneline --all'
537 test_expect_success
'merge c0 with c1 (no-ff)' '
538 git reset --hard c0 &&
540 git merge --no-ff c1 &&
541 verify_merge file result.1 &&
542 verify_parents $c0 $c1
545 test_debug
'git log --graph --decorate --oneline --all'
547 test_expect_success
'merge c0 with c1 (merge.ff=false)' '
548 git reset --hard c0 &&
549 test_config merge.ff "false" &&
552 verify_merge file result.1 &&
553 verify_parents $c0 $c1
555 test_debug
'git log --graph --decorate --oneline --all'
557 test_expect_success
'combine branch.main.mergeoptions with merge.ff' '
558 git reset --hard c0 &&
559 test_config branch.main.mergeoptions "--ff" &&
560 test_config merge.ff "false" &&
563 verify_merge file result.1 &&
567 test_expect_success
'tolerate unknown values for merge.ff' '
568 git reset --hard c0 &&
569 test_config merge.ff "something-new" &&
571 git merge c1 2>message &&
573 test_must_be_empty message
576 test_expect_success
'combining --squash and --no-ff is refused' '
577 git reset --hard c0 &&
578 test_must_fail git merge --squash --no-ff c1 &&
579 test_must_fail git merge --no-ff --squash c1
582 test_expect_success
'combining --squash and --commit is refused' '
583 git reset --hard c0 &&
584 test_must_fail git merge --squash --commit c1 &&
585 test_must_fail git merge --commit --squash c1
588 test_expect_success
'option --ff-only overwrites --no-ff' '
589 git merge --no-ff --ff-only c1 &&
590 test_must_fail git merge --no-ff --ff-only c2
593 test_expect_success
'option --no-ff overrides merge.ff=only config' '
594 git reset --hard c0 &&
595 test_config merge.ff only &&
599 test_expect_success
'merge c0 with c1 (ff overrides no-ff)' '
600 git reset --hard c0 &&
601 test_config branch.main.mergeoptions "--no-ff" &&
603 verify_merge file result.1 &&
607 test_expect_success
'merge log message' '
608 git reset --hard c0 &&
609 git merge --no-log c2 &&
610 git show -s --pretty=format:%b HEAD >msg.act &&
611 test_must_be_empty msg.act &&
613 git reset --hard c0 &&
614 test_config branch.main.mergeoptions "--no-ff" &&
615 git merge --no-log c2 &&
616 git show -s --pretty=format:%b HEAD >msg.act &&
617 test_must_be_empty msg.act &&
619 git merge --log c3 &&
620 git show -s --pretty=format:%b HEAD >msg.act &&
621 test_cmp msg.log msg.act &&
623 git reset --hard HEAD^ &&
624 test_config merge.log "yes" &&
626 git show -s --pretty=format:%b HEAD >msg.act &&
627 test_cmp msg.log msg.act
630 test_debug
'git log --graph --decorate --oneline --all'
632 test_expect_success
'merge c1 with c0, c2, c0, and c1' '
633 git reset --hard c1 &&
635 git merge c0 c2 c0 c1 &&
636 verify_merge file result.1-5 &&
637 verify_parents $c1 $c2
640 test_debug
'git log --graph --decorate --oneline --all'
642 test_expect_success
'merge c1 with c0, c2, c0, and c1' '
643 git reset --hard c1 &&
645 git merge c0 c2 c0 c1 &&
646 verify_merge file result.1-5 &&
647 verify_parents $c1 $c2
650 test_debug
'git log --graph --decorate --oneline --all'
652 test_expect_success
'merge c1 with c1 and c2' '
653 git reset --hard c1 &&
656 verify_merge file result.1-5 &&
657 verify_parents $c1 $c2
660 test_debug
'git log --graph --decorate --oneline --all'
662 test_expect_success
'merge fast-forward in a dirty tree' '
663 git reset --hard c0 &&
670 test_debug
'git log --graph --decorate --oneline --all'
672 test_expect_success
'in-index merge' '
673 git reset --hard c0 &&
674 git merge --no-ff -s resolve c1 >out &&
675 test_i18ngrep "Wonderful." out &&
676 verify_parents $c0 $c1
679 test_debug
'git log --graph --decorate --oneline --all'
681 test_expect_success
'refresh the index before merging' '
682 git reset --hard c1 &&
683 cp file file.n && mv -f file.n file &&
687 test_expect_success
'merge with --autostash' '
688 git reset --hard c1 &&
689 git merge-file file file.orig file.9 &&
690 git merge --autostash c2 2>err &&
691 test_i18ngrep "Applied autostash." err &&
692 git show HEAD:file >merge-result &&
693 test_cmp result.1-5 merge-result &&
694 test_cmp result.1-5-9 file
697 test_expect_success
'merge with merge.autoStash' '
698 test_config merge.autoStash true &&
699 git reset --hard c1 &&
700 git merge-file file file.orig file.9 &&
701 git merge c2 2>err &&
702 test_i18ngrep "Applied autostash." err &&
703 git show HEAD:file >merge-result &&
704 test_cmp result.1-5 merge-result &&
705 test_cmp result.1-5-9 file
708 test_expect_success
'fast-forward merge with --autostash' '
709 git reset --hard c0 &&
710 git merge-file file file.orig file.5 &&
711 git merge --autostash c1 2>err &&
712 test_i18ngrep "Applied autostash." err &&
713 test_cmp result.1-5 file
716 test_expect_success
'failed fast-forward merge with --autostash' '
717 git reset --hard c0 &&
718 git merge-file file file.orig file.5 &&
720 test_when_finished "rm other" &&
721 test_must_fail git merge --autostash c1 2>err &&
722 test_i18ngrep "Applied autostash." err &&
726 test_expect_success
'octopus merge with --autostash' '
727 git reset --hard c1 &&
728 git merge-file file file.orig file.3 &&
729 git merge --autostash c2 c3 2>err &&
730 test_i18ngrep "Applied autostash." err &&
731 git show HEAD:file >merge-result &&
732 test_cmp result.1-5-9 merge-result &&
733 test_cmp result.1-3-5-9 file
736 test_expect_success
'failed merge (exit 2) with --autostash' '
737 git reset --hard c1 &&
738 git merge-file file file.orig file.5 &&
739 test_must_fail git merge -s recursive --autostash c2 c3 2>err &&
740 test_i18ngrep "Applied autostash." err &&
741 test_cmp result.1-5 file
744 test_expect_success
'conflicted merge with --autostash, --abort restores stash' '
745 git reset --hard c3 &&
747 test_must_fail git merge --autostash c7 &&
748 git merge --abort 2>err &&
749 test_i18ngrep "Applied autostash." err &&
753 test_expect_success
'completed merge (git commit) with --no-commit and --autostash' '
754 git reset --hard c1 &&
755 git merge-file file file.orig file.9 &&
757 git merge --no-commit --autostash c2 &&
758 git stash show -p MERGE_AUTOSTASH >actual &&
759 test_cmp expect actual &&
761 test_i18ngrep "Applied autostash." err &&
762 git show HEAD:file >merge-result &&
763 test_cmp result.1-5 merge-result &&
764 test_cmp result.1-5-9 file
767 test_expect_success
'completed merge (git merge --continue) with --no-commit and --autostash' '
768 git reset --hard c1 &&
769 git merge-file file file.orig file.9 &&
771 git merge --no-commit --autostash c2 &&
772 git stash show -p MERGE_AUTOSTASH >actual &&
773 test_cmp expect actual &&
774 git merge --continue 2>err &&
775 test_i18ngrep "Applied autostash." err &&
776 git show HEAD:file >merge-result &&
777 test_cmp result.1-5 merge-result &&
778 test_cmp result.1-5-9 file
781 test_expect_success
'aborted merge (merge --abort) with --no-commit and --autostash' '
782 git reset --hard c1 &&
783 git merge-file file file.orig file.9 &&
785 git merge --no-commit --autostash c2 &&
786 git stash show -p MERGE_AUTOSTASH >actual &&
787 test_cmp expect actual &&
788 git merge --abort 2>err &&
789 test_i18ngrep "Applied autostash." err &&
791 test_cmp expect actual
794 test_expect_success
'aborted merge (reset --hard) with --no-commit and --autostash' '
795 git reset --hard c1 &&
796 git merge-file file file.orig file.9 &&
798 git merge --no-commit --autostash c2 &&
799 git stash show -p MERGE_AUTOSTASH >actual &&
800 test_cmp expect actual &&
801 git reset --hard 2>err &&
802 test_i18ngrep "Autostash exists; creating a new stash entry." err &&
806 test_expect_success
'quit merge with --no-commit and --autostash' '
807 git reset --hard c1 &&
808 git merge-file file file.orig file.9 &&
810 git merge --no-commit --autostash c2 &&
811 git stash show -p MERGE_AUTOSTASH >actual &&
812 test_cmp expect actual &&
813 git diff HEAD >expect &&
814 git merge --quit 2>err &&
815 test_i18ngrep "Autostash exists; creating a new stash entry." err &&
816 git diff HEAD >actual &&
817 test_cmp expect actual
820 test_expect_success
'merge with conflicted --autostash changes' '
821 git reset --hard c1 &&
822 git merge-file file file.orig file.9y &&
824 test_when_finished "test_might_fail git stash drop" &&
825 git merge --autostash c3 2>err &&
826 test_i18ngrep "Applying autostash resulted in conflicts." err &&
827 git show HEAD:file >merge-result &&
828 test_cmp result.1-9 merge-result &&
829 git stash show -p >actual &&
830 test_cmp expect actual
833 cat >expected.branch
<<\EOF
834 Merge branch
'c5-branch' (early part
)
836 cat >expected.tag
<<\EOF
840 test_expect_success
'merge early part of c2' '
841 git reset --hard c3 &&
850 git reset --hard c3 &&
855 git branch -f c5-branch c5 &&
856 git merge c5-branch~1 &&
857 git show -s --pretty=tformat:%s HEAD >actual.branch &&
858 git reset --keep HEAD^ &&
860 git show -s --pretty=tformat:%s HEAD >actual.tag &&
861 test_cmp expected.branch actual.branch &&
862 test_cmp expected.tag actual.tag
865 test_debug
'git log --graph --decorate --oneline --all'
867 test_expect_success
'merge --no-ff --no-commit && commit' '
868 git reset --hard c0 &&
869 git merge --no-ff --no-commit c1 &&
870 EDITOR=: git commit &&
871 verify_parents $c0 $c1
874 test_debug
'git log --graph --decorate --oneline --all'
876 test_expect_success
'amending no-ff merge commit' '
877 EDITOR=: git commit --amend &&
878 verify_parents $c0 $c1
881 test_debug
'git log --graph --decorate --oneline --all'
885 # Add a new message string that was not in the template
887 echo "Merge work done on the side branch c1"
890 ) >"$1.tmp" && mv "$1.tmp" "$1"
891 # strip comments and blank lines from end of message
892 sed -e '/^#/d' "$1" |
sed -e :a
-e '/^\n*$/{$d;N;ba' -e '}' >expected
896 test_expect_success
'merge --no-ff --edit' '
897 git reset --hard c0 &&
898 EDITOR=./editor git merge --no-ff --edit c1 &&
899 verify_parents $c0 $c1 &&
900 git cat-file commit HEAD >raw &&
901 grep "work done on the side branch" raw &&
902 sed "1,/^$/d" >actual raw &&
903 test_cmp expected actual
906 test_expect_success
'merge annotated/signed tag w/o tracking' '
907 test_when_finished "rm -rf dst; git tag -d anno1" &&
908 git tag -a -m "anno c1" anno1 c1 &&
910 git rev-parse c1 >dst/expect &&
912 # c0 fast-forwards to c1 but because this repository
913 # is not a "downstream" whose refs/tags follows along
914 # tag from the "upstream", this pull defaults to --no-ff
918 git rev-parse HEAD^2 >actual &&
919 test_cmp expect actual
923 test_expect_success
'merge annotated/signed tag w/ tracking' '
924 test_when_finished "rm -rf dst; git tag -d anno1" &&
925 git tag -a -m "anno c1" anno1 c1 &&
927 git rev-parse c1 >dst/expect &&
929 # c0 fast-forwards to c1 and because this repository
930 # is a "downstream" whose refs/tags follows along
931 # tag from the "upstream", this pull defaults to --ff
933 git remote add origin .. &&
934 git pull origin c0 &&
937 git rev-parse HEAD >actual &&
938 test_cmp expect actual
942 test_expect_success GPG
'merge --ff-only tag' '
943 git reset --hard c0 &&
944 git commit --allow-empty -m "A newer commit" &&
945 git tag -s -m "A newer commit" signed &&
946 git reset --hard c0 &&
948 git merge --ff-only signed &&
949 git rev-parse signed^0 >expect &&
950 git rev-parse HEAD >actual &&
951 test_cmp expect actual
954 test_expect_success GPG
'merge --no-edit tag should skip editor' '
955 git reset --hard c0 &&
956 git commit --allow-empty -m "A newer commit" &&
957 git tag -f -s -m "A newer commit" signed &&
958 git reset --hard c0 &&
960 EDITOR=false git merge --no-edit --no-ff signed &&
961 git rev-parse signed^0 >expect &&
962 git rev-parse HEAD^2 >actual &&
963 test_cmp expect actual
966 test_expect_success
'set up mod-256 conflict scenario' '
967 # 256 near-identical stanzas...
968 for i in $(test_seq 1 256); do
969 for j in 1 2 3 4 5; do
974 git commit -m base &&
976 # one side changes the first line of each to "main"
977 sed s/-1/-main/ file >tmp &&
979 git commit -am main &&
981 # and the other to "side"; merging the two will
982 # yield 256 separate conflicts
983 git checkout -b side HEAD^ &&
984 sed s/-1/-side/ file >tmp &&
989 test_expect_success
'merge detects mod-256 conflicts (recursive)' '
991 test_must_fail git merge -s recursive main
994 test_expect_success
'merge detects mod-256 conflicts (resolve)' '
996 test_must_fail git merge -s resolve main
999 test_expect_success
'merge nothing into void' '
1003 git remote add up .. &&
1005 test_must_fail git merge FETCH_HEAD
1009 test_expect_success
'merge can be completed with --continue' '
1010 git reset --hard c0 &&
1011 git merge --no-ff --no-commit c1 &&
1012 git merge --continue &&
1013 verify_parents $c0 $c1
1016 write_script .git
/FAKE_EDITOR
<<EOF
1017 # kill -TERM command added below.
1020 test_expect_success EXECKEEPSPID
'killed merge can be completed with --continue' '
1021 git reset --hard c0 &&
1022 ! "$SHELL_PATH" -c '\''
1023 echo kill -TERM $$ >>.git/FAKE_EDITOR
1024 GIT_EDITOR=.git/FAKE_EDITOR
1026 exec git merge --no-ff --edit c1'\'' &&
1027 git merge --continue &&
1028 verify_parents $c0 $c1
1031 test_expect_success
'merge --quit' '
1032 git init merge-quit &&
1036 echo one >>base.t &&
1037 git commit -am one &&
1039 git checkout base &&
1040 echo two >>base.t &&
1041 git commit -am two &&
1042 test_must_fail git -c rerere.enabled=true merge one &&
1043 test_path_is_file .git/MERGE_HEAD &&
1044 test_path_is_file .git/MERGE_MODE &&
1045 test_path_is_file .git/MERGE_MSG &&
1046 git rerere status >rerere.before &&
1048 test_path_is_missing .git/MERGE_HEAD &&
1049 test_path_is_missing .git/MERGE_MODE &&
1050 test_path_is_missing .git/MERGE_MSG &&
1051 git rerere status >rerere.after &&
1052 test_must_be_empty rerere.after &&
1053 ! test_cmp rerere.after rerere.before
1057 test_expect_success
'merge suggests matching remote refname' '
1058 git commit --allow-empty -m not-local &&
1059 git update-ref refs/remotes/origin/not-local HEAD &&
1060 git reset --hard HEAD^ &&
1062 # This is white-box testing hackery; we happen to know
1063 # that reading packed refs is more picky about the memory
1064 # ownership of strings we pass to for_each_ref() callbacks.
1065 git pack-refs --all --prune &&
1067 test_must_fail git merge not-local 2>stderr &&
1068 grep origin/not-local stderr
1071 test_expect_success
'suggested names are not ambiguous' '
1072 git update-ref refs/heads/origin/not-local HEAD &&
1073 test_must_fail git merge not-local 2>stderr &&
1074 grep remotes/origin/not-local stderr