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 >usage
178 test_grep "[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 cat >expect <<-\EOF &&
193 2 files changed, 10 insertions(+), 1 deletion(-)
194 create mode 100644 other
197 git reset --hard c0 &&
199 sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual &&
200 test_cmp expect actual &&
201 verify_merge file result.1 &&
204 git reflog -1 >reflog.actual &&
205 sed "s/$_x05[0-9a-f]*/OBJID/g" reflog.actual >reflog.fuzzy &&
206 test_cmp reflog.expected reflog.fuzzy
209 test_debug
'git log --graph --decorate --oneline --all'
211 test_expect_success
'merge c0 with c1 with --ff-only' '
212 git reset --hard c0 &&
213 git merge --ff-only c1 &&
214 git merge --ff-only HEAD c0 c1 &&
215 verify_merge file result.1 &&
219 test_expect_success
'the same merge with merge.stat=diffstat' '
220 cat >expect <<-\EOF &&
225 2 files changed, 10 insertions(+), 1 deletion(-)
226 create mode 100644 other
229 git reset --hard c0 &&
230 git -c merge.stat=diffstat merge c1 >out &&
231 sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual &&
232 test_cmp expect actual
235 test_expect_success
'the same merge with compact summary' '
236 cat >expect <<-\EOF &&
240 other (new) | 9 +++++++++
241 2 files changed, 10 insertions(+), 1 deletion(-)
244 git reset --hard c0 &&
245 git merge --compact-summary c1 >out &&
246 sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual &&
247 test_cmp expect actual
250 test_expect_success
'the same merge with compact summary' '
251 cat >expect <<-\EOF &&
255 other (new) | 9 +++++++++
256 2 files changed, 10 insertions(+), 1 deletion(-)
259 git reset --hard c0 &&
260 git merge --compact-summary c1 >out &&
261 sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual &&
262 test_cmp expect actual
265 test_expect_success
'the same merge with merge.stat=compact' '
266 cat >expect <<-\EOF &&
270 other (new) | 9 +++++++++
271 2 files changed, 10 insertions(+), 1 deletion(-)
274 git reset --hard c0 &&
275 git -c merge.stat=compact merge c1 >out &&
276 sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual &&
277 test_cmp expect actual
280 test_debug
'git log --graph --decorate --oneline --all'
282 test_expect_success
'merge from unborn branch' '
283 git checkout -f main &&
284 test_might_fail git branch -D kid &&
286 echo "OBJID HEAD@{0}: initial pull" >reflog.expected &&
288 git checkout --orphan kid &&
289 test_when_finished "git checkout -f main" &&
292 git merge --ff-only c1 &&
293 verify_merge file result.1 &&
296 git reflog -1 >reflog.actual &&
297 sed "s/$_x05[0-9a-f][0-9a-f]/OBJID/g" reflog.actual >reflog.fuzzy &&
298 test_cmp reflog.expected reflog.fuzzy
301 test_debug
'git log --graph --decorate --oneline --all'
303 test_expect_success
'merge c1 with c2' '
304 git reset --hard c1 &&
307 verify_merge file result.1-5 msg.1-5 &&
308 verify_parents $c1 $c2
311 test_expect_success
'merge c1 with c2 when index.lock exists' '
312 test_when_finished rm .git/index.lock &&
313 git reset --hard c1 &&
315 test_must_fail git merge c2 &&
316 test_path_is_missing .git/MERGE_HEAD &&
317 test_path_is_missing .git/MERGE_MODE &&
318 test_path_is_missing .git/MERGE_MSG
321 test_expect_success
'merge --squash c3 with c7' '
322 git reset --hard c3 &&
323 test_must_fail git merge --squash c7 &&
324 cat result.9z >file &&
325 git commit --no-edit -a &&
327 cat >expect <<-EOF &&
328 Squashed commit of the following:
335 git cat-file commit HEAD >raw &&
336 sed -e "1,/^$/d" raw >actual &&
337 test_cmp expect actual
340 test_expect_success
'merge --squash --autostash conflict does not attempt to apply autostash' '
341 git reset --hard c3 &&
344 test_must_fail git merge --squash c7 --autostash >out 2>err &&
345 ! grep "Applying autostash resulted in conflicts." err &&
346 grep "When finished, apply stashed changes with \`git stash pop\`" out
349 test_expect_success
'merge c3 with c7 with commit.cleanup = scissors' '
350 git config commit.cleanup scissors &&
351 git reset --hard c3 &&
352 test_must_fail git merge c7 &&
353 cat result.9z >file &&
354 git commit --no-edit -a &&
356 cat >expect <<-\EOF &&
357 Merge tag '"'"'c7'"'"'
359 # ------------------------ >8 ------------------------
360 # Do not modify or remove the line above.
361 # Everything below it will be ignored.
366 git cat-file commit HEAD >raw &&
367 sed -e "1,/^$/d" raw >actual &&
368 test_cmp expect actual
371 test_expect_success
'merge c3 with c7 with --squash commit.cleanup = scissors' '
372 git config commit.cleanup scissors &&
373 git reset --hard c3 &&
374 test_must_fail git merge --squash c7 &&
375 cat result.9z >file &&
376 git commit --no-edit -a &&
378 cat >expect <<-EOF &&
379 Squashed commit of the following:
383 # ------------------------ >8 ------------------------
384 # Do not modify or remove the line above.
385 # Everything below it will be ignored.
390 git cat-file commit HEAD >raw &&
391 sed -e "1,/^$/d" raw >actual &&
392 test_cmp expect actual
395 test_debug
'git log --graph --decorate --oneline --all'
397 test_expect_success
'merge c1 with c2 and c3' '
398 git reset --hard c1 &&
401 verify_merge file result.1-5-9 msg.1-5-9 &&
402 verify_parents $c1 $c2 $c3
405 test_debug
'git log --graph --decorate --oneline --all'
407 test_expect_success
'merges with --ff-only' '
408 git reset --hard c1 &&
410 test_must_fail git merge --ff-only c2 &&
411 test_must_fail git merge --ff-only c3 &&
412 test_must_fail git merge --ff-only c2 c3 &&
413 git reset --hard c0 &&
418 test_expect_success
'merges with merge.ff=only' '
419 git reset --hard c1 &&
421 test_config merge.ff "only" &&
422 test_must_fail git merge c2 &&
423 test_must_fail git merge c3 &&
424 test_must_fail git merge c2 c3 &&
425 git reset --hard c0 &&
430 test_expect_success
'merge c0 with c1 (no-commit)' '
431 git reset --hard c0 &&
432 git merge --no-commit c1 &&
433 verify_merge file result.1 &&
437 test_debug
'git log --graph --decorate --oneline --all'
439 test_expect_success
'merge c1 with c2 (no-commit)' '
440 git reset --hard c1 &&
441 git merge --no-commit c2 &&
442 verify_merge file result.1-5 &&
444 verify_mergeheads $c2
447 test_debug
'git log --graph --decorate --oneline --all'
449 test_expect_success
'merge c1 with c2 and c3 (no-commit)' '
450 git reset --hard c1 &&
451 git merge --no-commit c2 c3 &&
452 verify_merge file result.1-5-9 &&
454 verify_mergeheads $c2 $c3
457 test_debug
'git log --graph --decorate --oneline --all'
459 test_expect_success
'merge c0 with c1 (squash)' '
460 git reset --hard c0 &&
461 git merge --squash c1 &&
462 verify_merge file result.1 &&
464 verify_no_mergehead &&
465 test_cmp squash.1 .git/SQUASH_MSG
468 test_debug
'git log --graph --decorate --oneline --all'
470 test_expect_success
'merge c0 with c1 (squash, ff-only)' '
471 git reset --hard c0 &&
472 git merge --squash --ff-only c1 &&
473 verify_merge file result.1 &&
475 verify_no_mergehead &&
476 test_cmp squash.1 .git/SQUASH_MSG
479 test_debug
'git log --graph --decorate --oneline --all'
481 test_expect_success
'merge c1 with c2 (squash)' '
482 git reset --hard c1 &&
483 git merge --squash c2 &&
484 verify_merge file result.1-5 &&
486 verify_no_mergehead &&
487 test_cmp squash.1-5 .git/SQUASH_MSG
490 test_debug
'git log --graph --decorate --oneline --all'
492 test_expect_success
'unsuccessful merge of c1 with c2 (squash, ff-only)' '
493 git reset --hard c1 &&
494 test_must_fail git merge --squash --ff-only c2
497 test_debug
'git log --graph --decorate --oneline --all'
499 test_expect_success
'merge c1 with c2 and c3 (squash)' '
500 git reset --hard c1 &&
501 git merge --squash c2 c3 &&
502 verify_merge file result.1-5-9 &&
504 verify_no_mergehead &&
505 test_cmp squash.1-5-9 .git/SQUASH_MSG
508 test_debug
'git log --graph --decorate --oneline --all'
510 test_expect_success
'merge c1 with c2 (no-commit in config)' '
511 git reset --hard c1 &&
512 test_config branch.main.mergeoptions "--no-commit" &&
514 verify_merge file result.1-5 &&
516 verify_mergeheads $c2
519 test_debug
'git log --graph --decorate --oneline --all'
521 test_expect_success
'merge c1 with c2 (log in config)' '
522 git reset --hard c1 &&
523 git merge --log c2 &&
524 git show -s --pretty=tformat:%s%n%b >expect &&
526 test_config branch.main.mergeoptions "--log" &&
527 git reset --hard c1 &&
529 git show -s --pretty=tformat:%s%n%b >actual &&
531 test_cmp expect actual
534 test_expect_success
'merge c1 with c2 (log in config gets overridden)' '
535 git reset --hard c1 &&
537 git show -s --pretty=tformat:%s%n%b >expect &&
539 test_config branch.main.mergeoptions "--no-log" &&
540 test_config merge.log "true" &&
541 git reset --hard c1 &&
543 git show -s --pretty=tformat:%s%n%b >actual &&
545 test_cmp expect actual
548 test_expect_success
'merge c1 with c2 (squash in config)' '
549 git reset --hard c1 &&
550 test_config branch.main.mergeoptions "--squash" &&
552 verify_merge file result.1-5 &&
554 verify_no_mergehead &&
555 test_cmp squash.1-5 .git/SQUASH_MSG
558 test_debug
'git log --graph --decorate --oneline --all'
560 test_expect_success
'override config option -n with --summary' '
561 git reset --hard c1 &&
562 test_config branch.main.mergeoptions "-n" &&
564 git merge --summary c2 >diffstat.txt &&
565 verify_merge file result.1-5 msg.1-5 &&
566 verify_parents $c1 $c2 &&
567 if ! grep "^ file | *2 +-$" diffstat.txt
569 echo "[OOPS] diffstat was not generated with --summary"
574 test_expect_success
'override config option -n with --stat' '
575 git reset --hard c1 &&
576 test_config branch.main.mergeoptions "-n" &&
578 git merge --stat c2 >diffstat.txt &&
579 verify_merge file result.1-5 msg.1-5 &&
580 verify_parents $c1 $c2 &&
581 if ! grep "^ file | *2 +-$" diffstat.txt
583 echo "[OOPS] diffstat was not generated with --stat"
588 test_debug
'git log --graph --decorate --oneline --all'
590 test_expect_success
'override config option --stat' '
591 git reset --hard c1 &&
592 test_config branch.main.mergeoptions "--stat" &&
594 git merge -n c2 >diffstat.txt &&
595 verify_merge file result.1-5 msg.1-5 &&
596 verify_parents $c1 $c2 &&
597 if grep "^ file | *2 +-$" diffstat.txt
599 echo "[OOPS] diffstat was generated"
604 test_debug
'git log --graph --decorate --oneline --all'
606 test_expect_success
'merge c1 with c2 (override --no-commit)' '
607 git reset --hard c1 &&
608 test_config branch.main.mergeoptions "--no-commit" &&
610 git merge --commit c2 &&
611 verify_merge file result.1-5 msg.1-5 &&
612 verify_parents $c1 $c2
615 test_debug
'git log --graph --decorate --oneline --all'
617 test_expect_success
'merge c1 with c2 (override --squash)' '
618 git reset --hard c1 &&
619 test_config branch.main.mergeoptions "--squash" &&
621 git merge --no-squash c2 &&
622 verify_merge file result.1-5 msg.1-5 &&
623 verify_parents $c1 $c2
626 test_debug
'git log --graph --decorate --oneline --all'
628 test_expect_success
'merge c0 with c1 (no-ff)' '
629 git reset --hard c0 &&
631 git merge --no-ff c1 &&
632 verify_merge file result.1 &&
633 verify_parents $c0 $c1
636 test_debug
'git log --graph --decorate --oneline --all'
638 test_expect_success
'merge c0 with c1 (merge.ff=false)' '
639 git reset --hard c0 &&
640 test_config merge.ff "false" &&
643 verify_merge file result.1 &&
644 verify_parents $c0 $c1
646 test_debug
'git log --graph --decorate --oneline --all'
648 test_expect_success
'combine branch.main.mergeoptions with merge.ff' '
649 git reset --hard c0 &&
650 test_config branch.main.mergeoptions "--ff" &&
651 test_config merge.ff "false" &&
654 verify_merge file result.1 &&
658 test_expect_success
'tolerate unknown values for merge.ff' '
659 git reset --hard c0 &&
660 test_config merge.ff "something-new" &&
662 git merge c1 2>message &&
664 test_must_be_empty message
667 test_expect_success
'combining --squash and --no-ff is refused' '
668 git reset --hard c0 &&
669 test_must_fail git merge --squash --no-ff c1 &&
670 test_must_fail git merge --no-ff --squash c1
673 test_expect_success
'combining --squash and --commit is refused' '
674 git reset --hard c0 &&
675 test_must_fail git merge --squash --commit c1 &&
676 test_must_fail git merge --commit --squash c1
679 test_expect_success
'option --ff-only overwrites --no-ff' '
680 git merge --no-ff --ff-only c1 &&
681 test_must_fail git merge --no-ff --ff-only c2
684 test_expect_success
'option --no-ff overrides merge.ff=only config' '
685 git reset --hard c0 &&
686 test_config merge.ff only &&
690 test_expect_success
'merge c0 with c1 (ff overrides no-ff)' '
691 git reset --hard c0 &&
692 test_config branch.main.mergeoptions "--no-ff" &&
694 verify_merge file result.1 &&
698 test_expect_success
'merge log message' '
699 git reset --hard c0 &&
700 git merge --no-log c2 &&
701 git show -s --pretty=format:%b HEAD >msg.act &&
702 test_must_be_empty msg.act &&
704 git reset --hard c0 &&
705 test_config branch.main.mergeoptions "--no-ff" &&
706 git merge --no-log c2 &&
707 git show -s --pretty=format:%b HEAD >msg.act &&
708 test_must_be_empty msg.act &&
710 git merge --log c3 &&
711 git show -s --pretty=format:%b HEAD >msg.act &&
712 test_cmp msg.log msg.act &&
714 git reset --hard HEAD^ &&
715 test_config merge.log "yes" &&
717 git show -s --pretty=format:%b HEAD >msg.act &&
718 test_cmp msg.log msg.act
721 test_debug
'git log --graph --decorate --oneline --all'
723 test_expect_success
'merge c1 with c0, c2, c0, and c1' '
724 git reset --hard c1 &&
726 git merge c0 c2 c0 c1 &&
727 verify_merge file result.1-5 &&
728 verify_parents $c1 $c2
731 test_debug
'git log --graph --decorate --oneline --all'
733 test_expect_success
'merge c1 with c0, c2, c0, and c1' '
734 git reset --hard c1 &&
736 git merge c0 c2 c0 c1 &&
737 verify_merge file result.1-5 &&
738 verify_parents $c1 $c2
741 test_debug
'git log --graph --decorate --oneline --all'
743 test_expect_success
'merge c1 with c1 and c2' '
744 git reset --hard c1 &&
747 verify_merge file result.1-5 &&
748 verify_parents $c1 $c2
751 test_debug
'git log --graph --decorate --oneline --all'
753 test_expect_success
'merge fast-forward in a dirty tree' '
754 git reset --hard c0 &&
761 test_debug
'git log --graph --decorate --oneline --all'
763 test_expect_success
'in-index merge' '
764 git reset --hard c0 &&
765 git merge --no-ff -s resolve c1 >out &&
766 test_grep "Wonderful." out &&
767 verify_parents $c0 $c1
770 test_debug
'git log --graph --decorate --oneline --all'
772 test_expect_success
'refresh the index before merging' '
773 git reset --hard c1 &&
774 cp file file.n && mv -f file.n file &&
778 test_expect_success
'merge with --autostash' '
779 git reset --hard c1 &&
780 git merge-file file file.orig file.9 &&
781 git merge --autostash c2 2>err &&
782 test_grep "Applied autostash." err &&
783 git show HEAD:file >merge-result &&
784 test_cmp result.1-5 merge-result &&
785 test_cmp result.1-5-9 file
788 test_expect_success
'merge with merge.autoStash' '
789 test_config merge.autoStash true &&
790 git reset --hard c1 &&
791 git merge-file file file.orig file.9 &&
792 git merge c2 2>err &&
793 test_grep "Applied autostash." err &&
794 git show HEAD:file >merge-result &&
795 test_cmp result.1-5 merge-result &&
796 test_cmp result.1-5-9 file
799 test_expect_success
'fast-forward merge with --autostash' '
800 git reset --hard c0 &&
801 git merge-file file file.orig file.5 &&
802 git merge --autostash c1 2>err &&
803 test_grep "Applied autostash." err &&
804 test_cmp result.1-5 file
807 test_expect_success
'failed fast-forward merge with --autostash' '
808 git reset --hard c0 &&
809 git merge-file file file.orig file.5 &&
811 test_when_finished "rm other" &&
812 test_must_fail git merge --autostash c1 2>err &&
813 test_grep "Applied autostash." err &&
817 test_expect_success
'octopus merge with --autostash' '
818 git reset --hard c1 &&
819 git merge-file file file.orig file.3 &&
820 git merge --autostash c2 c3 2>err &&
821 test_grep "Applied autostash." err &&
822 git show HEAD:file >merge-result &&
823 test_cmp result.1-5-9 merge-result &&
824 test_cmp result.1-3-5-9 file
827 test_expect_success
'failed merge (exit 2) with --autostash' '
828 git reset --hard c1 &&
829 git merge-file file file.orig file.5 &&
830 test_must_fail git merge -s recursive --autostash c2 c3 2>err &&
831 test_grep "Applied autostash." err &&
832 test_cmp result.1-5 file
835 test_expect_success
'conflicted merge with --autostash, --abort restores stash' '
836 git reset --hard c3 &&
838 test_must_fail git merge --autostash c7 &&
839 git merge --abort 2>err &&
840 test_grep "Applied autostash." err &&
844 test_expect_success
'completed merge (git commit) with --no-commit and --autostash' '
845 git reset --hard c1 &&
846 git merge-file file file.orig file.9 &&
848 git merge --no-commit --autostash c2 &&
849 git stash show -p MERGE_AUTOSTASH >actual &&
850 test_cmp expect actual &&
852 test_grep "Applied autostash." err &&
853 git show HEAD:file >merge-result &&
854 test_cmp result.1-5 merge-result &&
855 test_cmp result.1-5-9 file
858 test_expect_success
'completed merge (git merge --continue) with --no-commit and --autostash' '
859 git reset --hard c1 &&
860 git merge-file file file.orig file.9 &&
862 git merge --no-commit --autostash c2 &&
863 git stash show -p MERGE_AUTOSTASH >actual &&
864 test_cmp expect actual &&
865 git merge --continue 2>err &&
866 test_grep "Applied autostash." err &&
867 git show HEAD:file >merge-result &&
868 test_cmp result.1-5 merge-result &&
869 test_cmp result.1-5-9 file
872 test_expect_success
'aborted merge (merge --abort) with --no-commit and --autostash' '
873 git reset --hard c1 &&
874 git merge-file file file.orig file.9 &&
876 git merge --no-commit --autostash c2 &&
877 git stash show -p MERGE_AUTOSTASH >actual &&
878 test_cmp expect actual &&
879 git merge --abort 2>err &&
880 test_grep "Applied autostash." err &&
882 test_cmp expect actual
885 test_expect_success
'aborted merge (reset --hard) with --no-commit and --autostash' '
886 git reset --hard c1 &&
887 git merge-file file file.orig file.9 &&
889 git merge --no-commit --autostash c2 &&
890 git stash show -p MERGE_AUTOSTASH >actual &&
891 test_cmp expect actual &&
892 git reset --hard 2>err &&
893 test_grep "Autostash exists; creating a new stash entry." err &&
897 test_expect_success
'quit merge with --no-commit and --autostash' '
898 git reset --hard c1 &&
899 git merge-file file file.orig file.9 &&
901 git merge --no-commit --autostash c2 &&
902 git stash show -p MERGE_AUTOSTASH >actual &&
903 test_cmp expect actual &&
904 git diff HEAD >expect &&
905 git merge --quit 2>err &&
906 test_grep "Autostash exists; creating a new stash entry." err &&
907 git diff HEAD >actual &&
908 test_cmp expect actual
911 test_expect_success
'merge with conflicted --autostash changes' '
912 git reset --hard c1 &&
913 git merge-file file file.orig file.9y &&
915 test_when_finished "test_might_fail git stash drop" &&
916 git merge --autostash c3 2>err &&
917 test_grep "Applying autostash resulted in conflicts." err &&
918 git show HEAD:file >merge-result &&
919 test_cmp result.1-9 merge-result &&
920 git stash show -p >actual &&
921 test_cmp expect actual
924 cat >expected.branch
<<\EOF
925 Merge branch
'c5-branch' (early part
)
927 cat >expected.tag
<<\EOF
931 test_expect_success
'merge early part of c2' '
932 git reset --hard c3 &&
941 git reset --hard c3 &&
946 git branch -f c5-branch c5 &&
947 git merge c5-branch~1 &&
948 git show -s --pretty=tformat:%s HEAD >actual.branch &&
949 git reset --keep HEAD^ &&
951 git show -s --pretty=tformat:%s HEAD >actual.tag &&
952 test_cmp expected.branch actual.branch &&
953 test_cmp expected.tag actual.tag
956 test_debug
'git log --graph --decorate --oneline --all'
958 test_expect_success
'merge --no-ff --no-commit && commit' '
959 git reset --hard c0 &&
960 git merge --no-ff --no-commit c1 &&
961 EDITOR=: git commit &&
962 verify_parents $c0 $c1
965 test_debug
'git log --graph --decorate --oneline --all'
967 test_expect_success
'amending no-ff merge commit' '
968 EDITOR=: git commit --amend &&
969 verify_parents $c0 $c1
972 test_debug
'git log --graph --decorate --oneline --all'
976 # Add a new message string that was not in the template
978 echo "Merge work done on the side branch c1"
981 ) >"$1.tmp" && mv "$1.tmp" "$1"
982 # strip comments and blank lines from end of message
983 sed -e '/^#/d' "$1" | sed -e :a
-e '/^\n*$/{$d;N;ba' -e '}' >expected
987 test_expect_success
'merge --no-ff --edit' '
988 git reset --hard c0 &&
989 EDITOR=./editor git merge --no-ff --edit c1 &&
990 verify_parents $c0 $c1 &&
991 git cat-file commit HEAD >raw &&
992 grep "work done on the side branch" raw &&
993 sed "1,/^$/d" >actual raw &&
994 test_cmp expected actual
997 test_expect_success
'merge annotated/signed tag w/o tracking' '
998 test_when_finished "rm -rf dst; git tag -d anno1" &&
999 git tag -a -m "anno c1" anno1 c1 &&
1001 git rev-parse c1 >dst/expect &&
1003 # c0 fast-forwards to c1 but because this repository
1004 # is not a "downstream" whose refs/tags follows along
1005 # tag from the "upstream", this pull defaults to --no-ff
1008 git pull .. anno1 &&
1009 git rev-parse HEAD^2 >actual &&
1010 test_cmp expect actual
1014 test_expect_success
'merge annotated/signed tag w/ tracking' '
1015 test_when_finished "rm -rf dst; git tag -d anno1" &&
1016 git tag -a -m "anno c1" anno1 c1 &&
1018 git rev-parse c1 >dst/expect &&
1020 # c0 fast-forwards to c1 and because this repository
1021 # is a "downstream" whose refs/tags follows along
1022 # tag from the "upstream", this pull defaults to --ff
1024 git remote add origin .. &&
1025 git pull origin c0 &&
1028 git rev-parse HEAD >actual &&
1029 test_cmp expect actual
1033 test_expect_success GPG
'merge --ff-only tag' '
1034 git reset --hard c0 &&
1035 git commit --allow-empty -m "A newer commit" &&
1036 git tag -s -m "A newer commit" signed &&
1037 git reset --hard c0 &&
1039 git merge --ff-only signed &&
1040 git rev-parse signed^0 >expect &&
1041 git rev-parse HEAD >actual &&
1042 test_cmp expect actual
1045 test_expect_success GPG
'merge --no-edit tag should skip editor' '
1046 git reset --hard c0 &&
1047 git commit --allow-empty -m "A newer commit" &&
1048 git tag -f -s -m "A newer commit" signed &&
1049 git reset --hard c0 &&
1051 EDITOR=false git merge --no-edit --no-ff signed &&
1052 git rev-parse signed^0 >expect &&
1053 git rev-parse HEAD^2 >actual &&
1054 test_cmp expect actual
1057 test_expect_success
'set up mod-256 conflict scenario' '
1058 # 256 near-identical stanzas...
1059 for i in $(test_seq 1 256); do
1060 for j in 1 2 3 4 5; do
1061 echo $i-$j || return 1
1065 git commit -m base &&
1067 # one side changes the first line of each to "main"
1068 sed s/-1/-main/ file >tmp &&
1070 git commit -am main &&
1072 # and the other to "side"; merging the two will
1073 # yield 256 separate conflicts
1074 git checkout -b side HEAD^ &&
1075 sed s/-1/-side/ file >tmp &&
1080 test_expect_success
'merge detects mod-256 conflicts (recursive)' '
1082 test_must_fail git merge -s recursive main
1085 test_expect_success
'merge detects mod-256 conflicts (resolve)' '
1087 test_must_fail git merge -s resolve main
1090 test_expect_success
'merge nothing into void' '
1094 git remote add up .. &&
1096 test_must_fail git merge FETCH_HEAD
1100 test_expect_success
'merge can be completed with --continue' '
1101 git reset --hard c0 &&
1102 git merge --no-ff --no-commit c1 &&
1103 git merge --continue &&
1104 verify_parents $c0 $c1
1107 write_script .git
/FAKE_EDITOR
<<EOF
1108 # kill -TERM command added below.
1111 test_expect_success EXECKEEPSPID
'killed merge can be completed with --continue' '
1112 git reset --hard c0 &&
1113 ! "$SHELL_PATH" -c '\''
1114 echo kill -TERM $$ >>.git/FAKE_EDITOR
1115 GIT_EDITOR=.git/FAKE_EDITOR
1117 exec git merge --no-ff --edit c1'\'' &&
1118 git merge --continue &&
1119 verify_parents $c0 $c1
1122 test_expect_success
'merge --quit' '
1123 git init merge-quit &&
1127 echo one >>base.t &&
1128 git commit -am one &&
1130 git checkout base &&
1131 echo two >>base.t &&
1132 git commit -am two &&
1133 test_must_fail git -c rerere.enabled=true merge one &&
1134 test_path_is_file .git/MERGE_HEAD &&
1135 test_path_is_file .git/MERGE_MODE &&
1136 test_path_is_file .git/MERGE_MSG &&
1137 git rerere status >rerere.before &&
1139 test_path_is_missing .git/MERGE_HEAD &&
1140 test_path_is_missing .git/MERGE_MODE &&
1141 test_path_is_missing .git/MERGE_MSG &&
1142 git rerere status >rerere.after &&
1143 test_must_be_empty rerere.after &&
1144 ! test_cmp rerere.after rerere.before
1148 test_expect_success
'merge suggests matching remote refname' '
1149 git commit --allow-empty -m not-local &&
1150 git update-ref refs/remotes/origin/not-local HEAD &&
1151 git reset --hard HEAD^ &&
1153 # This is white-box testing hackery; we happen to know
1154 # that reading packed refs is more picky about the memory
1155 # ownership of strings we pass to for_each_ref() callbacks.
1156 git pack-refs --all --prune &&
1158 test_must_fail git merge not-local 2>stderr &&
1159 grep origin/not-local stderr
1162 test_expect_success
'suggested names are not ambiguous' '
1163 git update-ref refs/heads/origin/not-local HEAD &&
1164 test_must_fail git merge not-local 2>stderr &&
1165 grep remotes/origin/not-local stderr