l10n: bg.po: Updated Bulgarian translation (5211t)
[git/debian.git] / t / t7600-merge.sh
blobc773e30b3fa17bc129ca78afe3aef9194d77cb1d
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 * [main] Merge commit 'c1'
18 --------
19 - [main] 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 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
30 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
32 . ./test-lib.sh
33 . "$TEST_DIRECTORY"/lib-gpg.sh
35 test_write_lines 1 2 3 4 5 6 7 8 9 >file
36 cp file file.orig
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:" &&
54 echo &&
55 git log --no-merges ^HEAD c1
56 } >squash.1 &&
58 echo "Squashed commit of the following:" &&
59 echo &&
60 git log --no-merges ^HEAD c2
61 } >squash.1-5 &&
63 echo "Squashed commit of the following:" &&
64 echo &&
65 git log --no-merges ^HEAD c2 c3
66 } >squash.1-5-9 &&
68 echo "* tag 'c3':" &&
69 echo " commit 3"
70 } >msg.log
73 verify_merge () {
74 test_cmp "$2" "$1" &&
75 git update-index --refresh &&
76 git diff --exit-code &&
77 if test -n "$3"
78 then
79 git show -s --pretty=tformat:%s HEAD >msg.act &&
80 test_cmp "$3" msg.act
84 verify_head () {
85 echo "$1" >head.expected &&
86 git rev-parse HEAD >head.actual &&
87 test_cmp head.expected head.actual
90 verify_parents () {
91 test_write_lines "$@" >parents.expected &&
92 >parents.actual &&
93 i=1 &&
94 while test $i -le $#
96 git rev-parse HEAD^$i >>parents.actual &&
97 i=$(expr $i + 1) ||
98 return 1
99 done &&
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 &&
106 while read sha1 rest
108 git rev-parse $sha1
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' '
118 git add file &&
119 test_tick &&
120 git commit -m "commit 0" &&
121 git tag c0 &&
122 c0=$(git rev-parse HEAD) &&
123 cp file.1 file &&
124 git add file &&
125 cp file.1 other &&
126 git add other &&
127 test_tick &&
128 git commit -m "commit 1" &&
129 git tag c1 &&
130 c1=$(git rev-parse HEAD) &&
131 git reset --hard "$c0" &&
132 cp file.5 file &&
133 git add file &&
134 test_tick &&
135 git commit -m "commit 2" &&
136 git tag c2 &&
137 c2=$(git rev-parse HEAD) &&
138 git reset --hard "$c0" &&
139 cp file.9y file &&
140 git add file &&
141 test_tick &&
142 git commit -m "commit 7" &&
143 git tag c7 &&
144 git reset --hard "$c0" &&
145 cp file.9 file &&
146 git add file &&
147 test_tick &&
148 git commit -m "commit 3" &&
149 git tag c3 &&
150 c3=$(git rev-parse HEAD) &&
151 git reset --hard "$c0" &&
152 create_merge_msgs
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' '
171 mkdir broken &&
173 cd broken &&
174 git init &&
175 >.git/index &&
176 test_expect_code 129 git merge -h 2>usage
177 ) &&
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 &&
189 git merge c1 &&
190 verify_merge file result.1 &&
191 verify_head "$c1" &&
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 &&
205 verify_head "$c1"
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" &&
218 git rm -fr . &&
219 test_tick &&
220 git merge --ff-only c1 &&
221 verify_merge file result.1 &&
222 verify_head "$c1" &&
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 &&
233 test_tick &&
234 git merge c2 &&
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:
248 $(git show -s c7)
250 # Conflicts:
251 # file
253 git cat-file commit HEAD >raw &&
254 sed -e "1,/^$/d" raw >actual &&
255 test_cmp expect actual
258 test_expect_success 'merge c3 with c7 with commit.cleanup = scissors' '
259 git config commit.cleanup scissors &&
260 git reset --hard c3 &&
261 test_must_fail git merge c7 &&
262 cat result.9z >file &&
263 git commit --no-edit -a &&
265 cat >expect <<-\EOF &&
266 Merge tag '"'"'c7'"'"'
268 # ------------------------ >8 ------------------------
269 # Do not modify or remove the line above.
270 # Everything below it will be ignored.
272 # Conflicts:
273 # file
275 git cat-file commit HEAD >raw &&
276 sed -e "1,/^$/d" raw >actual &&
277 test_cmp expect actual
280 test_expect_success 'merge c3 with c7 with --squash commit.cleanup = scissors' '
281 git config commit.cleanup scissors &&
282 git reset --hard c3 &&
283 test_must_fail git merge --squash c7 &&
284 cat result.9z >file &&
285 git commit --no-edit -a &&
287 cat >expect <<-EOF &&
288 Squashed commit of the following:
290 $(git show -s c7)
292 # ------------------------ >8 ------------------------
293 # Do not modify or remove the line above.
294 # Everything below it will be ignored.
296 # Conflicts:
297 # file
299 git cat-file commit HEAD >raw &&
300 sed -e "1,/^$/d" raw >actual &&
301 test_cmp expect actual
304 test_debug 'git log --graph --decorate --oneline --all'
306 test_expect_success 'merge c1 with c2 and c3' '
307 git reset --hard c1 &&
308 test_tick &&
309 git merge c2 c3 &&
310 verify_merge file result.1-5-9 msg.1-5-9 &&
311 verify_parents $c1 $c2 $c3
314 test_debug 'git log --graph --decorate --oneline --all'
316 test_expect_success 'merges with --ff-only' '
317 git reset --hard c1 &&
318 test_tick &&
319 test_must_fail git merge --ff-only c2 &&
320 test_must_fail git merge --ff-only c3 &&
321 test_must_fail git merge --ff-only c2 c3 &&
322 git reset --hard c0 &&
323 git merge c3 &&
324 verify_head $c3
327 test_expect_success 'merges with merge.ff=only' '
328 git reset --hard c1 &&
329 test_tick &&
330 test_config merge.ff "only" &&
331 test_must_fail git merge c2 &&
332 test_must_fail git merge c3 &&
333 test_must_fail git merge c2 c3 &&
334 git reset --hard c0 &&
335 git merge c3 &&
336 verify_head $c3
339 test_expect_success 'merge c0 with c1 (no-commit)' '
340 git reset --hard c0 &&
341 git merge --no-commit c1 &&
342 verify_merge file result.1 &&
343 verify_head $c1
346 test_debug 'git log --graph --decorate --oneline --all'
348 test_expect_success 'merge c1 with c2 (no-commit)' '
349 git reset --hard c1 &&
350 git merge --no-commit c2 &&
351 verify_merge file result.1-5 &&
352 verify_head $c1 &&
353 verify_mergeheads $c2
356 test_debug 'git log --graph --decorate --oneline --all'
358 test_expect_success 'merge c1 with c2 and c3 (no-commit)' '
359 git reset --hard c1 &&
360 git merge --no-commit c2 c3 &&
361 verify_merge file result.1-5-9 &&
362 verify_head $c1 &&
363 verify_mergeheads $c2 $c3
366 test_debug 'git log --graph --decorate --oneline --all'
368 test_expect_success 'merge c0 with c1 (squash)' '
369 git reset --hard c0 &&
370 git merge --squash c1 &&
371 verify_merge file result.1 &&
372 verify_head $c0 &&
373 verify_no_mergehead &&
374 test_cmp squash.1 .git/SQUASH_MSG
377 test_debug 'git log --graph --decorate --oneline --all'
379 test_expect_success 'merge c0 with c1 (squash, ff-only)' '
380 git reset --hard c0 &&
381 git merge --squash --ff-only c1 &&
382 verify_merge file result.1 &&
383 verify_head $c0 &&
384 verify_no_mergehead &&
385 test_cmp squash.1 .git/SQUASH_MSG
388 test_debug 'git log --graph --decorate --oneline --all'
390 test_expect_success 'merge c1 with c2 (squash)' '
391 git reset --hard c1 &&
392 git merge --squash c2 &&
393 verify_merge file result.1-5 &&
394 verify_head $c1 &&
395 verify_no_mergehead &&
396 test_cmp squash.1-5 .git/SQUASH_MSG
399 test_debug 'git log --graph --decorate --oneline --all'
401 test_expect_success 'unsuccessful merge of c1 with c2 (squash, ff-only)' '
402 git reset --hard c1 &&
403 test_must_fail git merge --squash --ff-only c2
406 test_debug 'git log --graph --decorate --oneline --all'
408 test_expect_success 'merge c1 with c2 and c3 (squash)' '
409 git reset --hard c1 &&
410 git merge --squash c2 c3 &&
411 verify_merge file result.1-5-9 &&
412 verify_head $c1 &&
413 verify_no_mergehead &&
414 test_cmp squash.1-5-9 .git/SQUASH_MSG
417 test_debug 'git log --graph --decorate --oneline --all'
419 test_expect_success 'merge c1 with c2 (no-commit in config)' '
420 git reset --hard c1 &&
421 test_config branch.main.mergeoptions "--no-commit" &&
422 git merge c2 &&
423 verify_merge file result.1-5 &&
424 verify_head $c1 &&
425 verify_mergeheads $c2
428 test_debug 'git log --graph --decorate --oneline --all'
430 test_expect_success 'merge c1 with c2 (log in config)' '
431 git reset --hard c1 &&
432 git merge --log c2 &&
433 git show -s --pretty=tformat:%s%n%b >expect &&
435 test_config branch.main.mergeoptions "--log" &&
436 git reset --hard c1 &&
437 git merge c2 &&
438 git show -s --pretty=tformat:%s%n%b >actual &&
440 test_cmp expect actual
443 test_expect_success 'merge c1 with c2 (log in config gets overridden)' '
444 git reset --hard c1 &&
445 git merge c2 &&
446 git show -s --pretty=tformat:%s%n%b >expect &&
448 test_config branch.main.mergeoptions "--no-log" &&
449 test_config merge.log "true" &&
450 git reset --hard c1 &&
451 git merge c2 &&
452 git show -s --pretty=tformat:%s%n%b >actual &&
454 test_cmp expect actual
457 test_expect_success 'merge c1 with c2 (squash in config)' '
458 git reset --hard c1 &&
459 test_config branch.main.mergeoptions "--squash" &&
460 git merge c2 &&
461 verify_merge file result.1-5 &&
462 verify_head $c1 &&
463 verify_no_mergehead &&
464 test_cmp squash.1-5 .git/SQUASH_MSG
467 test_debug 'git log --graph --decorate --oneline --all'
469 test_expect_success 'override config option -n with --summary' '
470 git reset --hard c1 &&
471 test_config branch.main.mergeoptions "-n" &&
472 test_tick &&
473 git merge --summary c2 >diffstat.txt &&
474 verify_merge file result.1-5 msg.1-5 &&
475 verify_parents $c1 $c2 &&
476 if ! grep "^ file | *2 +-$" diffstat.txt
477 then
478 echo "[OOPS] diffstat was not generated with --summary"
479 false
483 test_expect_success 'override config option -n with --stat' '
484 git reset --hard c1 &&
485 test_config branch.main.mergeoptions "-n" &&
486 test_tick &&
487 git merge --stat c2 >diffstat.txt &&
488 verify_merge file result.1-5 msg.1-5 &&
489 verify_parents $c1 $c2 &&
490 if ! grep "^ file | *2 +-$" diffstat.txt
491 then
492 echo "[OOPS] diffstat was not generated with --stat"
493 false
497 test_debug 'git log --graph --decorate --oneline --all'
499 test_expect_success 'override config option --stat' '
500 git reset --hard c1 &&
501 test_config branch.main.mergeoptions "--stat" &&
502 test_tick &&
503 git merge -n c2 >diffstat.txt &&
504 verify_merge file result.1-5 msg.1-5 &&
505 verify_parents $c1 $c2 &&
506 if grep "^ file | *2 +-$" diffstat.txt
507 then
508 echo "[OOPS] diffstat was generated"
509 false
513 test_debug 'git log --graph --decorate --oneline --all'
515 test_expect_success 'merge c1 with c2 (override --no-commit)' '
516 git reset --hard c1 &&
517 test_config branch.main.mergeoptions "--no-commit" &&
518 test_tick &&
519 git merge --commit c2 &&
520 verify_merge file result.1-5 msg.1-5 &&
521 verify_parents $c1 $c2
524 test_debug 'git log --graph --decorate --oneline --all'
526 test_expect_success 'merge c1 with c2 (override --squash)' '
527 git reset --hard c1 &&
528 test_config branch.main.mergeoptions "--squash" &&
529 test_tick &&
530 git merge --no-squash c2 &&
531 verify_merge file result.1-5 msg.1-5 &&
532 verify_parents $c1 $c2
535 test_debug 'git log --graph --decorate --oneline --all'
537 test_expect_success 'merge c0 with c1 (no-ff)' '
538 git reset --hard c0 &&
539 test_tick &&
540 git merge --no-ff c1 &&
541 verify_merge file result.1 &&
542 verify_parents $c0 $c1
545 test_debug 'git log --graph --decorate --oneline --all'
547 test_expect_success 'merge c0 with c1 (merge.ff=false)' '
548 git reset --hard c0 &&
549 test_config merge.ff "false" &&
550 test_tick &&
551 git merge c1 &&
552 verify_merge file result.1 &&
553 verify_parents $c0 $c1
555 test_debug 'git log --graph --decorate --oneline --all'
557 test_expect_success 'combine branch.main.mergeoptions with merge.ff' '
558 git reset --hard c0 &&
559 test_config branch.main.mergeoptions "--ff" &&
560 test_config merge.ff "false" &&
561 test_tick &&
562 git merge c1 &&
563 verify_merge file result.1 &&
564 verify_parents "$c0"
567 test_expect_success 'tolerate unknown values for merge.ff' '
568 git reset --hard c0 &&
569 test_config merge.ff "something-new" &&
570 test_tick &&
571 git merge c1 2>message &&
572 verify_head "$c1" &&
573 test_must_be_empty message
576 test_expect_success 'combining --squash and --no-ff is refused' '
577 git reset --hard c0 &&
578 test_must_fail git merge --squash --no-ff c1 &&
579 test_must_fail git merge --no-ff --squash c1
582 test_expect_success 'combining --squash and --commit is refused' '
583 git reset --hard c0 &&
584 test_must_fail git merge --squash --commit c1 &&
585 test_must_fail git merge --commit --squash c1
588 test_expect_success 'option --ff-only overwrites --no-ff' '
589 git merge --no-ff --ff-only c1 &&
590 test_must_fail git merge --no-ff --ff-only c2
593 test_expect_success 'option --no-ff overrides merge.ff=only config' '
594 git reset --hard c0 &&
595 test_config merge.ff only &&
596 git merge --no-ff c1
599 test_expect_success 'merge c0 with c1 (ff overrides no-ff)' '
600 git reset --hard c0 &&
601 test_config branch.main.mergeoptions "--no-ff" &&
602 git merge --ff c1 &&
603 verify_merge file result.1 &&
604 verify_head $c1
607 test_expect_success 'merge log message' '
608 git reset --hard c0 &&
609 git merge --no-log c2 &&
610 git show -s --pretty=format:%b HEAD >msg.act &&
611 test_must_be_empty msg.act &&
613 git reset --hard c0 &&
614 test_config branch.main.mergeoptions "--no-ff" &&
615 git merge --no-log c2 &&
616 git show -s --pretty=format:%b HEAD >msg.act &&
617 test_must_be_empty msg.act &&
619 git merge --log c3 &&
620 git show -s --pretty=format:%b HEAD >msg.act &&
621 test_cmp msg.log msg.act &&
623 git reset --hard HEAD^ &&
624 test_config merge.log "yes" &&
625 git merge c3 &&
626 git show -s --pretty=format:%b HEAD >msg.act &&
627 test_cmp msg.log msg.act
630 test_debug 'git log --graph --decorate --oneline --all'
632 test_expect_success 'merge c1 with c0, c2, c0, and c1' '
633 git reset --hard c1 &&
634 test_tick &&
635 git merge c0 c2 c0 c1 &&
636 verify_merge file result.1-5 &&
637 verify_parents $c1 $c2
640 test_debug 'git log --graph --decorate --oneline --all'
642 test_expect_success 'merge c1 with c0, c2, c0, and c1' '
643 git reset --hard c1 &&
644 test_tick &&
645 git merge c0 c2 c0 c1 &&
646 verify_merge file result.1-5 &&
647 verify_parents $c1 $c2
650 test_debug 'git log --graph --decorate --oneline --all'
652 test_expect_success 'merge c1 with c1 and c2' '
653 git reset --hard c1 &&
654 test_tick &&
655 git merge c1 c2 &&
656 verify_merge file result.1-5 &&
657 verify_parents $c1 $c2
660 test_debug 'git log --graph --decorate --oneline --all'
662 test_expect_success 'merge fast-forward in a dirty tree' '
663 git reset --hard c0 &&
664 mv file file1 &&
665 cat file1 >file &&
666 rm -f file1 &&
667 git merge c2
670 test_debug 'git log --graph --decorate --oneline --all'
672 test_expect_success 'in-index merge' '
673 git reset --hard c0 &&
674 git merge --no-ff -s resolve c1 >out &&
675 test_i18ngrep "Wonderful." out &&
676 verify_parents $c0 $c1
679 test_debug 'git log --graph --decorate --oneline --all'
681 test_expect_success 'refresh the index before merging' '
682 git reset --hard c1 &&
683 cp file file.n && mv -f file.n file &&
684 git merge c3
687 test_expect_success 'merge with --autostash' '
688 git reset --hard c1 &&
689 git merge-file file file.orig file.9 &&
690 git merge --autostash c2 2>err &&
691 test_i18ngrep "Applied autostash." err &&
692 git show HEAD:file >merge-result &&
693 test_cmp result.1-5 merge-result &&
694 test_cmp result.1-5-9 file
697 test_expect_success 'merge with merge.autoStash' '
698 test_config merge.autoStash true &&
699 git reset --hard c1 &&
700 git merge-file file file.orig file.9 &&
701 git merge c2 2>err &&
702 test_i18ngrep "Applied autostash." err &&
703 git show HEAD:file >merge-result &&
704 test_cmp result.1-5 merge-result &&
705 test_cmp result.1-5-9 file
708 test_expect_success 'fast-forward merge with --autostash' '
709 git reset --hard c0 &&
710 git merge-file file file.orig file.5 &&
711 git merge --autostash c1 2>err &&
712 test_i18ngrep "Applied autostash." err &&
713 test_cmp result.1-5 file
716 test_expect_success 'failed fast-forward merge with --autostash' '
717 git reset --hard c0 &&
718 git merge-file file file.orig file.5 &&
719 cp file.5 other &&
720 test_when_finished "rm other" &&
721 test_must_fail git merge --autostash c1 2>err &&
722 test_i18ngrep "Applied autostash." err &&
723 test_cmp file.5 file
726 test_expect_success 'octopus merge with --autostash' '
727 git reset --hard c1 &&
728 git merge-file file file.orig file.3 &&
729 git merge --autostash c2 c3 2>err &&
730 test_i18ngrep "Applied autostash." err &&
731 git show HEAD:file >merge-result &&
732 test_cmp result.1-5-9 merge-result &&
733 test_cmp result.1-3-5-9 file
736 test_expect_success 'failed merge (exit 2) with --autostash' '
737 git reset --hard c1 &&
738 git merge-file file file.orig file.5 &&
739 test_must_fail git merge -s recursive --autostash c2 c3 2>err &&
740 test_i18ngrep "Applied autostash." err &&
741 test_cmp result.1-5 file
744 test_expect_success 'conflicted merge with --autostash, --abort restores stash' '
745 git reset --hard c3 &&
746 cp file.1 file &&
747 test_must_fail git merge --autostash c7 &&
748 git merge --abort 2>err &&
749 test_i18ngrep "Applied autostash." err &&
750 test_cmp file.1 file
753 test_expect_success 'completed merge (git commit) with --no-commit and --autostash' '
754 git reset --hard c1 &&
755 git merge-file file file.orig file.9 &&
756 git diff >expect &&
757 git merge --no-commit --autostash c2 &&
758 git stash show -p MERGE_AUTOSTASH >actual &&
759 test_cmp expect actual &&
760 git commit 2>err &&
761 test_i18ngrep "Applied autostash." err &&
762 git show HEAD:file >merge-result &&
763 test_cmp result.1-5 merge-result &&
764 test_cmp result.1-5-9 file
767 test_expect_success 'completed merge (git merge --continue) with --no-commit and --autostash' '
768 git reset --hard c1 &&
769 git merge-file file file.orig file.9 &&
770 git diff >expect &&
771 git merge --no-commit --autostash c2 &&
772 git stash show -p MERGE_AUTOSTASH >actual &&
773 test_cmp expect actual &&
774 git merge --continue 2>err &&
775 test_i18ngrep "Applied autostash." err &&
776 git show HEAD:file >merge-result &&
777 test_cmp result.1-5 merge-result &&
778 test_cmp result.1-5-9 file
781 test_expect_success 'aborted merge (merge --abort) with --no-commit and --autostash' '
782 git reset --hard c1 &&
783 git merge-file file file.orig file.9 &&
784 git diff >expect &&
785 git merge --no-commit --autostash c2 &&
786 git stash show -p MERGE_AUTOSTASH >actual &&
787 test_cmp expect actual &&
788 git merge --abort 2>err &&
789 test_i18ngrep "Applied autostash." err &&
790 git diff >actual &&
791 test_cmp expect actual
794 test_expect_success 'aborted merge (reset --hard) with --no-commit and --autostash' '
795 git reset --hard c1 &&
796 git merge-file file file.orig file.9 &&
797 git diff >expect &&
798 git merge --no-commit --autostash c2 &&
799 git stash show -p MERGE_AUTOSTASH >actual &&
800 test_cmp expect actual &&
801 git reset --hard 2>err &&
802 test_i18ngrep "Autostash exists; creating a new stash entry." err &&
803 git diff --exit-code
806 test_expect_success 'quit merge with --no-commit and --autostash' '
807 git reset --hard c1 &&
808 git merge-file file file.orig file.9 &&
809 git diff >expect &&
810 git merge --no-commit --autostash c2 &&
811 git stash show -p MERGE_AUTOSTASH >actual &&
812 test_cmp expect actual &&
813 git diff HEAD >expect &&
814 git merge --quit 2>err &&
815 test_i18ngrep "Autostash exists; creating a new stash entry." err &&
816 git diff HEAD >actual &&
817 test_cmp expect actual
820 test_expect_success 'merge with conflicted --autostash changes' '
821 git reset --hard c1 &&
822 git merge-file file file.orig file.9y &&
823 git diff >expect &&
824 test_when_finished "test_might_fail git stash drop" &&
825 git merge --autostash c3 2>err &&
826 test_i18ngrep "Applying autostash resulted in conflicts." err &&
827 git show HEAD:file >merge-result &&
828 test_cmp result.1-9 merge-result &&
829 git stash show -p >actual &&
830 test_cmp expect actual
833 cat >expected.branch <<\EOF
834 Merge branch 'c5-branch' (early part)
836 cat >expected.tag <<\EOF
837 Merge commit 'c5~1'
840 test_expect_success 'merge early part of c2' '
841 git reset --hard c3 &&
842 echo c4 >c4.c &&
843 git add c4.c &&
844 git commit -m c4 &&
845 git tag c4 &&
846 echo c5 >c5.c &&
847 git add c5.c &&
848 git commit -m c5 &&
849 git tag c5 &&
850 git reset --hard c3 &&
851 echo c6 >c6.c &&
852 git add c6.c &&
853 git commit -m c6 &&
854 git tag c6 &&
855 git branch -f c5-branch c5 &&
856 git merge c5-branch~1 &&
857 git show -s --pretty=tformat:%s HEAD >actual.branch &&
858 git reset --keep HEAD^ &&
859 git merge c5~1 &&
860 git show -s --pretty=tformat:%s HEAD >actual.tag &&
861 test_cmp expected.branch actual.branch &&
862 test_cmp expected.tag actual.tag
865 test_debug 'git log --graph --decorate --oneline --all'
867 test_expect_success 'merge --no-ff --no-commit && commit' '
868 git reset --hard c0 &&
869 git merge --no-ff --no-commit c1 &&
870 EDITOR=: git commit &&
871 verify_parents $c0 $c1
874 test_debug 'git log --graph --decorate --oneline --all'
876 test_expect_success 'amending no-ff merge commit' '
877 EDITOR=: git commit --amend &&
878 verify_parents $c0 $c1
881 test_debug 'git log --graph --decorate --oneline --all'
883 cat >editor <<\EOF
884 #!/bin/sh
885 # Add a new message string that was not in the template
887 echo "Merge work done on the side branch c1"
888 echo
889 cat "$1"
890 ) >"$1.tmp" && mv "$1.tmp" "$1"
891 # strip comments and blank lines from end of message
892 sed -e '/^#/d' "$1" | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' >expected
894 chmod 755 editor
896 test_expect_success 'merge --no-ff --edit' '
897 git reset --hard c0 &&
898 EDITOR=./editor git merge --no-ff --edit c1 &&
899 verify_parents $c0 $c1 &&
900 git cat-file commit HEAD >raw &&
901 grep "work done on the side branch" raw &&
902 sed "1,/^$/d" >actual raw &&
903 test_cmp expected actual
906 test_expect_success 'merge annotated/signed tag w/o tracking' '
907 test_when_finished "rm -rf dst; git tag -d anno1" &&
908 git tag -a -m "anno c1" anno1 c1 &&
909 git init dst &&
910 git rev-parse c1 >dst/expect &&
912 # c0 fast-forwards to c1 but because this repository
913 # is not a "downstream" whose refs/tags follows along
914 # tag from the "upstream", this pull defaults to --no-ff
915 cd dst &&
916 git pull .. c0 &&
917 git pull .. anno1 &&
918 git rev-parse HEAD^2 >actual &&
919 test_cmp expect actual
923 test_expect_success 'merge annotated/signed tag w/ tracking' '
924 test_when_finished "rm -rf dst; git tag -d anno1" &&
925 git tag -a -m "anno c1" anno1 c1 &&
926 git init dst &&
927 git rev-parse c1 >dst/expect &&
929 # c0 fast-forwards to c1 and because this repository
930 # is a "downstream" whose refs/tags follows along
931 # tag from the "upstream", this pull defaults to --ff
932 cd dst &&
933 git remote add origin .. &&
934 git pull origin c0 &&
935 git fetch origin &&
936 git merge anno1 &&
937 git rev-parse HEAD >actual &&
938 test_cmp expect actual
942 test_expect_success GPG 'merge --ff-only tag' '
943 git reset --hard c0 &&
944 git commit --allow-empty -m "A newer commit" &&
945 git tag -s -m "A newer commit" signed &&
946 git reset --hard c0 &&
948 git merge --ff-only signed &&
949 git rev-parse signed^0 >expect &&
950 git rev-parse HEAD >actual &&
951 test_cmp expect actual
954 test_expect_success GPG 'merge --no-edit tag should skip editor' '
955 git reset --hard c0 &&
956 git commit --allow-empty -m "A newer commit" &&
957 git tag -f -s -m "A newer commit" signed &&
958 git reset --hard c0 &&
960 EDITOR=false git merge --no-edit --no-ff signed &&
961 git rev-parse signed^0 >expect &&
962 git rev-parse HEAD^2 >actual &&
963 test_cmp expect actual
966 test_expect_success 'set up mod-256 conflict scenario' '
967 # 256 near-identical stanzas...
968 for i in $(test_seq 1 256); do
969 for j in 1 2 3 4 5; do
970 echo $i-$j
971 done
972 done >file &&
973 git add file &&
974 git commit -m base &&
976 # one side changes the first line of each to "main"
977 sed s/-1/-main/ file >tmp &&
978 mv tmp file &&
979 git commit -am main &&
981 # and the other to "side"; merging the two will
982 # yield 256 separate conflicts
983 git checkout -b side HEAD^ &&
984 sed s/-1/-side/ file >tmp &&
985 mv tmp file &&
986 git commit -am side
989 test_expect_success 'merge detects mod-256 conflicts (recursive)' '
990 git reset --hard &&
991 test_must_fail git merge -s recursive main
994 test_expect_success 'merge detects mod-256 conflicts (resolve)' '
995 git reset --hard &&
996 test_must_fail git merge -s resolve main
999 test_expect_success 'merge nothing into void' '
1000 git init void &&
1002 cd void &&
1003 git remote add up .. &&
1004 git fetch up &&
1005 test_must_fail git merge FETCH_HEAD
1009 test_expect_success 'merge can be completed with --continue' '
1010 git reset --hard c0 &&
1011 git merge --no-ff --no-commit c1 &&
1012 git merge --continue &&
1013 verify_parents $c0 $c1
1016 write_script .git/FAKE_EDITOR <<EOF
1017 # kill -TERM command added below.
1020 test_expect_success EXECKEEPSPID 'killed merge can be completed with --continue' '
1021 git reset --hard c0 &&
1022 ! "$SHELL_PATH" -c '\''
1023 echo kill -TERM $$ >>.git/FAKE_EDITOR
1024 GIT_EDITOR=.git/FAKE_EDITOR
1025 export GIT_EDITOR
1026 exec git merge --no-ff --edit c1'\'' &&
1027 git merge --continue &&
1028 verify_parents $c0 $c1
1031 test_expect_success 'merge --quit' '
1032 git init merge-quit &&
1034 cd merge-quit &&
1035 test_commit base &&
1036 echo one >>base.t &&
1037 git commit -am one &&
1038 git branch one &&
1039 git checkout base &&
1040 echo two >>base.t &&
1041 git commit -am two &&
1042 test_must_fail git -c rerere.enabled=true merge one &&
1043 test_path_is_file .git/MERGE_HEAD &&
1044 test_path_is_file .git/MERGE_MODE &&
1045 test_path_is_file .git/MERGE_MSG &&
1046 git rerere status >rerere.before &&
1047 git merge --quit &&
1048 test_path_is_missing .git/MERGE_HEAD &&
1049 test_path_is_missing .git/MERGE_MODE &&
1050 test_path_is_missing .git/MERGE_MSG &&
1051 git rerere status >rerere.after &&
1052 test_must_be_empty rerere.after &&
1053 ! test_cmp rerere.after rerere.before
1057 test_expect_success 'merge suggests matching remote refname' '
1058 git commit --allow-empty -m not-local &&
1059 git update-ref refs/remotes/origin/not-local HEAD &&
1060 git reset --hard HEAD^ &&
1062 # This is white-box testing hackery; we happen to know
1063 # that reading packed refs is more picky about the memory
1064 # ownership of strings we pass to for_each_ref() callbacks.
1065 git pack-refs --all --prune &&
1067 test_must_fail git merge not-local 2>stderr &&
1068 grep origin/not-local stderr
1071 test_expect_success 'suggested names are not ambiguous' '
1072 git update-ref refs/heads/origin/not-local HEAD &&
1073 test_must_fail git merge not-local 2>stderr &&
1074 grep remotes/origin/not-local stderr
1077 test_done