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
32 TEST_PASSES_SANITIZE_LEAK
=true
34 .
"$TEST_DIRECTORY"/lib-gpg.sh
36 test_write_lines
1 2 3 4 5 6 7 8 9 >file
38 test_write_lines
'1 X' 2 3 4 5 6 7 8 9 >file.1
39 test_write_lines
1 2 '3 X' 4 5 6 7 8 9 >file.3
40 test_write_lines
1 2 3 4 '5 X' 6 7 8 9 >file.5
41 test_write_lines
1 2 3 4 5 6 7 8 '9 X' >file.9
42 test_write_lines
1 2 3 4 5 6 7 8 '9 Y' >file.9y
43 test_write_lines
'1 X' 2 3 4 5 6 7 8 9 >result
.1
44 test_write_lines
'1 X' 2 3 4 '5 X' 6 7 8 9 >result
.1-5
45 test_write_lines
'1 X' 2 3 4 5 6 7 8 '9 X' >result
.1-9
46 test_write_lines
'1 X' 2 3 4 '5 X' 6 7 8 '9 X' >result
.1-5-9
47 test_write_lines
'1 X' 2 '3 X' 4 '5 X' 6 7 8 '9 X' >result
.1-3-5-9
48 test_write_lines
1 2 3 4 5 6 7 8 '9 Z' >result
.9z
50 create_merge_msgs
() {
51 echo "Merge tag 'c2'" >msg
.1-5 &&
52 echo "Merge tags 'c2' and 'c3'" >msg
.1-5-9 &&
54 echo "Squashed commit of the following:" &&
56 git log
--no-merges ^HEAD c1
59 echo "Squashed commit of the following:" &&
61 git log
--no-merges ^HEAD c2
64 echo "Squashed commit of the following:" &&
66 git log
--no-merges ^HEAD c2 c3
76 git update-index
--refresh &&
77 git
diff --exit-code &&
80 git show
-s --pretty=tformat
:%s HEAD
>msg.act
&&
86 echo "$1" >head.expected
&&
87 git rev-parse HEAD
>head.actual
&&
88 test_cmp
head.expected
head.actual
92 test_write_lines
"$@" >parents.expected
&&
97 git rev-parse HEAD^
$i >>parents.actual
&&
101 test_must_fail git rev-parse
--verify "HEAD^$i" &&
102 test_cmp parents.expected parents.actual
105 verify_mergeheads
() {
106 test_write_lines
"$@" >mergehead.expected
&&
109 git rev-parse
$sha1 ||
return 1
110 done <.git
/MERGE_HEAD
>mergehead.actual
&&
111 test_cmp mergehead.expected mergehead.actual
114 verify_no_mergehead
() {
115 ! test -e .git
/MERGE_HEAD
118 test_expect_success
'setup' '
121 git commit -m "commit 0" &&
123 c0=$(git rev-parse HEAD) &&
129 git commit -m "commit 1" &&
131 c1=$(git rev-parse HEAD) &&
132 git reset --hard "$c0" &&
136 git commit -m "commit 2" &&
138 c2=$(git rev-parse HEAD) &&
139 git reset --hard "$c0" &&
143 git commit -m "commit 7" &&
145 git reset --hard "$c0" &&
149 git commit -m "commit 3" &&
151 c3=$(git rev-parse HEAD) &&
152 git reset --hard "$c0" &&
156 test_debug
'git log --graph --decorate --oneline --all'
158 test_expect_success
'test option parsing' '
159 test_must_fail git merge -$ c1 &&
160 test_must_fail git merge --no-such c1 &&
161 test_must_fail git merge -s foobar c1 &&
162 test_must_fail git merge -s=foobar c1 &&
163 test_must_fail git merge -m &&
164 test_must_fail git merge --abort foobar &&
165 test_must_fail git merge --abort --quiet &&
166 test_must_fail git merge --continue foobar &&
167 test_must_fail git merge --continue --quiet &&
168 test_must_fail git merge
171 test_expect_success
'merge -h with invalid index' '
177 test_expect_code 129 git merge -h 2>usage
179 test_grep "[Uu]sage: git merge" broken/usage
182 test_expect_success
'reject non-strategy with a git-merge-foo name' '
183 test_must_fail git merge -s index c1
186 test_expect_success
'merge c0 with c1' '
187 echo "OBJID HEAD@{0}: merge c1: Fast-forward" >reflog.expected &&
189 git reset --hard c0 &&
191 verify_merge file result.1 &&
194 git reflog -1 >reflog.actual &&
195 sed "s/$_x05[0-9a-f]*/OBJID/g" reflog.actual >reflog.fuzzy &&
196 test_cmp reflog.expected reflog.fuzzy
199 test_debug
'git log --graph --decorate --oneline --all'
201 test_expect_success
'merge c0 with c1 with --ff-only' '
202 git reset --hard c0 &&
203 git merge --ff-only c1 &&
204 git merge --ff-only HEAD c0 c1 &&
205 verify_merge file result.1 &&
209 test_debug
'git log --graph --decorate --oneline --all'
211 test_expect_success
'merge from unborn branch' '
212 git checkout -f main &&
213 test_might_fail git branch -D kid &&
215 echo "OBJID HEAD@{0}: initial pull" >reflog.expected &&
217 git checkout --orphan kid &&
218 test_when_finished "git checkout -f main" &&
221 git merge --ff-only c1 &&
222 verify_merge file result.1 &&
225 git reflog -1 >reflog.actual &&
226 sed "s/$_x05[0-9a-f][0-9a-f]/OBJID/g" reflog.actual >reflog.fuzzy &&
227 test_cmp reflog.expected reflog.fuzzy
230 test_debug
'git log --graph --decorate --oneline --all'
232 test_expect_success
'merge c1 with c2' '
233 git reset --hard c1 &&
236 verify_merge file result.1-5 msg.1-5 &&
237 verify_parents $c1 $c2
240 test_expect_success
'merge c1 with c2 when index.lock exists' '
241 test_when_finished rm .git/index.lock &&
242 git reset --hard c1 &&
244 test_must_fail git merge c2 &&
245 test_path_is_missing .git/MERGE_HEAD &&
246 test_path_is_missing .git/MERGE_MODE &&
247 test_path_is_missing .git/MERGE_MSG
250 test_expect_success
'merge --squash c3 with c7' '
251 git reset --hard c3 &&
252 test_must_fail git merge --squash c7 &&
253 cat result.9z >file &&
254 git commit --no-edit -a &&
256 cat >expect <<-EOF &&
257 Squashed commit of the following:
264 git cat-file commit HEAD >raw &&
265 sed -e "1,/^$/d" raw >actual &&
266 test_cmp expect actual
269 test_expect_success
'merge --squash --autostash conflict does not attempt to apply autostash' '
270 git reset --hard c3 &&
273 test_must_fail git merge --squash c7 --autostash >out 2>err &&
274 ! grep "Applying autostash resulted in conflicts." err &&
275 grep "When finished, apply stashed changes with \`git stash pop\`" out
278 test_expect_success
'merge c3 with c7 with commit.cleanup = scissors' '
279 git config commit.cleanup scissors &&
280 git reset --hard c3 &&
281 test_must_fail git merge c7 &&
282 cat result.9z >file &&
283 git commit --no-edit -a &&
285 cat >expect <<-\EOF &&
286 Merge tag '"'"'c7'"'"'
288 # ------------------------ >8 ------------------------
289 # Do not modify or remove the line above.
290 # Everything below it will be ignored.
295 git cat-file commit HEAD >raw &&
296 sed -e "1,/^$/d" raw >actual &&
297 test_cmp expect actual
300 test_expect_success
'merge c3 with c7 with --squash commit.cleanup = scissors' '
301 git config commit.cleanup scissors &&
302 git reset --hard c3 &&
303 test_must_fail git merge --squash c7 &&
304 cat result.9z >file &&
305 git commit --no-edit -a &&
307 cat >expect <<-EOF &&
308 Squashed commit of the following:
312 # ------------------------ >8 ------------------------
313 # Do not modify or remove the line above.
314 # Everything below it will be ignored.
319 git cat-file commit HEAD >raw &&
320 sed -e "1,/^$/d" raw >actual &&
321 test_cmp expect actual
324 test_debug
'git log --graph --decorate --oneline --all'
326 test_expect_success
'merge c1 with c2 and c3' '
327 git reset --hard c1 &&
330 verify_merge file result.1-5-9 msg.1-5-9 &&
331 verify_parents $c1 $c2 $c3
334 test_debug
'git log --graph --decorate --oneline --all'
336 test_expect_success
'merges with --ff-only' '
337 git reset --hard c1 &&
339 test_must_fail git merge --ff-only c2 &&
340 test_must_fail git merge --ff-only c3 &&
341 test_must_fail git merge --ff-only c2 c3 &&
342 git reset --hard c0 &&
347 test_expect_success
'merges with merge.ff=only' '
348 git reset --hard c1 &&
350 test_config merge.ff "only" &&
351 test_must_fail git merge c2 &&
352 test_must_fail git merge c3 &&
353 test_must_fail git merge c2 c3 &&
354 git reset --hard c0 &&
359 test_expect_success
'merge c0 with c1 (no-commit)' '
360 git reset --hard c0 &&
361 git merge --no-commit c1 &&
362 verify_merge file result.1 &&
366 test_debug
'git log --graph --decorate --oneline --all'
368 test_expect_success
'merge c1 with c2 (no-commit)' '
369 git reset --hard c1 &&
370 git merge --no-commit c2 &&
371 verify_merge file result.1-5 &&
373 verify_mergeheads $c2
376 test_debug
'git log --graph --decorate --oneline --all'
378 test_expect_success
'merge c1 with c2 and c3 (no-commit)' '
379 git reset --hard c1 &&
380 git merge --no-commit c2 c3 &&
381 verify_merge file result.1-5-9 &&
383 verify_mergeheads $c2 $c3
386 test_debug
'git log --graph --decorate --oneline --all'
388 test_expect_success
'merge c0 with c1 (squash)' '
389 git reset --hard c0 &&
390 git merge --squash c1 &&
391 verify_merge file result.1 &&
393 verify_no_mergehead &&
394 test_cmp squash.1 .git/SQUASH_MSG
397 test_debug
'git log --graph --decorate --oneline --all'
399 test_expect_success
'merge c0 with c1 (squash, ff-only)' '
400 git reset --hard c0 &&
401 git merge --squash --ff-only c1 &&
402 verify_merge file result.1 &&
404 verify_no_mergehead &&
405 test_cmp squash.1 .git/SQUASH_MSG
408 test_debug
'git log --graph --decorate --oneline --all'
410 test_expect_success
'merge c1 with c2 (squash)' '
411 git reset --hard c1 &&
412 git merge --squash c2 &&
413 verify_merge file result.1-5 &&
415 verify_no_mergehead &&
416 test_cmp squash.1-5 .git/SQUASH_MSG
419 test_debug
'git log --graph --decorate --oneline --all'
421 test_expect_success
'unsuccessful merge of c1 with c2 (squash, ff-only)' '
422 git reset --hard c1 &&
423 test_must_fail git merge --squash --ff-only c2
426 test_debug
'git log --graph --decorate --oneline --all'
428 test_expect_success
'merge c1 with c2 and c3 (squash)' '
429 git reset --hard c1 &&
430 git merge --squash c2 c3 &&
431 verify_merge file result.1-5-9 &&
433 verify_no_mergehead &&
434 test_cmp squash.1-5-9 .git/SQUASH_MSG
437 test_debug
'git log --graph --decorate --oneline --all'
439 test_expect_success
'merge c1 with c2 (no-commit in config)' '
440 git reset --hard c1 &&
441 test_config branch.main.mergeoptions "--no-commit" &&
443 verify_merge file result.1-5 &&
445 verify_mergeheads $c2
448 test_debug
'git log --graph --decorate --oneline --all'
450 test_expect_success
'merge c1 with c2 (log in config)' '
451 git reset --hard c1 &&
452 git merge --log c2 &&
453 git show -s --pretty=tformat:%s%n%b >expect &&
455 test_config branch.main.mergeoptions "--log" &&
456 git reset --hard c1 &&
458 git show -s --pretty=tformat:%s%n%b >actual &&
460 test_cmp expect actual
463 test_expect_success
'merge c1 with c2 (log in config gets overridden)' '
464 git reset --hard c1 &&
466 git show -s --pretty=tformat:%s%n%b >expect &&
468 test_config branch.main.mergeoptions "--no-log" &&
469 test_config merge.log "true" &&
470 git reset --hard c1 &&
472 git show -s --pretty=tformat:%s%n%b >actual &&
474 test_cmp expect actual
477 test_expect_success
'merge c1 with c2 (squash in config)' '
478 git reset --hard c1 &&
479 test_config branch.main.mergeoptions "--squash" &&
481 verify_merge file result.1-5 &&
483 verify_no_mergehead &&
484 test_cmp squash.1-5 .git/SQUASH_MSG
487 test_debug
'git log --graph --decorate --oneline --all'
489 test_expect_success
'override config option -n with --summary' '
490 git reset --hard c1 &&
491 test_config branch.main.mergeoptions "-n" &&
493 git merge --summary c2 >diffstat.txt &&
494 verify_merge file result.1-5 msg.1-5 &&
495 verify_parents $c1 $c2 &&
496 if ! grep "^ file | *2 +-$" diffstat.txt
498 echo "[OOPS] diffstat was not generated with --summary"
503 test_expect_success
'override config option -n with --stat' '
504 git reset --hard c1 &&
505 test_config branch.main.mergeoptions "-n" &&
507 git merge --stat c2 >diffstat.txt &&
508 verify_merge file result.1-5 msg.1-5 &&
509 verify_parents $c1 $c2 &&
510 if ! grep "^ file | *2 +-$" diffstat.txt
512 echo "[OOPS] diffstat was not generated with --stat"
517 test_debug
'git log --graph --decorate --oneline --all'
519 test_expect_success
'override config option --stat' '
520 git reset --hard c1 &&
521 test_config branch.main.mergeoptions "--stat" &&
523 git merge -n c2 >diffstat.txt &&
524 verify_merge file result.1-5 msg.1-5 &&
525 verify_parents $c1 $c2 &&
526 if grep "^ file | *2 +-$" diffstat.txt
528 echo "[OOPS] diffstat was generated"
533 test_debug
'git log --graph --decorate --oneline --all'
535 test_expect_success
'merge c1 with c2 (override --no-commit)' '
536 git reset --hard c1 &&
537 test_config branch.main.mergeoptions "--no-commit" &&
539 git merge --commit c2 &&
540 verify_merge file result.1-5 msg.1-5 &&
541 verify_parents $c1 $c2
544 test_debug
'git log --graph --decorate --oneline --all'
546 test_expect_success
'merge c1 with c2 (override --squash)' '
547 git reset --hard c1 &&
548 test_config branch.main.mergeoptions "--squash" &&
550 git merge --no-squash c2 &&
551 verify_merge file result.1-5 msg.1-5 &&
552 verify_parents $c1 $c2
555 test_debug
'git log --graph --decorate --oneline --all'
557 test_expect_success
'merge c0 with c1 (no-ff)' '
558 git reset --hard c0 &&
560 git merge --no-ff c1 &&
561 verify_merge file result.1 &&
562 verify_parents $c0 $c1
565 test_debug
'git log --graph --decorate --oneline --all'
567 test_expect_success
'merge c0 with c1 (merge.ff=false)' '
568 git reset --hard c0 &&
569 test_config merge.ff "false" &&
572 verify_merge file result.1 &&
573 verify_parents $c0 $c1
575 test_debug
'git log --graph --decorate --oneline --all'
577 test_expect_success
'combine branch.main.mergeoptions with merge.ff' '
578 git reset --hard c0 &&
579 test_config branch.main.mergeoptions "--ff" &&
580 test_config merge.ff "false" &&
583 verify_merge file result.1 &&
587 test_expect_success
'tolerate unknown values for merge.ff' '
588 git reset --hard c0 &&
589 test_config merge.ff "something-new" &&
591 git merge c1 2>message &&
593 test_must_be_empty message
596 test_expect_success
'combining --squash and --no-ff is refused' '
597 git reset --hard c0 &&
598 test_must_fail git merge --squash --no-ff c1 &&
599 test_must_fail git merge --no-ff --squash c1
602 test_expect_success
'combining --squash and --commit is refused' '
603 git reset --hard c0 &&
604 test_must_fail git merge --squash --commit c1 &&
605 test_must_fail git merge --commit --squash c1
608 test_expect_success
'option --ff-only overwrites --no-ff' '
609 git merge --no-ff --ff-only c1 &&
610 test_must_fail git merge --no-ff --ff-only c2
613 test_expect_success
'option --no-ff overrides merge.ff=only config' '
614 git reset --hard c0 &&
615 test_config merge.ff only &&
619 test_expect_success
'merge c0 with c1 (ff overrides no-ff)' '
620 git reset --hard c0 &&
621 test_config branch.main.mergeoptions "--no-ff" &&
623 verify_merge file result.1 &&
627 test_expect_success
'merge log message' '
628 git reset --hard c0 &&
629 git merge --no-log c2 &&
630 git show -s --pretty=format:%b HEAD >msg.act &&
631 test_must_be_empty msg.act &&
633 git reset --hard c0 &&
634 test_config branch.main.mergeoptions "--no-ff" &&
635 git merge --no-log c2 &&
636 git show -s --pretty=format:%b HEAD >msg.act &&
637 test_must_be_empty msg.act &&
639 git merge --log c3 &&
640 git show -s --pretty=format:%b HEAD >msg.act &&
641 test_cmp msg.log msg.act &&
643 git reset --hard HEAD^ &&
644 test_config merge.log "yes" &&
646 git show -s --pretty=format:%b HEAD >msg.act &&
647 test_cmp msg.log msg.act
650 test_debug
'git log --graph --decorate --oneline --all'
652 test_expect_success
'merge c1 with c0, c2, c0, and c1' '
653 git reset --hard c1 &&
655 git merge c0 c2 c0 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 c1 with c0, c2, c0, and c1' '
663 git reset --hard c1 &&
665 git merge c0 c2 c0 c1 &&
666 verify_merge file result.1-5 &&
667 verify_parents $c1 $c2
670 test_debug
'git log --graph --decorate --oneline --all'
672 test_expect_success
'merge c1 with c1 and c2' '
673 git reset --hard c1 &&
676 verify_merge file result.1-5 &&
677 verify_parents $c1 $c2
680 test_debug
'git log --graph --decorate --oneline --all'
682 test_expect_success
'merge fast-forward in a dirty tree' '
683 git reset --hard c0 &&
690 test_debug
'git log --graph --decorate --oneline --all'
692 test_expect_success
'in-index merge' '
693 git reset --hard c0 &&
694 git merge --no-ff -s resolve c1 >out &&
695 test_grep "Wonderful." out &&
696 verify_parents $c0 $c1
699 test_debug
'git log --graph --decorate --oneline --all'
701 test_expect_success
'refresh the index before merging' '
702 git reset --hard c1 &&
703 cp file file.n && mv -f file.n file &&
707 test_expect_success
'merge with --autostash' '
708 git reset --hard c1 &&
709 git merge-file file file.orig file.9 &&
710 git merge --autostash c2 2>err &&
711 test_grep "Applied autostash." err &&
712 git show HEAD:file >merge-result &&
713 test_cmp result.1-5 merge-result &&
714 test_cmp result.1-5-9 file
717 test_expect_success
'merge with merge.autoStash' '
718 test_config merge.autoStash true &&
719 git reset --hard c1 &&
720 git merge-file file file.orig file.9 &&
721 git merge c2 2>err &&
722 test_grep "Applied autostash." err &&
723 git show HEAD:file >merge-result &&
724 test_cmp result.1-5 merge-result &&
725 test_cmp result.1-5-9 file
728 test_expect_success
'fast-forward merge with --autostash' '
729 git reset --hard c0 &&
730 git merge-file file file.orig file.5 &&
731 git merge --autostash c1 2>err &&
732 test_grep "Applied autostash." err &&
733 test_cmp result.1-5 file
736 test_expect_success
'failed fast-forward merge with --autostash' '
737 git reset --hard c0 &&
738 git merge-file file file.orig file.5 &&
740 test_when_finished "rm other" &&
741 test_must_fail git merge --autostash c1 2>err &&
742 test_grep "Applied autostash." err &&
746 test_expect_success
'octopus merge with --autostash' '
747 git reset --hard c1 &&
748 git merge-file file file.orig file.3 &&
749 git merge --autostash c2 c3 2>err &&
750 test_grep "Applied autostash." err &&
751 git show HEAD:file >merge-result &&
752 test_cmp result.1-5-9 merge-result &&
753 test_cmp result.1-3-5-9 file
756 test_expect_success
'failed merge (exit 2) with --autostash' '
757 git reset --hard c1 &&
758 git merge-file file file.orig file.5 &&
759 test_must_fail git merge -s recursive --autostash c2 c3 2>err &&
760 test_grep "Applied autostash." err &&
761 test_cmp result.1-5 file
764 test_expect_success
'conflicted merge with --autostash, --abort restores stash' '
765 git reset --hard c3 &&
767 test_must_fail git merge --autostash c7 &&
768 git merge --abort 2>err &&
769 test_grep "Applied autostash." err &&
773 test_expect_success
'completed merge (git commit) with --no-commit and --autostash' '
774 git reset --hard c1 &&
775 git merge-file file file.orig file.9 &&
777 git merge --no-commit --autostash c2 &&
778 git stash show -p MERGE_AUTOSTASH >actual &&
779 test_cmp expect actual &&
781 test_grep "Applied autostash." err &&
782 git show HEAD:file >merge-result &&
783 test_cmp result.1-5 merge-result &&
784 test_cmp result.1-5-9 file
787 test_expect_success
'completed merge (git merge --continue) with --no-commit and --autostash' '
788 git reset --hard c1 &&
789 git merge-file file file.orig file.9 &&
791 git merge --no-commit --autostash c2 &&
792 git stash show -p MERGE_AUTOSTASH >actual &&
793 test_cmp expect actual &&
794 git merge --continue 2>err &&
795 test_grep "Applied autostash." err &&
796 git show HEAD:file >merge-result &&
797 test_cmp result.1-5 merge-result &&
798 test_cmp result.1-5-9 file
801 test_expect_success
'aborted merge (merge --abort) with --no-commit and --autostash' '
802 git reset --hard c1 &&
803 git merge-file file file.orig file.9 &&
805 git merge --no-commit --autostash c2 &&
806 git stash show -p MERGE_AUTOSTASH >actual &&
807 test_cmp expect actual &&
808 git merge --abort 2>err &&
809 test_grep "Applied autostash." err &&
811 test_cmp expect actual
814 test_expect_success
'aborted merge (reset --hard) with --no-commit and --autostash' '
815 git reset --hard c1 &&
816 git merge-file file file.orig file.9 &&
818 git merge --no-commit --autostash c2 &&
819 git stash show -p MERGE_AUTOSTASH >actual &&
820 test_cmp expect actual &&
821 git reset --hard 2>err &&
822 test_grep "Autostash exists; creating a new stash entry." err &&
826 test_expect_success
'quit merge with --no-commit and --autostash' '
827 git reset --hard c1 &&
828 git merge-file file file.orig file.9 &&
830 git merge --no-commit --autostash c2 &&
831 git stash show -p MERGE_AUTOSTASH >actual &&
832 test_cmp expect actual &&
833 git diff HEAD >expect &&
834 git merge --quit 2>err &&
835 test_grep "Autostash exists; creating a new stash entry." err &&
836 git diff HEAD >actual &&
837 test_cmp expect actual
840 test_expect_success
'merge with conflicted --autostash changes' '
841 git reset --hard c1 &&
842 git merge-file file file.orig file.9y &&
844 test_when_finished "test_might_fail git stash drop" &&
845 git merge --autostash c3 2>err &&
846 test_grep "Applying autostash resulted in conflicts." err &&
847 git show HEAD:file >merge-result &&
848 test_cmp result.1-9 merge-result &&
849 git stash show -p >actual &&
850 test_cmp expect actual
853 cat >expected.branch
<<\EOF
854 Merge branch
'c5-branch' (early part
)
856 cat >expected.tag
<<\EOF
860 test_expect_success
'merge early part of c2' '
861 git reset --hard c3 &&
870 git reset --hard c3 &&
875 git branch -f c5-branch c5 &&
876 git merge c5-branch~1 &&
877 git show -s --pretty=tformat:%s HEAD >actual.branch &&
878 git reset --keep HEAD^ &&
880 git show -s --pretty=tformat:%s HEAD >actual.tag &&
881 test_cmp expected.branch actual.branch &&
882 test_cmp expected.tag actual.tag
885 test_debug
'git log --graph --decorate --oneline --all'
887 test_expect_success
'merge --no-ff --no-commit && commit' '
888 git reset --hard c0 &&
889 git merge --no-ff --no-commit c1 &&
890 EDITOR=: git commit &&
891 verify_parents $c0 $c1
894 test_debug
'git log --graph --decorate --oneline --all'
896 test_expect_success
'amending no-ff merge commit' '
897 EDITOR=: git commit --amend &&
898 verify_parents $c0 $c1
901 test_debug
'git log --graph --decorate --oneline --all'
905 # Add a new message string that was not in the template
907 echo "Merge work done on the side branch c1"
910 ) >"$1.tmp" && mv "$1.tmp" "$1"
911 # strip comments and blank lines from end of message
912 sed -e '/^#/d' "$1" |
sed -e :a
-e '/^\n*$/{$d;N;ba' -e '}' >expected
916 test_expect_success
'merge --no-ff --edit' '
917 git reset --hard c0 &&
918 EDITOR=./editor git merge --no-ff --edit c1 &&
919 verify_parents $c0 $c1 &&
920 git cat-file commit HEAD >raw &&
921 grep "work done on the side branch" raw &&
922 sed "1,/^$/d" >actual raw &&
923 test_cmp expected actual
926 test_expect_success
'merge annotated/signed tag w/o tracking' '
927 test_when_finished "rm -rf dst; git tag -d anno1" &&
928 git tag -a -m "anno c1" anno1 c1 &&
930 git rev-parse c1 >dst/expect &&
932 # c0 fast-forwards to c1 but because this repository
933 # is not a "downstream" whose refs/tags follows along
934 # tag from the "upstream", this pull defaults to --no-ff
938 git rev-parse HEAD^2 >actual &&
939 test_cmp expect actual
943 test_expect_success
'merge annotated/signed tag w/ tracking' '
944 test_when_finished "rm -rf dst; git tag -d anno1" &&
945 git tag -a -m "anno c1" anno1 c1 &&
947 git rev-parse c1 >dst/expect &&
949 # c0 fast-forwards to c1 and because this repository
950 # is a "downstream" whose refs/tags follows along
951 # tag from the "upstream", this pull defaults to --ff
953 git remote add origin .. &&
954 git pull origin c0 &&
957 git rev-parse HEAD >actual &&
958 test_cmp expect actual
962 test_expect_success GPG
'merge --ff-only tag' '
963 git reset --hard c0 &&
964 git commit --allow-empty -m "A newer commit" &&
965 git tag -s -m "A newer commit" signed &&
966 git reset --hard c0 &&
968 git merge --ff-only signed &&
969 git rev-parse signed^0 >expect &&
970 git rev-parse HEAD >actual &&
971 test_cmp expect actual
974 test_expect_success GPG
'merge --no-edit tag should skip editor' '
975 git reset --hard c0 &&
976 git commit --allow-empty -m "A newer commit" &&
977 git tag -f -s -m "A newer commit" signed &&
978 git reset --hard c0 &&
980 EDITOR=false git merge --no-edit --no-ff signed &&
981 git rev-parse signed^0 >expect &&
982 git rev-parse HEAD^2 >actual &&
983 test_cmp expect actual
986 test_expect_success
'set up mod-256 conflict scenario' '
987 # 256 near-identical stanzas...
988 for i in $(test_seq 1 256); do
989 for j in 1 2 3 4 5; do
990 echo $i-$j || return 1
994 git commit -m base &&
996 # one side changes the first line of each to "main"
997 sed s/-1/-main/ file >tmp &&
999 git commit -am main &&
1001 # and the other to "side"; merging the two will
1002 # yield 256 separate conflicts
1003 git checkout -b side HEAD^ &&
1004 sed s/-1/-side/ file >tmp &&
1009 test_expect_success
'merge detects mod-256 conflicts (recursive)' '
1011 test_must_fail git merge -s recursive main
1014 test_expect_success
'merge detects mod-256 conflicts (resolve)' '
1016 test_must_fail git merge -s resolve main
1019 test_expect_success
'merge nothing into void' '
1023 git remote add up .. &&
1025 test_must_fail git merge FETCH_HEAD
1029 test_expect_success
'merge can be completed with --continue' '
1030 git reset --hard c0 &&
1031 git merge --no-ff --no-commit c1 &&
1032 git merge --continue &&
1033 verify_parents $c0 $c1
1036 write_script .git
/FAKE_EDITOR
<<EOF
1037 # kill -TERM command added below.
1040 test_expect_success EXECKEEPSPID
'killed merge can be completed with --continue' '
1041 git reset --hard c0 &&
1042 ! "$SHELL_PATH" -c '\''
1043 echo kill -TERM $$ >>.git/FAKE_EDITOR
1044 GIT_EDITOR=.git/FAKE_EDITOR
1046 exec git merge --no-ff --edit c1'\'' &&
1047 git merge --continue &&
1048 verify_parents $c0 $c1
1051 test_expect_success
'merge --quit' '
1052 git init merge-quit &&
1056 echo one >>base.t &&
1057 git commit -am one &&
1059 git checkout base &&
1060 echo two >>base.t &&
1061 git commit -am two &&
1062 test_must_fail git -c rerere.enabled=true merge one &&
1063 test_path_is_file .git/MERGE_HEAD &&
1064 test_path_is_file .git/MERGE_MODE &&
1065 test_path_is_file .git/MERGE_MSG &&
1066 git rerere status >rerere.before &&
1068 test_path_is_missing .git/MERGE_HEAD &&
1069 test_path_is_missing .git/MERGE_MODE &&
1070 test_path_is_missing .git/MERGE_MSG &&
1071 git rerere status >rerere.after &&
1072 test_must_be_empty rerere.after &&
1073 ! test_cmp rerere.after rerere.before
1077 test_expect_success
'merge suggests matching remote refname' '
1078 git commit --allow-empty -m not-local &&
1079 git update-ref refs/remotes/origin/not-local HEAD &&
1080 git reset --hard HEAD^ &&
1082 # This is white-box testing hackery; we happen to know
1083 # that reading packed refs is more picky about the memory
1084 # ownership of strings we pass to for_each_ref() callbacks.
1085 git pack-refs --all --prune &&
1087 test_must_fail git merge not-local 2>stderr &&
1088 grep origin/not-local stderr
1091 test_expect_success
'suggested names are not ambiguous' '
1092 git update-ref refs/heads/origin/not-local HEAD &&
1093 test_must_fail git merge not-local 2>stderr &&
1094 grep remotes/origin/not-local stderr