Sync with maint
[git/raj.git] / t / t7600-merge.sh
blob132608879ad3c93011b8429d7f6f0f8ab1ed45cf
1 #!/bin/sh
3 # Copyright (c) 2007 Lars Hjemli
6 test_description='git merge
8 Testing basic merge operations/option parsing.
10 ! [c0] commit 0
11 ! [c1] commit 1
12 ! [c2] commit 2
13 ! [c3] commit 3
14 ! [c4] c4
15 ! [c5] c5
16 ! [c6] c6
17 * [master] Merge commit 'c1'
18 --------
19 - [master] Merge commit 'c1'
20 + * [c1] commit 1
21 + [c6] c6
22 + [c5] c5
23 ++ [c4] c4
24 ++++ [c3] commit 3
25 + [c2] commit 2
26 +++++++* [c0] commit 0
29 . ./test-lib.sh
30 . "$TEST_DIRECTORY"/lib-gpg.sh
32 printf '%s\n' 1 2 3 4 5 6 7 8 9 >file
33 printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >file.1
34 printf '%s\n' 1 2 3 4 '5 X' 6 7 8 9 >file.5
35 printf '%s\n' 1 2 3 4 5 6 7 8 '9 X' >file.9
36 printf '%s\n' 1 2 3 4 5 6 7 8 '9 Y' >file.9y
37 printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >result.1
38 printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 9 >result.1-5
39 printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 '9 X' >result.1-5-9
40 printf '%s\n' 1 2 3 4 5 6 7 8 '9 Z' >result.9z
42 create_merge_msgs () {
43 echo "Merge tag 'c2'" >msg.1-5 &&
44 echo "Merge tags 'c2' and 'c3'" >msg.1-5-9 &&
46 echo "Squashed commit of the following:" &&
47 echo &&
48 git log --no-merges ^HEAD c1
49 } >squash.1 &&
51 echo "Squashed commit of the following:" &&
52 echo &&
53 git log --no-merges ^HEAD c2
54 } >squash.1-5 &&
56 echo "Squashed commit of the following:" &&
57 echo &&
58 git log --no-merges ^HEAD c2 c3
59 } >squash.1-5-9 &&
61 echo "* tag 'c3':" &&
62 echo " commit 3"
63 } >msg.log
66 verify_merge () {
67 test_cmp "$2" "$1" &&
68 git update-index --refresh &&
69 git diff --exit-code &&
70 if test -n "$3"
71 then
72 git show -s --pretty=tformat:%s HEAD >msg.act &&
73 test_cmp "$3" msg.act
77 verify_head () {
78 echo "$1" >head.expected &&
79 git rev-parse HEAD >head.actual &&
80 test_cmp head.expected head.actual
83 verify_parents () {
84 printf '%s\n' "$@" >parents.expected &&
85 >parents.actual &&
86 i=1 &&
87 while test $i -le $#
89 git rev-parse HEAD^$i >>parents.actual &&
90 i=$(expr $i + 1) ||
91 return 1
92 done &&
93 test_must_fail git rev-parse --verify "HEAD^$i" &&
94 test_cmp parents.expected parents.actual
97 verify_mergeheads () {
98 printf '%s\n' "$@" >mergehead.expected &&
99 while read sha1 rest
101 git rev-parse $sha1
102 done <.git/MERGE_HEAD >mergehead.actual &&
103 test_cmp mergehead.expected mergehead.actual
106 verify_no_mergehead () {
107 ! test -e .git/MERGE_HEAD
110 test_expect_success 'setup' '
111 git add file &&
112 test_tick &&
113 git commit -m "commit 0" &&
114 git tag c0 &&
115 c0=$(git rev-parse HEAD) &&
116 cp file.1 file &&
117 git add file &&
118 test_tick &&
119 git commit -m "commit 1" &&
120 git tag c1 &&
121 c1=$(git rev-parse HEAD) &&
122 git reset --hard "$c0" &&
123 cp file.5 file &&
124 git add file &&
125 test_tick &&
126 git commit -m "commit 2" &&
127 git tag c2 &&
128 c2=$(git rev-parse HEAD) &&
129 git reset --hard "$c0" &&
130 cp file.9y file &&
131 git add file &&
132 test_tick &&
133 git commit -m "commit 7" &&
134 git tag c7 &&
135 git reset --hard "$c0" &&
136 cp file.9 file &&
137 git add file &&
138 test_tick &&
139 git commit -m "commit 3" &&
140 git tag c3 &&
141 c3=$(git rev-parse HEAD) &&
142 git reset --hard "$c0" &&
143 create_merge_msgs
146 test_debug 'git log --graph --decorate --oneline --all'
148 test_expect_success 'test option parsing' '
149 test_must_fail git merge -$ c1 &&
150 test_must_fail git merge --no-such c1 &&
151 test_must_fail git merge -s foobar c1 &&
152 test_must_fail git merge -s=foobar c1 &&
153 test_must_fail git merge -m &&
154 test_must_fail git merge --abort foobar &&
155 test_must_fail git merge --abort --quiet &&
156 test_must_fail git merge --continue foobar &&
157 test_must_fail git merge --continue --quiet &&
158 test_must_fail git merge
161 test_expect_success 'merge -h with invalid index' '
162 mkdir broken &&
164 cd broken &&
165 git init &&
166 >.git/index &&
167 test_expect_code 129 git merge -h 2>usage
168 ) &&
169 test_i18ngrep "[Uu]sage: git merge" broken/usage
172 test_expect_success 'reject non-strategy with a git-merge-foo name' '
173 test_must_fail git merge -s index c1
176 test_expect_success 'merge c0 with c1' '
177 echo "OBJID HEAD@{0}: merge c1: Fast-forward" >reflog.expected &&
179 git reset --hard c0 &&
180 git merge c1 &&
181 verify_merge file result.1 &&
182 verify_head "$c1" &&
184 git reflog -1 >reflog.actual &&
185 sed "s/$_x05[0-9a-f]*/OBJID/g" reflog.actual >reflog.fuzzy &&
186 test_cmp reflog.expected reflog.fuzzy
189 test_debug 'git log --graph --decorate --oneline --all'
191 test_expect_success 'merge c0 with c1 with --ff-only' '
192 git reset --hard c0 &&
193 git merge --ff-only c1 &&
194 git merge --ff-only HEAD c0 c1 &&
195 verify_merge file result.1 &&
196 verify_head "$c1"
199 test_debug 'git log --graph --decorate --oneline --all'
201 test_expect_success 'merge from unborn branch' '
202 git checkout -f master &&
203 test_might_fail git branch -D kid &&
205 echo "OBJID HEAD@{0}: initial pull" >reflog.expected &&
207 git checkout --orphan kid &&
208 test_when_finished "git checkout -f master" &&
209 git rm -fr . &&
210 test_tick &&
211 git merge --ff-only c1 &&
212 verify_merge file result.1 &&
213 verify_head "$c1" &&
215 git reflog -1 >reflog.actual &&
216 sed "s/$_x05[0-9a-f][0-9a-f]/OBJID/g" reflog.actual >reflog.fuzzy &&
217 test_cmp reflog.expected reflog.fuzzy
220 test_debug 'git log --graph --decorate --oneline --all'
222 test_expect_success 'merge c1 with c2' '
223 git reset --hard c1 &&
224 test_tick &&
225 git merge c2 &&
226 verify_merge file result.1-5 msg.1-5 &&
227 verify_parents $c1 $c2
230 test_expect_success 'merge --squash c3 with c7' '
231 git reset --hard c3 &&
232 test_must_fail git merge --squash c7 &&
233 cat result.9z >file &&
234 git commit --no-edit -a &&
236 cat >expect <<-EOF &&
237 Squashed commit of the following:
239 $(git show -s c7)
241 # Conflicts:
242 # file
244 git cat-file commit HEAD >raw &&
245 sed -e '1,/^$/d' raw >actual &&
246 test_cmp expect actual
249 test_expect_success 'merge c3 with c7 with commit.cleanup = scissors' '
250 git config commit.cleanup scissors &&
251 git reset --hard c3 &&
252 test_must_fail git merge c7 &&
253 cat result.9z >file &&
254 git commit --no-edit -a &&
256 cat >expect <<-\EOF &&
257 Merge tag '"'"'c7'"'"'
259 # ------------------------ >8 ------------------------
260 # Do not modify or remove the line above.
261 # Everything below it will be ignored.
263 # Conflicts:
264 # file
266 git cat-file commit HEAD >raw &&
267 sed -e '1,/^$/d' raw >actual &&
268 test_i18ncmp expect actual
271 test_expect_success 'merge c3 with c7 with --squash commit.cleanup = scissors' '
272 git config commit.cleanup scissors &&
273 git reset --hard c3 &&
274 test_must_fail git merge --squash c7 &&
275 cat result.9z >file &&
276 git commit --no-edit -a &&
278 cat >expect <<-EOF &&
279 Squashed commit of the following:
281 $(git show -s c7)
283 # ------------------------ >8 ------------------------
284 # Do not modify or remove the line above.
285 # Everything below it will be ignored.
287 # Conflicts:
288 # file
290 git cat-file commit HEAD >raw &&
291 sed -e '1,/^$/d' raw >actual &&
292 test_i18ncmp expect actual
295 test_debug 'git log --graph --decorate --oneline --all'
297 test_expect_success 'merge c1 with c2 and c3' '
298 git reset --hard c1 &&
299 test_tick &&
300 git merge c2 c3 &&
301 verify_merge file result.1-5-9 msg.1-5-9 &&
302 verify_parents $c1 $c2 $c3
305 test_debug 'git log --graph --decorate --oneline --all'
307 test_expect_success 'merges with --ff-only' '
308 git reset --hard c1 &&
309 test_tick &&
310 test_must_fail git merge --ff-only c2 &&
311 test_must_fail git merge --ff-only c3 &&
312 test_must_fail git merge --ff-only c2 c3 &&
313 git reset --hard c0 &&
314 git merge c3 &&
315 verify_head $c3
318 test_expect_success 'merges with merge.ff=only' '
319 git reset --hard c1 &&
320 test_tick &&
321 test_config merge.ff "only" &&
322 test_must_fail git merge c2 &&
323 test_must_fail git merge c3 &&
324 test_must_fail git merge c2 c3 &&
325 git reset --hard c0 &&
326 git merge c3 &&
327 verify_head $c3
330 test_expect_success 'merge c0 with c1 (no-commit)' '
331 git reset --hard c0 &&
332 git merge --no-commit c1 &&
333 verify_merge file result.1 &&
334 verify_head $c1
337 test_debug 'git log --graph --decorate --oneline --all'
339 test_expect_success 'merge c1 with c2 (no-commit)' '
340 git reset --hard c1 &&
341 git merge --no-commit c2 &&
342 verify_merge file result.1-5 &&
343 verify_head $c1 &&
344 verify_mergeheads $c2
347 test_debug 'git log --graph --decorate --oneline --all'
349 test_expect_success 'merge c1 with c2 and c3 (no-commit)' '
350 git reset --hard c1 &&
351 git merge --no-commit c2 c3 &&
352 verify_merge file result.1-5-9 &&
353 verify_head $c1 &&
354 verify_mergeheads $c2 $c3
357 test_debug 'git log --graph --decorate --oneline --all'
359 test_expect_success 'merge c0 with c1 (squash)' '
360 git reset --hard c0 &&
361 git merge --squash c1 &&
362 verify_merge file result.1 &&
363 verify_head $c0 &&
364 verify_no_mergehead &&
365 test_cmp squash.1 .git/SQUASH_MSG
368 test_debug 'git log --graph --decorate --oneline --all'
370 test_expect_success 'merge c0 with c1 (squash, ff-only)' '
371 git reset --hard c0 &&
372 git merge --squash --ff-only c1 &&
373 verify_merge file result.1 &&
374 verify_head $c0 &&
375 verify_no_mergehead &&
376 test_cmp squash.1 .git/SQUASH_MSG
379 test_debug 'git log --graph --decorate --oneline --all'
381 test_expect_success 'merge c1 with c2 (squash)' '
382 git reset --hard c1 &&
383 git merge --squash c2 &&
384 verify_merge file result.1-5 &&
385 verify_head $c1 &&
386 verify_no_mergehead &&
387 test_cmp squash.1-5 .git/SQUASH_MSG
390 test_debug 'git log --graph --decorate --oneline --all'
392 test_expect_success 'unsuccessful merge of c1 with c2 (squash, ff-only)' '
393 git reset --hard c1 &&
394 test_must_fail git merge --squash --ff-only c2
397 test_debug 'git log --graph --decorate --oneline --all'
399 test_expect_success 'merge c1 with c2 and c3 (squash)' '
400 git reset --hard c1 &&
401 git merge --squash c2 c3 &&
402 verify_merge file result.1-5-9 &&
403 verify_head $c1 &&
404 verify_no_mergehead &&
405 test_cmp squash.1-5-9 .git/SQUASH_MSG
408 test_debug 'git log --graph --decorate --oneline --all'
410 test_expect_success 'merge c1 with c2 (no-commit in config)' '
411 git reset --hard c1 &&
412 test_config branch.master.mergeoptions "--no-commit" &&
413 git merge c2 &&
414 verify_merge file result.1-5 &&
415 verify_head $c1 &&
416 verify_mergeheads $c2
419 test_debug 'git log --graph --decorate --oneline --all'
421 test_expect_success 'merge c1 with c2 (log in config)' '
422 git reset --hard c1 &&
423 git merge --log c2 &&
424 git show -s --pretty=tformat:%s%n%b >expect &&
426 test_config branch.master.mergeoptions "--log" &&
427 git reset --hard c1 &&
428 git merge c2 &&
429 git show -s --pretty=tformat:%s%n%b >actual &&
431 test_cmp expect actual
434 test_expect_success 'merge c1 with c2 (log in config gets overridden)' '
435 git reset --hard c1 &&
436 git merge c2 &&
437 git show -s --pretty=tformat:%s%n%b >expect &&
439 test_config branch.master.mergeoptions "--no-log" &&
440 test_config merge.log "true" &&
441 git reset --hard c1 &&
442 git merge c2 &&
443 git show -s --pretty=tformat:%s%n%b >actual &&
445 test_cmp expect actual
448 test_expect_success 'merge c1 with c2 (squash in config)' '
449 git reset --hard c1 &&
450 test_config branch.master.mergeoptions "--squash" &&
451 git merge c2 &&
452 verify_merge file result.1-5 &&
453 verify_head $c1 &&
454 verify_no_mergehead &&
455 test_cmp squash.1-5 .git/SQUASH_MSG
458 test_debug 'git log --graph --decorate --oneline --all'
460 test_expect_success 'override config option -n with --summary' '
461 git reset --hard c1 &&
462 test_config branch.master.mergeoptions "-n" &&
463 test_tick &&
464 git merge --summary c2 >diffstat.txt &&
465 verify_merge file result.1-5 msg.1-5 &&
466 verify_parents $c1 $c2 &&
467 if ! grep "^ file | *2 +-$" diffstat.txt
468 then
469 echo "[OOPS] diffstat was not generated with --summary"
470 false
474 test_expect_success 'override config option -n with --stat' '
475 git reset --hard c1 &&
476 test_config branch.master.mergeoptions "-n" &&
477 test_tick &&
478 git merge --stat c2 >diffstat.txt &&
479 verify_merge file result.1-5 msg.1-5 &&
480 verify_parents $c1 $c2 &&
481 if ! grep "^ file | *2 +-$" diffstat.txt
482 then
483 echo "[OOPS] diffstat was not generated with --stat"
484 false
488 test_debug 'git log --graph --decorate --oneline --all'
490 test_expect_success 'override config option --stat' '
491 git reset --hard c1 &&
492 test_config branch.master.mergeoptions "--stat" &&
493 test_tick &&
494 git merge -n c2 >diffstat.txt &&
495 verify_merge file result.1-5 msg.1-5 &&
496 verify_parents $c1 $c2 &&
497 if grep "^ file | *2 +-$" diffstat.txt
498 then
499 echo "[OOPS] diffstat was generated"
500 false
504 test_debug 'git log --graph --decorate --oneline --all'
506 test_expect_success 'merge c1 with c2 (override --no-commit)' '
507 git reset --hard c1 &&
508 test_config branch.master.mergeoptions "--no-commit" &&
509 test_tick &&
510 git merge --commit c2 &&
511 verify_merge file result.1-5 msg.1-5 &&
512 verify_parents $c1 $c2
515 test_debug 'git log --graph --decorate --oneline --all'
517 test_expect_success 'merge c1 with c2 (override --squash)' '
518 git reset --hard c1 &&
519 test_config branch.master.mergeoptions "--squash" &&
520 test_tick &&
521 git merge --no-squash c2 &&
522 verify_merge file result.1-5 msg.1-5 &&
523 verify_parents $c1 $c2
526 test_debug 'git log --graph --decorate --oneline --all'
528 test_expect_success 'merge c0 with c1 (no-ff)' '
529 git reset --hard c0 &&
530 test_tick &&
531 git merge --no-ff c1 &&
532 verify_merge file result.1 &&
533 verify_parents $c0 $c1
536 test_debug 'git log --graph --decorate --oneline --all'
538 test_expect_success 'merge c0 with c1 (merge.ff=false)' '
539 git reset --hard c0 &&
540 test_config merge.ff "false" &&
541 test_tick &&
542 git merge c1 &&
543 verify_merge file result.1 &&
544 verify_parents $c0 $c1
546 test_debug 'git log --graph --decorate --oneline --all'
548 test_expect_success 'combine branch.master.mergeoptions with merge.ff' '
549 git reset --hard c0 &&
550 test_config branch.master.mergeoptions "--ff" &&
551 test_config merge.ff "false" &&
552 test_tick &&
553 git merge c1 &&
554 verify_merge file result.1 &&
555 verify_parents "$c0"
558 test_expect_success 'tolerate unknown values for merge.ff' '
559 git reset --hard c0 &&
560 test_config merge.ff "something-new" &&
561 test_tick &&
562 git merge c1 2>message &&
563 verify_head "$c1" &&
564 test_must_be_empty message
567 test_expect_success 'combining --squash and --no-ff is refused' '
568 git reset --hard c0 &&
569 test_must_fail git merge --squash --no-ff c1 &&
570 test_must_fail git merge --no-ff --squash c1
573 test_expect_success 'combining --squash and --commit is refused' '
574 git reset --hard c0 &&
575 test_must_fail git merge --squash --commit c1 &&
576 test_must_fail git merge --commit --squash c1
579 test_expect_success 'option --ff-only overwrites --no-ff' '
580 git merge --no-ff --ff-only c1 &&
581 test_must_fail git merge --no-ff --ff-only c2
584 test_expect_success 'option --no-ff overrides merge.ff=only config' '
585 git reset --hard c0 &&
586 test_config merge.ff only &&
587 git merge --no-ff c1
590 test_expect_success 'merge c0 with c1 (ff overrides no-ff)' '
591 git reset --hard c0 &&
592 test_config branch.master.mergeoptions "--no-ff" &&
593 git merge --ff c1 &&
594 verify_merge file result.1 &&
595 verify_head $c1
598 test_expect_success 'merge log message' '
599 git reset --hard c0 &&
600 git merge --no-log c2 &&
601 git show -s --pretty=format:%b HEAD >msg.act &&
602 test_must_be_empty msg.act &&
604 git reset --hard c0 &&
605 test_config branch.master.mergeoptions "--no-ff" &&
606 git merge --no-log c2 &&
607 git show -s --pretty=format:%b HEAD >msg.act &&
608 test_must_be_empty msg.act &&
610 git merge --log c3 &&
611 git show -s --pretty=format:%b HEAD >msg.act &&
612 test_cmp msg.log msg.act &&
614 git reset --hard HEAD^ &&
615 test_config merge.log "yes" &&
616 git merge c3 &&
617 git show -s --pretty=format:%b HEAD >msg.act &&
618 test_cmp msg.log msg.act
621 test_debug 'git log --graph --decorate --oneline --all'
623 test_expect_success 'merge c1 with c0, c2, c0, and c1' '
624 git reset --hard c1 &&
625 test_tick &&
626 git merge c0 c2 c0 c1 &&
627 verify_merge file result.1-5 &&
628 verify_parents $c1 $c2
631 test_debug 'git log --graph --decorate --oneline --all'
633 test_expect_success 'merge c1 with c0, c2, c0, and c1' '
634 git reset --hard c1 &&
635 test_tick &&
636 git merge c0 c2 c0 c1 &&
637 verify_merge file result.1-5 &&
638 verify_parents $c1 $c2
641 test_debug 'git log --graph --decorate --oneline --all'
643 test_expect_success 'merge c1 with c1 and c2' '
644 git reset --hard c1 &&
645 test_tick &&
646 git merge c1 c2 &&
647 verify_merge file result.1-5 &&
648 verify_parents $c1 $c2
651 test_debug 'git log --graph --decorate --oneline --all'
653 test_expect_success 'merge fast-forward in a dirty tree' '
654 git reset --hard c0 &&
655 mv file file1 &&
656 cat file1 >file &&
657 rm -f file1 &&
658 git merge c2
661 test_debug 'git log --graph --decorate --oneline --all'
663 test_expect_success 'in-index merge' '
664 git reset --hard c0 &&
665 git merge --no-ff -s resolve c1 >out &&
666 test_i18ngrep "Wonderful." out &&
667 verify_parents $c0 $c1
670 test_debug 'git log --graph --decorate --oneline --all'
672 test_expect_success 'refresh the index before merging' '
673 git reset --hard c1 &&
674 cp file file.n && mv -f file.n file &&
675 git merge c3
678 cat >expected.branch <<\EOF
679 Merge branch 'c5-branch' (early part)
681 cat >expected.tag <<\EOF
682 Merge commit 'c5~1'
685 test_expect_success 'merge early part of c2' '
686 git reset --hard c3 &&
687 echo c4 >c4.c &&
688 git add c4.c &&
689 git commit -m c4 &&
690 git tag c4 &&
691 echo c5 >c5.c &&
692 git add c5.c &&
693 git commit -m c5 &&
694 git tag c5 &&
695 git reset --hard c3 &&
696 echo c6 >c6.c &&
697 git add c6.c &&
698 git commit -m c6 &&
699 git tag c6 &&
700 git branch -f c5-branch c5 &&
701 git merge c5-branch~1 &&
702 git show -s --pretty=tformat:%s HEAD >actual.branch &&
703 git reset --keep HEAD^ &&
704 git merge c5~1 &&
705 git show -s --pretty=tformat:%s HEAD >actual.tag &&
706 test_cmp expected.branch actual.branch &&
707 test_cmp expected.tag actual.tag
710 test_debug 'git log --graph --decorate --oneline --all'
712 test_expect_success 'merge --no-ff --no-commit && commit' '
713 git reset --hard c0 &&
714 git merge --no-ff --no-commit c1 &&
715 EDITOR=: git commit &&
716 verify_parents $c0 $c1
719 test_debug 'git log --graph --decorate --oneline --all'
721 test_expect_success 'amending no-ff merge commit' '
722 EDITOR=: git commit --amend &&
723 verify_parents $c0 $c1
726 test_debug 'git log --graph --decorate --oneline --all'
728 cat >editor <<\EOF
729 #!/bin/sh
730 # Add a new message string that was not in the template
732 echo "Merge work done on the side branch c1"
733 echo
734 cat "$1"
735 ) >"$1.tmp" && mv "$1.tmp" "$1"
736 # strip comments and blank lines from end of message
737 sed -e '/^#/d' "$1" | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' >expected
739 chmod 755 editor
741 test_expect_success 'merge --no-ff --edit' '
742 git reset --hard c0 &&
743 EDITOR=./editor git merge --no-ff --edit c1 &&
744 verify_parents $c0 $c1 &&
745 git cat-file commit HEAD >raw &&
746 grep "work done on the side branch" raw &&
747 sed "1,/^$/d" >actual raw &&
748 test_cmp expected actual
751 test_expect_success 'merge annotated/signed tag w/o tracking' '
752 test_when_finished "rm -rf dst; git tag -d anno1" &&
753 git tag -a -m "anno c1" anno1 c1 &&
754 git init dst &&
755 git rev-parse c1 >dst/expect &&
757 # c0 fast-forwards to c1 but because this repository
758 # is not a "downstream" whose refs/tags follows along
759 # tag from the "upstream", this pull defaults to --no-ff
760 cd dst &&
761 git pull .. c0 &&
762 git pull .. anno1 &&
763 git rev-parse HEAD^2 >actual &&
764 test_cmp expect actual
768 test_expect_success 'merge annotated/signed tag w/ tracking' '
769 test_when_finished "rm -rf dst; git tag -d anno1" &&
770 git tag -a -m "anno c1" anno1 c1 &&
771 git init dst &&
772 git rev-parse c1 >dst/expect &&
774 # c0 fast-forwards to c1 and because this repository
775 # is a "downstream" whose refs/tags follows along
776 # tag from the "upstream", this pull defaults to --ff
777 cd dst &&
778 git remote add origin .. &&
779 git pull origin c0 &&
780 git fetch origin &&
781 git merge anno1 &&
782 git rev-parse HEAD >actual &&
783 test_cmp expect actual
787 test_expect_success GPG 'merge --ff-only tag' '
788 git reset --hard c0 &&
789 git commit --allow-empty -m "A newer commit" &&
790 git tag -s -m "A newer commit" signed &&
791 git reset --hard c0 &&
793 git merge --ff-only signed &&
794 git rev-parse signed^0 >expect &&
795 git rev-parse HEAD >actual &&
796 test_cmp expect actual
799 test_expect_success GPG 'merge --no-edit tag should skip editor' '
800 git reset --hard c0 &&
801 git commit --allow-empty -m "A newer commit" &&
802 git tag -f -s -m "A newer commit" signed &&
803 git reset --hard c0 &&
805 EDITOR=false git merge --no-edit --no-ff signed &&
806 git rev-parse signed^0 >expect &&
807 git rev-parse HEAD^2 >actual &&
808 test_cmp expect actual
811 test_expect_success 'set up mod-256 conflict scenario' '
812 # 256 near-identical stanzas...
813 for i in $(test_seq 1 256); do
814 for j in 1 2 3 4 5; do
815 echo $i-$j
816 done
817 done >file &&
818 git add file &&
819 git commit -m base &&
821 # one side changes the first line of each to "master"
822 sed s/-1/-master/ file >tmp &&
823 mv tmp file &&
824 git commit -am master &&
826 # and the other to "side"; merging the two will
827 # yield 256 separate conflicts
828 git checkout -b side HEAD^ &&
829 sed s/-1/-side/ file >tmp &&
830 mv tmp file &&
831 git commit -am side
834 test_expect_success 'merge detects mod-256 conflicts (recursive)' '
835 git reset --hard &&
836 test_must_fail git merge -s recursive master
839 test_expect_success 'merge detects mod-256 conflicts (resolve)' '
840 git reset --hard &&
841 test_must_fail git merge -s resolve master
844 test_expect_success 'merge nothing into void' '
845 git init void &&
847 cd void &&
848 git remote add up .. &&
849 git fetch up &&
850 test_must_fail git merge FETCH_HEAD
854 test_expect_success 'merge can be completed with --continue' '
855 git reset --hard c0 &&
856 git merge --no-ff --no-commit c1 &&
857 git merge --continue &&
858 verify_parents $c0 $c1
861 write_script .git/FAKE_EDITOR <<EOF
862 # kill -TERM command added below.
865 test_expect_success EXECKEEPSPID 'killed merge can be completed with --continue' '
866 git reset --hard c0 &&
867 ! "$SHELL_PATH" -c '\''
868 echo kill -TERM $$ >>.git/FAKE_EDITOR
869 GIT_EDITOR=.git/FAKE_EDITOR
870 export GIT_EDITOR
871 exec git merge --no-ff --edit c1'\'' &&
872 git merge --continue &&
873 verify_parents $c0 $c1
876 test_expect_success 'merge --quit' '
877 git init merge-quit &&
879 cd merge-quit &&
880 test_commit base &&
881 echo one >>base.t &&
882 git commit -am one &&
883 git branch one &&
884 git checkout base &&
885 echo two >>base.t &&
886 git commit -am two &&
887 test_must_fail git -c rerere.enabled=true merge one &&
888 test_path_is_file .git/MERGE_HEAD &&
889 test_path_is_file .git/MERGE_MODE &&
890 test_path_is_file .git/MERGE_MSG &&
891 git rerere status >rerere.before &&
892 git merge --quit &&
893 test_path_is_missing .git/MERGE_HEAD &&
894 test_path_is_missing .git/MERGE_MODE &&
895 test_path_is_missing .git/MERGE_MSG &&
896 git rerere status >rerere.after &&
897 test_must_be_empty rerere.after &&
898 ! test_cmp rerere.after rerere.before
902 test_expect_success 'merge suggests matching remote refname' '
903 git commit --allow-empty -m not-local &&
904 git update-ref refs/remotes/origin/not-local HEAD &&
905 git reset --hard HEAD^ &&
907 # This is white-box testing hackery; we happen to know
908 # that reading packed refs is more picky about the memory
909 # ownership of strings we pass to for_each_ref() callbacks.
910 git pack-refs --all --prune &&
912 test_must_fail git merge not-local 2>stderr &&
913 grep origin/not-local stderr
916 test_expect_success 'suggested names are not ambiguous' '
917 git update-ref refs/heads/origin/not-local HEAD &&
918 test_must_fail git merge not-local 2>stderr &&
919 grep remotes/origin/not-local stderr
922 test_done