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
&&
108 git rev-parse
$sha1 ||
return 1
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 --squash --autostash conflict does not attempt to apply autostash' '
259 git reset --hard c3 &&
262 test_must_fail git merge --squash c7 --autostash >out 2>err &&
263 ! grep "Applying autostash resulted in conflicts." err &&
264 grep "When finished, apply stashed changes with \`git stash pop\`" out
267 test_expect_success
'merge c3 with c7 with commit.cleanup = scissors' '
268 git config commit.cleanup scissors &&
269 git reset --hard c3 &&
270 test_must_fail git merge c7 &&
271 cat result.9z >file &&
272 git commit --no-edit -a &&
274 cat >expect <<-\EOF &&
275 Merge tag '"'"'c7'"'"'
277 # ------------------------ >8 ------------------------
278 # Do not modify or remove the line above.
279 # Everything below it will be ignored.
284 git cat-file commit HEAD >raw &&
285 sed -e "1,/^$/d" raw >actual &&
286 test_cmp expect actual
289 test_expect_success
'merge c3 with c7 with --squash commit.cleanup = scissors' '
290 git config commit.cleanup scissors &&
291 git reset --hard c3 &&
292 test_must_fail git merge --squash c7 &&
293 cat result.9z >file &&
294 git commit --no-edit -a &&
296 cat >expect <<-EOF &&
297 Squashed commit of the following:
301 # ------------------------ >8 ------------------------
302 # Do not modify or remove the line above.
303 # Everything below it will be ignored.
308 git cat-file commit HEAD >raw &&
309 sed -e "1,/^$/d" raw >actual &&
310 test_cmp expect actual
313 test_debug
'git log --graph --decorate --oneline --all'
315 test_expect_success
'merge c1 with c2 and c3' '
316 git reset --hard c1 &&
319 verify_merge file result.1-5-9 msg.1-5-9 &&
320 verify_parents $c1 $c2 $c3
323 test_debug
'git log --graph --decorate --oneline --all'
325 test_expect_success
'merges with --ff-only' '
326 git reset --hard c1 &&
328 test_must_fail git merge --ff-only c2 &&
329 test_must_fail git merge --ff-only c3 &&
330 test_must_fail git merge --ff-only c2 c3 &&
331 git reset --hard c0 &&
336 test_expect_success
'merges with merge.ff=only' '
337 git reset --hard c1 &&
339 test_config merge.ff "only" &&
340 test_must_fail git merge c2 &&
341 test_must_fail git merge c3 &&
342 test_must_fail git merge c2 c3 &&
343 git reset --hard c0 &&
348 test_expect_success
'merge c0 with c1 (no-commit)' '
349 git reset --hard c0 &&
350 git merge --no-commit c1 &&
351 verify_merge file result.1 &&
355 test_debug
'git log --graph --decorate --oneline --all'
357 test_expect_success
'merge c1 with c2 (no-commit)' '
358 git reset --hard c1 &&
359 git merge --no-commit c2 &&
360 verify_merge file result.1-5 &&
362 verify_mergeheads $c2
365 test_debug
'git log --graph --decorate --oneline --all'
367 test_expect_success
'merge c1 with c2 and c3 (no-commit)' '
368 git reset --hard c1 &&
369 git merge --no-commit c2 c3 &&
370 verify_merge file result.1-5-9 &&
372 verify_mergeheads $c2 $c3
375 test_debug
'git log --graph --decorate --oneline --all'
377 test_expect_success
'merge c0 with c1 (squash)' '
378 git reset --hard c0 &&
379 git merge --squash c1 &&
380 verify_merge file result.1 &&
382 verify_no_mergehead &&
383 test_cmp squash.1 .git/SQUASH_MSG
386 test_debug
'git log --graph --decorate --oneline --all'
388 test_expect_success
'merge c0 with c1 (squash, ff-only)' '
389 git reset --hard c0 &&
390 git merge --squash --ff-only 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 c1 with c2 (squash)' '
400 git reset --hard c1 &&
401 git merge --squash c2 &&
402 verify_merge file result.1-5 &&
404 verify_no_mergehead &&
405 test_cmp squash.1-5 .git/SQUASH_MSG
408 test_debug
'git log --graph --decorate --oneline --all'
410 test_expect_success
'unsuccessful merge of c1 with c2 (squash, ff-only)' '
411 git reset --hard c1 &&
412 test_must_fail git merge --squash --ff-only c2
415 test_debug
'git log --graph --decorate --oneline --all'
417 test_expect_success
'merge c1 with c2 and c3 (squash)' '
418 git reset --hard c1 &&
419 git merge --squash c2 c3 &&
420 verify_merge file result.1-5-9 &&
422 verify_no_mergehead &&
423 test_cmp squash.1-5-9 .git/SQUASH_MSG
426 test_debug
'git log --graph --decorate --oneline --all'
428 test_expect_success
'merge c1 with c2 (no-commit in config)' '
429 git reset --hard c1 &&
430 test_config branch.main.mergeoptions "--no-commit" &&
432 verify_merge file result.1-5 &&
434 verify_mergeheads $c2
437 test_debug
'git log --graph --decorate --oneline --all'
439 test_expect_success
'merge c1 with c2 (log in config)' '
440 git reset --hard c1 &&
441 git merge --log c2 &&
442 git show -s --pretty=tformat:%s%n%b >expect &&
444 test_config branch.main.mergeoptions "--log" &&
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 (log in config gets overridden)' '
453 git reset --hard c1 &&
455 git show -s --pretty=tformat:%s%n%b >expect &&
457 test_config branch.main.mergeoptions "--no-log" &&
458 test_config merge.log "true" &&
459 git reset --hard c1 &&
461 git show -s --pretty=tformat:%s%n%b >actual &&
463 test_cmp expect actual
466 test_expect_success
'merge c1 with c2 (squash in config)' '
467 git reset --hard c1 &&
468 test_config branch.main.mergeoptions "--squash" &&
470 verify_merge file result.1-5 &&
472 verify_no_mergehead &&
473 test_cmp squash.1-5 .git/SQUASH_MSG
476 test_debug
'git log --graph --decorate --oneline --all'
478 test_expect_success
'override config option -n with --summary' '
479 git reset --hard c1 &&
480 test_config branch.main.mergeoptions "-n" &&
482 git merge --summary 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 --summary"
492 test_expect_success
'override config option -n with --stat' '
493 git reset --hard c1 &&
494 test_config branch.main.mergeoptions "-n" &&
496 git merge --stat c2 >diffstat.txt &&
497 verify_merge file result.1-5 msg.1-5 &&
498 verify_parents $c1 $c2 &&
499 if ! grep "^ file | *2 +-$" diffstat.txt
501 echo "[OOPS] diffstat was not generated with --stat"
506 test_debug
'git log --graph --decorate --oneline --all'
508 test_expect_success
'override config option --stat' '
509 git reset --hard c1 &&
510 test_config branch.main.mergeoptions "--stat" &&
512 git merge -n c2 >diffstat.txt &&
513 verify_merge file result.1-5 msg.1-5 &&
514 verify_parents $c1 $c2 &&
515 if grep "^ file | *2 +-$" diffstat.txt
517 echo "[OOPS] diffstat was generated"
522 test_debug
'git log --graph --decorate --oneline --all'
524 test_expect_success
'merge c1 with c2 (override --no-commit)' '
525 git reset --hard c1 &&
526 test_config branch.main.mergeoptions "--no-commit" &&
528 git merge --commit c2 &&
529 verify_merge file result.1-5 msg.1-5 &&
530 verify_parents $c1 $c2
533 test_debug
'git log --graph --decorate --oneline --all'
535 test_expect_success
'merge c1 with c2 (override --squash)' '
536 git reset --hard c1 &&
537 test_config branch.main.mergeoptions "--squash" &&
539 git merge --no-squash 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 c0 with c1 (no-ff)' '
547 git reset --hard c0 &&
549 git merge --no-ff c1 &&
550 verify_merge file result.1 &&
551 verify_parents $c0 $c1
554 test_debug
'git log --graph --decorate --oneline --all'
556 test_expect_success
'merge c0 with c1 (merge.ff=false)' '
557 git reset --hard c0 &&
558 test_config merge.ff "false" &&
561 verify_merge file result.1 &&
562 verify_parents $c0 $c1
564 test_debug
'git log --graph --decorate --oneline --all'
566 test_expect_success
'combine branch.main.mergeoptions with merge.ff' '
567 git reset --hard c0 &&
568 test_config branch.main.mergeoptions "--ff" &&
569 test_config merge.ff "false" &&
572 verify_merge file result.1 &&
576 test_expect_success
'tolerate unknown values for merge.ff' '
577 git reset --hard c0 &&
578 test_config merge.ff "something-new" &&
580 git merge c1 2>message &&
582 test_must_be_empty message
585 test_expect_success
'combining --squash and --no-ff is refused' '
586 git reset --hard c0 &&
587 test_must_fail git merge --squash --no-ff c1 &&
588 test_must_fail git merge --no-ff --squash c1
591 test_expect_success
'combining --squash and --commit is refused' '
592 git reset --hard c0 &&
593 test_must_fail git merge --squash --commit c1 &&
594 test_must_fail git merge --commit --squash c1
597 test_expect_success
'option --ff-only overwrites --no-ff' '
598 git merge --no-ff --ff-only c1 &&
599 test_must_fail git merge --no-ff --ff-only c2
602 test_expect_success
'option --no-ff overrides merge.ff=only config' '
603 git reset --hard c0 &&
604 test_config merge.ff only &&
608 test_expect_success
'merge c0 with c1 (ff overrides no-ff)' '
609 git reset --hard c0 &&
610 test_config branch.main.mergeoptions "--no-ff" &&
612 verify_merge file result.1 &&
616 test_expect_success
'merge log message' '
617 git reset --hard c0 &&
618 git merge --no-log c2 &&
619 git show -s --pretty=format:%b HEAD >msg.act &&
620 test_must_be_empty msg.act &&
622 git reset --hard c0 &&
623 test_config branch.main.mergeoptions "--no-ff" &&
624 git merge --no-log c2 &&
625 git show -s --pretty=format:%b HEAD >msg.act &&
626 test_must_be_empty msg.act &&
628 git merge --log c3 &&
629 git show -s --pretty=format:%b HEAD >msg.act &&
630 test_cmp msg.log msg.act &&
632 git reset --hard HEAD^ &&
633 test_config merge.log "yes" &&
635 git show -s --pretty=format:%b HEAD >msg.act &&
636 test_cmp msg.log msg.act
639 test_debug
'git log --graph --decorate --oneline --all'
641 test_expect_success
'merge c1 with c0, c2, c0, and c1' '
642 git reset --hard c1 &&
644 git merge c0 c2 c0 c1 &&
645 verify_merge file result.1-5 &&
646 verify_parents $c1 $c2
649 test_debug
'git log --graph --decorate --oneline --all'
651 test_expect_success
'merge c1 with c0, c2, c0, and c1' '
652 git reset --hard c1 &&
654 git merge c0 c2 c0 c1 &&
655 verify_merge file result.1-5 &&
656 verify_parents $c1 $c2
659 test_debug
'git log --graph --decorate --oneline --all'
661 test_expect_success
'merge c1 with c1 and c2' '
662 git reset --hard c1 &&
665 verify_merge file result.1-5 &&
666 verify_parents $c1 $c2
669 test_debug
'git log --graph --decorate --oneline --all'
671 test_expect_success
'merge fast-forward in a dirty tree' '
672 git reset --hard c0 &&
679 test_debug
'git log --graph --decorate --oneline --all'
681 test_expect_success
'in-index merge' '
682 git reset --hard c0 &&
683 git merge --no-ff -s resolve c1 >out &&
684 test_i18ngrep "Wonderful." out &&
685 verify_parents $c0 $c1
688 test_debug
'git log --graph --decorate --oneline --all'
690 test_expect_success
'refresh the index before merging' '
691 git reset --hard c1 &&
692 cp file file.n && mv -f file.n file &&
696 test_expect_success
'merge with --autostash' '
697 git reset --hard c1 &&
698 git merge-file file file.orig file.9 &&
699 git merge --autostash c2 2>err &&
700 test_i18ngrep "Applied autostash." err &&
701 git show HEAD:file >merge-result &&
702 test_cmp result.1-5 merge-result &&
703 test_cmp result.1-5-9 file
706 test_expect_success
'merge with merge.autoStash' '
707 test_config merge.autoStash true &&
708 git reset --hard c1 &&
709 git merge-file file file.orig file.9 &&
710 git merge c2 2>err &&
711 test_i18ngrep "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
'fast-forward merge with --autostash' '
718 git reset --hard c0 &&
719 git merge-file file file.orig file.5 &&
720 git merge --autostash c1 2>err &&
721 test_i18ngrep "Applied autostash." err &&
722 test_cmp result.1-5 file
725 test_expect_success
'failed fast-forward merge with --autostash' '
726 git reset --hard c0 &&
727 git merge-file file file.orig file.5 &&
729 test_when_finished "rm other" &&
730 test_must_fail git merge --autostash c1 2>err &&
731 test_i18ngrep "Applied autostash." err &&
735 test_expect_success
'octopus merge with --autostash' '
736 git reset --hard c1 &&
737 git merge-file file file.orig file.3 &&
738 git merge --autostash c2 c3 2>err &&
739 test_i18ngrep "Applied autostash." err &&
740 git show HEAD:file >merge-result &&
741 test_cmp result.1-5-9 merge-result &&
742 test_cmp result.1-3-5-9 file
745 test_expect_success
'failed merge (exit 2) with --autostash' '
746 git reset --hard c1 &&
747 git merge-file file file.orig file.5 &&
748 test_must_fail git merge -s recursive --autostash c2 c3 2>err &&
749 test_i18ngrep "Applied autostash." err &&
750 test_cmp result.1-5 file
753 test_expect_success
'conflicted merge with --autostash, --abort restores stash' '
754 git reset --hard c3 &&
756 test_must_fail git merge --autostash c7 &&
757 git merge --abort 2>err &&
758 test_i18ngrep "Applied autostash." err &&
762 test_expect_success
'completed merge (git commit) with --no-commit and --autostash' '
763 git reset --hard c1 &&
764 git merge-file file file.orig file.9 &&
766 git merge --no-commit --autostash c2 &&
767 git stash show -p MERGE_AUTOSTASH >actual &&
768 test_cmp expect actual &&
770 test_i18ngrep "Applied autostash." err &&
771 git show HEAD:file >merge-result &&
772 test_cmp result.1-5 merge-result &&
773 test_cmp result.1-5-9 file
776 test_expect_success
'completed merge (git merge --continue) with --no-commit and --autostash' '
777 git reset --hard c1 &&
778 git merge-file file file.orig file.9 &&
780 git merge --no-commit --autostash c2 &&
781 git stash show -p MERGE_AUTOSTASH >actual &&
782 test_cmp expect actual &&
783 git merge --continue 2>err &&
784 test_i18ngrep "Applied autostash." err &&
785 git show HEAD:file >merge-result &&
786 test_cmp result.1-5 merge-result &&
787 test_cmp result.1-5-9 file
790 test_expect_success
'aborted merge (merge --abort) with --no-commit and --autostash' '
791 git reset --hard c1 &&
792 git merge-file file file.orig file.9 &&
794 git merge --no-commit --autostash c2 &&
795 git stash show -p MERGE_AUTOSTASH >actual &&
796 test_cmp expect actual &&
797 git merge --abort 2>err &&
798 test_i18ngrep "Applied autostash." err &&
800 test_cmp expect actual
803 test_expect_success
'aborted merge (reset --hard) with --no-commit and --autostash' '
804 git reset --hard c1 &&
805 git merge-file file file.orig file.9 &&
807 git merge --no-commit --autostash c2 &&
808 git stash show -p MERGE_AUTOSTASH >actual &&
809 test_cmp expect actual &&
810 git reset --hard 2>err &&
811 test_i18ngrep "Autostash exists; creating a new stash entry." err &&
815 test_expect_success
'quit merge with --no-commit and --autostash' '
816 git reset --hard c1 &&
817 git merge-file file file.orig file.9 &&
819 git merge --no-commit --autostash c2 &&
820 git stash show -p MERGE_AUTOSTASH >actual &&
821 test_cmp expect actual &&
822 git diff HEAD >expect &&
823 git merge --quit 2>err &&
824 test_i18ngrep "Autostash exists; creating a new stash entry." err &&
825 git diff HEAD >actual &&
826 test_cmp expect actual
829 test_expect_success
'merge with conflicted --autostash changes' '
830 git reset --hard c1 &&
831 git merge-file file file.orig file.9y &&
833 test_when_finished "test_might_fail git stash drop" &&
834 git merge --autostash c3 2>err &&
835 test_i18ngrep "Applying autostash resulted in conflicts." err &&
836 git show HEAD:file >merge-result &&
837 test_cmp result.1-9 merge-result &&
838 git stash show -p >actual &&
839 test_cmp expect actual
842 cat >expected.branch
<<\EOF
843 Merge branch
'c5-branch' (early part
)
845 cat >expected.tag
<<\EOF
849 test_expect_success
'merge early part of c2' '
850 git reset --hard c3 &&
859 git reset --hard c3 &&
864 git branch -f c5-branch c5 &&
865 git merge c5-branch~1 &&
866 git show -s --pretty=tformat:%s HEAD >actual.branch &&
867 git reset --keep HEAD^ &&
869 git show -s --pretty=tformat:%s HEAD >actual.tag &&
870 test_cmp expected.branch actual.branch &&
871 test_cmp expected.tag actual.tag
874 test_debug
'git log --graph --decorate --oneline --all'
876 test_expect_success
'merge --no-ff --no-commit && commit' '
877 git reset --hard c0 &&
878 git merge --no-ff --no-commit c1 &&
879 EDITOR=: git commit &&
880 verify_parents $c0 $c1
883 test_debug
'git log --graph --decorate --oneline --all'
885 test_expect_success
'amending no-ff merge commit' '
886 EDITOR=: git commit --amend &&
887 verify_parents $c0 $c1
890 test_debug
'git log --graph --decorate --oneline --all'
894 # Add a new message string that was not in the template
896 echo "Merge work done on the side branch c1"
899 ) >"$1.tmp" && mv "$1.tmp" "$1"
900 # strip comments and blank lines from end of message
901 sed -e '/^#/d' "$1" |
sed -e :a
-e '/^\n*$/{$d;N;ba' -e '}' >expected
905 test_expect_success
'merge --no-ff --edit' '
906 git reset --hard c0 &&
907 EDITOR=./editor git merge --no-ff --edit c1 &&
908 verify_parents $c0 $c1 &&
909 git cat-file commit HEAD >raw &&
910 grep "work done on the side branch" raw &&
911 sed "1,/^$/d" >actual raw &&
912 test_cmp expected actual
915 test_expect_success
'merge annotated/signed tag w/o tracking' '
916 test_when_finished "rm -rf dst; git tag -d anno1" &&
917 git tag -a -m "anno c1" anno1 c1 &&
919 git rev-parse c1 >dst/expect &&
921 # c0 fast-forwards to c1 but because this repository
922 # is not a "downstream" whose refs/tags follows along
923 # tag from the "upstream", this pull defaults to --no-ff
927 git rev-parse HEAD^2 >actual &&
928 test_cmp expect actual
932 test_expect_success
'merge annotated/signed tag w/ tracking' '
933 test_when_finished "rm -rf dst; git tag -d anno1" &&
934 git tag -a -m "anno c1" anno1 c1 &&
936 git rev-parse c1 >dst/expect &&
938 # c0 fast-forwards to c1 and because this repository
939 # is a "downstream" whose refs/tags follows along
940 # tag from the "upstream", this pull defaults to --ff
942 git remote add origin .. &&
943 git pull origin c0 &&
946 git rev-parse HEAD >actual &&
947 test_cmp expect actual
951 test_expect_success GPG
'merge --ff-only tag' '
952 git reset --hard c0 &&
953 git commit --allow-empty -m "A newer commit" &&
954 git tag -s -m "A newer commit" signed &&
955 git reset --hard c0 &&
957 git merge --ff-only signed &&
958 git rev-parse signed^0 >expect &&
959 git rev-parse HEAD >actual &&
960 test_cmp expect actual
963 test_expect_success GPG
'merge --no-edit tag should skip editor' '
964 git reset --hard c0 &&
965 git commit --allow-empty -m "A newer commit" &&
966 git tag -f -s -m "A newer commit" signed &&
967 git reset --hard c0 &&
969 EDITOR=false git merge --no-edit --no-ff signed &&
970 git rev-parse signed^0 >expect &&
971 git rev-parse HEAD^2 >actual &&
972 test_cmp expect actual
975 test_expect_success
'set up mod-256 conflict scenario' '
976 # 256 near-identical stanzas...
977 for i in $(test_seq 1 256); do
978 for j in 1 2 3 4 5; do
979 echo $i-$j || return 1
983 git commit -m base &&
985 # one side changes the first line of each to "main"
986 sed s/-1/-main/ file >tmp &&
988 git commit -am main &&
990 # and the other to "side"; merging the two will
991 # yield 256 separate conflicts
992 git checkout -b side HEAD^ &&
993 sed s/-1/-side/ file >tmp &&
998 test_expect_success
'merge detects mod-256 conflicts (recursive)' '
1000 test_must_fail git merge -s recursive main
1003 test_expect_success
'merge detects mod-256 conflicts (resolve)' '
1005 test_must_fail git merge -s resolve main
1008 test_expect_success
'merge nothing into void' '
1012 git remote add up .. &&
1014 test_must_fail git merge FETCH_HEAD
1018 test_expect_success
'merge can be completed with --continue' '
1019 git reset --hard c0 &&
1020 git merge --no-ff --no-commit c1 &&
1021 git merge --continue &&
1022 verify_parents $c0 $c1
1025 write_script .git
/FAKE_EDITOR
<<EOF
1026 # kill -TERM command added below.
1029 test_expect_success EXECKEEPSPID
'killed merge can be completed with --continue' '
1030 git reset --hard c0 &&
1031 ! "$SHELL_PATH" -c '\''
1032 echo kill -TERM $$ >>.git/FAKE_EDITOR
1033 GIT_EDITOR=.git/FAKE_EDITOR
1035 exec git merge --no-ff --edit c1'\'' &&
1036 git merge --continue &&
1037 verify_parents $c0 $c1
1040 test_expect_success
'merge --quit' '
1041 git init merge-quit &&
1045 echo one >>base.t &&
1046 git commit -am one &&
1048 git checkout base &&
1049 echo two >>base.t &&
1050 git commit -am two &&
1051 test_must_fail git -c rerere.enabled=true merge one &&
1052 test_path_is_file .git/MERGE_HEAD &&
1053 test_path_is_file .git/MERGE_MODE &&
1054 test_path_is_file .git/MERGE_MSG &&
1055 git rerere status >rerere.before &&
1057 test_path_is_missing .git/MERGE_HEAD &&
1058 test_path_is_missing .git/MERGE_MODE &&
1059 test_path_is_missing .git/MERGE_MSG &&
1060 git rerere status >rerere.after &&
1061 test_must_be_empty rerere.after &&
1062 ! test_cmp rerere.after rerere.before
1066 test_expect_success
'merge suggests matching remote refname' '
1067 git commit --allow-empty -m not-local &&
1068 git update-ref refs/remotes/origin/not-local HEAD &&
1069 git reset --hard HEAD^ &&
1071 # This is white-box testing hackery; we happen to know
1072 # that reading packed refs is more picky about the memory
1073 # ownership of strings we pass to for_each_ref() callbacks.
1074 git pack-refs --all --prune &&
1076 test_must_fail git merge not-local 2>stderr &&
1077 grep origin/not-local stderr
1080 test_expect_success
'suggested names are not ambiguous' '
1081 git update-ref refs/heads/origin/not-local HEAD &&
1082 test_must_fail git merge not-local 2>stderr &&
1083 grep remotes/origin/not-local stderr