3 # Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 local testroot=`test_init merge_basic`
21 local commit0=`git_show_head $testroot/repo`
22 local commit0_author_time=`git_show_author_time $testroot/repo`
24 git -C $testroot/repo checkout -q -b newbranch
25 echo "modified delta on branch" > $testroot/repo/gamma/delta
26 git_commit $testroot/repo -m "committing to delta on newbranch"
27 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
29 echo "modified alpha on branch" > $testroot/repo/alpha
30 git_commit $testroot/repo -m "committing to alpha on newbranch"
31 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
32 git -C $testroot/repo rm -q beta
33 git_commit $testroot/repo -m "removing beta on newbranch"
34 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
35 echo "new file on branch" > $testroot/repo/epsilon/new
36 git -C $testroot/repo add epsilon/new
37 git_commit $testroot/repo -m "adding new file on newbranch"
38 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
39 (cd $testroot/repo && ln -s alpha symlink)
40 git -C $testroot/repo add symlink
41 git_commit $testroot/repo -m "adding symlink on newbranch"
42 local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
43 (cd $testroot/repo && ln -sf .got/bar dotgotbar.link)
44 git -C $testroot/repo add dotgotbar.link
45 git_commit $testroot/repo -m "adding a bad symlink on newbranch"
46 local branch_commit5=`git_show_branch_head $testroot/repo newbranch`
48 got checkout -b master $testroot/repo $testroot/wt > /dev/null
50 if [ $ret -ne 0 ]; then
51 echo "got checkout failed unexpectedly" >&2
52 test_done "$testroot" "$ret"
56 # create a divergent commit
57 git -C $testroot/repo checkout -q master
58 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
59 git_commit $testroot/repo -m "committing to zeta on master"
60 local master_commit=`git_show_head $testroot/repo`
62 # need an up-to-date work tree for 'got merge'
63 (cd $testroot/wt && got merge newbranch \
64 > $testroot/stdout 2> $testroot/stderr)
66 if [ $ret -eq 0 ]; then
67 echo "got merge succeeded unexpectedly" >&2
68 test_done "$testroot" "1"
71 echo -n "got: work tree must be updated before it can be used " \
72 > $testroot/stderr.expected
73 echo "to merge a branch" >> $testroot/stderr.expected
74 cmp -s $testroot/stderr.expected $testroot/stderr
76 if [ $ret -ne 0 ]; then
77 diff -u $testroot/stderr.expected $testroot/stderr
78 test_done "$testroot" "$ret"
82 (cd $testroot/wt && got update > /dev/null)
84 if [ $ret -ne 0 ]; then
85 echo "got update failed unexpectedly" >&2
86 test_done "$testroot" "$ret"
90 # must not use a mixed-commit work tree with 'got merge'
91 (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
93 if [ $ret -ne 0 ]; then
94 echo "got update failed unexpectedly" >&2
95 test_done "$testroot" "$ret"
98 (cd $testroot/wt && got merge newbranch \
99 > $testroot/stdout 2> $testroot/stderr)
101 if [ $ret -eq 0 ]; then
102 echo "got merge succeeded unexpectedly" >&2
103 test_done "$testroot" "1"
106 echo -n "got: work tree contains files from multiple base commits; " \
107 > $testroot/stderr.expected
108 echo "the entire work tree must be updated first" \
109 >> $testroot/stderr.expected
110 cmp -s $testroot/stderr.expected $testroot/stderr
112 if [ $ret -ne 0 ]; then
113 diff -u $testroot/stderr.expected $testroot/stderr
114 test_done "$testroot" "$ret"
118 (cd $testroot/wt && got update > /dev/null)
120 if [ $ret -ne 0 ]; then
121 echo "got update failed unexpectedly" >&2
122 test_done "$testroot" "$ret"
126 # must not have staged files with 'got merge'
127 echo "modified file alpha" > $testroot/wt/alpha
128 (cd $testroot/wt && got stage alpha > /dev/null)
130 if [ $ret -ne 0 ]; then
131 echo "got stage failed unexpectedly" >&2
132 test_done "$testroot" "$ret"
135 (cd $testroot/wt && got merge newbranch \
136 > $testroot/stdout 2> $testroot/stderr)
138 if [ $ret -eq 0 ]; then
139 echo "got merge succeeded unexpectedly" >&2
140 test_done "$testroot" "1"
143 echo "got: alpha: file is staged" > $testroot/stderr.expected
144 cmp -s $testroot/stderr.expected $testroot/stderr
146 if [ $ret -ne 0 ]; then
147 diff -u $testroot/stderr.expected $testroot/stderr
148 test_done "$testroot" "$ret"
151 (cd $testroot/wt && got unstage alpha > /dev/null)
153 if [ $ret -ne 0 ]; then
154 echo "got unstage failed unexpectedly" >&2
155 test_done "$testroot" "$ret"
159 # must not have local changes with 'got merge'
160 (cd $testroot/wt && got merge newbranch \
161 > $testroot/stdout 2> $testroot/stderr)
163 if [ $ret -eq 0 ]; then
164 echo "got merge succeeded unexpectedly" >&2
165 test_done "$testroot" "1"
168 echo -n "got: work tree contains local changes; " \
169 > $testroot/stderr.expected
170 echo "these changes must be committed or reverted first" \
171 >> $testroot/stderr.expected
172 cmp -s $testroot/stderr.expected $testroot/stderr
174 if [ $ret -ne 0 ]; then
175 diff -u $testroot/stderr.expected $testroot/stderr
176 test_done "$testroot" "$ret"
180 (cd $testroot/wt && got revert alpha > /dev/null)
182 if [ $ret -ne 0 ]; then
183 echo "got revert failed unexpectedly" >&2
184 test_done "$testroot" "$ret"
188 (cd $testroot/wt && got merge newbranch > $testroot/stdout)
190 if [ $ret -ne 0 ]; then
191 echo "got merge failed unexpectedly" >&2
192 test_done "$testroot" "$ret"
196 local merge_commit=`git_show_head $testroot/repo`
198 echo "G alpha" >> $testroot/stdout.expected
199 echo "D beta" >> $testroot/stdout.expected
200 echo "A dotgotbar.link" >> $testroot/stdout.expected
201 echo "A epsilon/new" >> $testroot/stdout.expected
202 echo "G gamma/delta" >> $testroot/stdout.expected
203 echo "A symlink" >> $testroot/stdout.expected
204 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
205 >> $testroot/stdout.expected
206 echo $merge_commit >> $testroot/stdout.expected
208 cmp -s $testroot/stdout.expected $testroot/stdout
210 if [ $ret -ne 0 ]; then
211 diff -u $testroot/stdout.expected $testroot/stdout
212 test_done "$testroot" "$ret"
216 echo "modified delta on branch" > $testroot/content.expected
217 cat $testroot/wt/gamma/delta > $testroot/content
218 cmp -s $testroot/content.expected $testroot/content
220 if [ $ret -ne 0 ]; then
221 diff -u $testroot/content.expected $testroot/content
222 test_done "$testroot" "$ret"
226 echo "modified alpha on branch" > $testroot/content.expected
227 cat $testroot/wt/alpha > $testroot/content
228 cmp -s $testroot/content.expected $testroot/content
230 if [ $ret -ne 0 ]; then
231 diff -u $testroot/content.expected $testroot/content
232 test_done "$testroot" "$ret"
236 if [ -e $testroot/wt/beta ]; then
237 echo "removed file beta still exists on disk" >&2
238 test_done "$testroot" "1"
242 echo "new file on branch" > $testroot/content.expected
243 cat $testroot/wt/epsilon/new > $testroot/content
244 cmp -s $testroot/content.expected $testroot/content
246 if [ $ret -ne 0 ]; then
247 diff -u $testroot/content.expected $testroot/content
248 test_done "$testroot" "$ret"
252 if [ ! -h $testroot/wt/dotgotbar.link ]; then
253 echo "dotgotbar.link is not a symlink"
254 test_done "$testroot" "1"
258 readlink $testroot/wt/symlink > $testroot/stdout
259 echo "alpha" > $testroot/stdout.expected
260 cmp -s $testroot/stdout.expected $testroot/stdout
262 if [ $ret -ne 0 ]; then
263 diff -u $testroot/stdout.expected $testroot/stdout
264 test_done "$testroot" "$ret"
268 (cd $testroot/wt && got status > $testroot/stdout)
270 echo -n > $testroot/stdout.expected
271 cmp -s $testroot/stdout.expected $testroot/stdout
273 if [ $ret -ne 0 ]; then
274 diff -u $testroot/stdout.expected $testroot/stdout
275 test_done "$testroot" "$ret"
279 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
280 echo "commit $merge_commit (master)" > $testroot/stdout.expected
281 echo "commit $master_commit" >> $testroot/stdout.expected
282 echo "commit $commit0" >> $testroot/stdout.expected
283 cmp -s $testroot/stdout.expected $testroot/stdout
285 if [ $ret -ne 0 ]; then
286 diff -u $testroot/stdout.expected $testroot/stdout
287 test_done "$testroot" "$ret"
291 (cd $testroot/wt && got update > $testroot/stdout)
293 echo 'U dotgotbar.link' > $testroot/stdout.expected
294 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
295 git_show_head $testroot/repo >> $testroot/stdout.expected
296 echo >> $testroot/stdout.expected
297 cmp -s $testroot/stdout.expected $testroot/stdout
299 if [ $ret -ne 0 ]; then
300 diff -u $testroot/stdout.expected $testroot/stdout
301 test_done "$testroot" "$ret"
305 # update has changed the bad symlink into a regular file
306 if [ -h $testroot/wt/dotgotbar.link ]; then
307 echo "dotgotbar.link is a symlink"
308 test_done "$testroot" "1"
312 # We should have created a merge commit with two parents.
313 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
314 echo "parent 1: $master_commit" > $testroot/stdout.expected
315 echo "parent 2: $branch_commit5" >> $testroot/stdout.expected
316 cmp -s $testroot/stdout.expected $testroot/stdout
318 if [ $ret -ne 0 ]; then
319 diff -u $testroot/stdout.expected $testroot/stdout
320 test_done "$testroot" "$ret"
324 got tree -r $testroot/repo -c $merge_commit -R > $testroot/stdout
326 if [ $ret -ne 0 ]; then
327 echo "got tree failed unexpectedly" >&2
328 test_done "$testroot" "$ret"
332 # bad symlink dotgotbar.link appears as a symlink in the merge commit:
333 cat > $testroot/stdout.expected <<EOF
335 dotgotbar.link@ -> .got/bar
343 cmp -s $testroot/stdout.expected $testroot/stdout
345 if [ $ret -ne 0 ]; then
346 diff -u $testroot/stdout.expected $testroot/stdout
348 test_done "$testroot" "$ret"
351 test_merge_forward() {
352 local testroot=`test_init merge_forward`
353 local commit0=`git_show_head $testroot/repo`
355 # Create a commit before branching, which will be used to help test
356 # preconditions for "got merge".
357 echo "modified alpha" > $testroot/repo/alpha
358 git_commit $testroot/repo -m "common commit"
359 local commit1=`git_show_head $testroot/repo`
361 git -C $testroot/repo checkout -q -b newbranch
362 echo "modified beta on branch" > $testroot/repo/beta
363 git_commit $testroot/repo -m "committing to beta on newbranch"
364 local commit2=`git_show_head $testroot/repo`
366 got checkout -b master $testroot/repo $testroot/wt > /dev/null
368 if [ $ret -ne 0 ]; then
369 echo "got checkout failed unexpectedly" >&2
370 test_done "$testroot" "$ret"
374 # must not use a mixed-commit work tree with 'got merge'
375 (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
377 if [ $ret -ne 0 ]; then
378 echo "got update failed unexpectedly" >&2
379 test_done "$testroot" "$ret"
382 (cd $testroot/wt && got merge newbranch \
383 > $testroot/stdout 2> $testroot/stderr)
385 if [ $ret -eq 0 ]; then
386 echo "got merge succeeded unexpectedly" >&2
387 test_done "$testroot" "$ret"
390 echo -n "got: work tree contains files from multiple base commits; " \
391 > $testroot/stderr.expected
392 echo "the entire work tree must be updated first" \
393 >> $testroot/stderr.expected
394 cmp -s $testroot/stderr.expected $testroot/stderr
396 if [ $ret -ne 0 ]; then
397 diff -u $testroot/stderr.expected $testroot/stderr
398 test_done "$testroot" "$ret"
402 (cd $testroot/wt && got update > /dev/null)
404 if [ $ret -ne 0 ]; then
405 echo "got update failed unexpectedly" >&2
406 test_done "$testroot" "$ret"
410 # 'got merge -n' refuses to fast-forward
411 (cd $testroot/wt && got merge -n newbranch \
412 > $testroot/stdout 2> $testroot/stderr)
414 if [ $ret -eq 0 ]; then
415 echo "got merge succeeded unexpectedly" >&2
416 test_done "$testroot" "1"
420 echo -n "got: there are no changes to merge since " \
421 > $testroot/stderr.expected
422 echo -n "refs/heads/newbranch is already based on " \
423 >> $testroot/stderr.expected
424 echo -n "refs/heads/master; merge cannot be interrupted " \
425 >> $testroot/stderr.expected
426 echo "for amending; -n: option cannot be used" \
427 >> $testroot/stderr.expected
429 cmp -s $testroot/stderr.expected $testroot/stderr
431 if [ $ret -ne 0 ]; then
432 diff -u $testroot/stderr.expected $testroot/stderr
433 test_done "$testroot" "$ret"
437 (cd $testroot/wt && got merge newbranch \
438 > $testroot/stdout 2> $testroot/stderr)
440 if [ $ret -ne 0 ]; then
441 echo "got merge failed unexpectedly" >&2
442 test_done "$testroot" "$ret"
446 echo "Forwarding refs/heads/master to refs/heads/newbranch" \
447 > $testroot/stdout.expected
448 echo "U beta" >> $testroot/stdout.expected
449 echo "Updated to commit $commit2" \
450 >> $testroot/stdout.expected
451 cmp -s $testroot/stdout.expected $testroot/stdout
453 if [ $ret -ne 0 ]; then
454 diff -u $testroot/stdout.expected $testroot/stdout
455 test_done "$testroot" "$ret"
459 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
460 echo -n "commit $commit2 " > $testroot/stdout.expected
461 echo "(master, newbranch)" >> $testroot/stdout.expected
462 echo "commit $commit1" >> $testroot/stdout.expected
463 echo "commit $commit0" >> $testroot/stdout.expected
464 cmp -s $testroot/stdout.expected $testroot/stdout
466 if [ $ret -ne 0 ]; then
467 diff -u $testroot/stdout.expected $testroot/stdout
468 test_done "$testroot" "$ret"
471 test_done "$testroot" "$ret"
474 test_merge_forward_commit() {
475 local testroot=`test_init merge_forward_commit`
476 local commit0=`git_show_head $testroot/repo`
478 git -C $testroot/repo checkout -q -b newbranch
479 echo "modified alpha on branch" > $testroot/repo/alpha
480 git_commit $testroot/repo -m "committing to alpha on newbranch"
481 local commit1=`git_show_head $testroot/repo`
483 got checkout -b master $testroot/repo $testroot/wt > /dev/null
485 if [ $ret -ne 0 ]; then
486 echo "got checkout failed unexpectedly" >&2
487 test_done "$testroot" "$ret"
491 (cd $testroot/wt && got merge -M newbranch > $testroot/stdout)
493 if [ $ret -ne 0 ]; then
494 echo "got merge failed unexpectedly" >&2
495 test_done "$testroot" "$ret"
499 local merge_commit=`git_show_branch_head $testroot/repo master`
501 echo "G alpha" >> $testroot/stdout.expected
502 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
503 >> $testroot/stdout.expected
504 echo $merge_commit >> $testroot/stdout.expected
506 cmp -s $testroot/stdout.expected $testroot/stdout
508 if [ $ret -ne 0 ]; then
509 diff -u $testroot/stdout.expected $testroot/stdout
510 test_done "$testroot" "$ret"
514 # We should have created a merge commit with two parents.
515 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
516 echo "parent 1: $commit0" > $testroot/stdout.expected
517 echo "parent 2: $commit1" >> $testroot/stdout.expected
518 cmp -s $testroot/stdout.expected $testroot/stdout
520 if [ $ret -ne 0 ]; then
521 diff -u $testroot/stdout.expected $testroot/stdout
522 test_done "$testroot" "$ret"
526 test_done "$testroot" "$ret"
529 test_merge_forward_interrupt() {
530 # Test -M and -n options together.
531 local testroot=`test_init merge_forward_commit`
532 local commit0=`git_show_head $testroot/repo`
534 git -C $testroot/repo checkout -q -b newbranch
535 echo "modified alpha on branch" > $testroot/repo/alpha
536 git_commit $testroot/repo -m "committing to alpha on newbranch"
537 local commit1=`git_show_head $testroot/repo`
539 got checkout -b master $testroot/repo $testroot/wt > /dev/null
541 if [ $ret -ne 0 ]; then
542 echo "got checkout failed unexpectedly" >&2
543 test_done "$testroot" "$ret"
547 (cd $testroot/wt && got merge -M -n newbranch > $testroot/stdout)
549 if [ $ret -ne 0 ]; then
550 echo "got merge failed unexpectedly" >&2
551 test_done "$testroot" "$ret"
555 echo "G alpha" > $testroot/stdout.expected
556 echo "Merge of refs/heads/newbranch interrupted on request" \
557 >> $testroot/stdout.expected
558 cmp -s $testroot/stdout.expected $testroot/stdout
560 if [ $ret -ne 0 ]; then
561 diff -u $testroot/stdout.expected $testroot/stdout
562 test_done "$testroot" "$ret"
566 # Continue the merge.
567 (cd $testroot/wt && got merge -c > $testroot/stdout)
569 if [ $ret -ne 0 ]; then
570 echo "got merge failed unexpectedly" >&2
571 test_done "$testroot" "$ret"
575 local merge_commit=`git_show_branch_head $testroot/repo master`
577 echo "M alpha" > $testroot/stdout.expected
578 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
579 >> $testroot/stdout.expected
580 echo $merge_commit >> $testroot/stdout.expected
582 cmp -s $testroot/stdout.expected $testroot/stdout
584 if [ $ret -ne 0 ]; then
585 diff -u $testroot/stdout.expected $testroot/stdout
586 test_done "$testroot" "$ret"
590 # We should have created a merge commit with two parents.
591 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
592 echo "parent 1: $commit0" > $testroot/stdout.expected
593 echo "parent 2: $commit1" >> $testroot/stdout.expected
594 cmp -s $testroot/stdout.expected $testroot/stdout
596 if [ $ret -ne 0 ]; then
597 diff -u $testroot/stdout.expected $testroot/stdout
599 test_done "$testroot" "$ret"
602 test_merge_backward() {
603 local testroot=`test_init merge_backward`
604 local commit0=`git_show_head $testroot/repo`
606 git -C $testroot/repo checkout -q -b newbranch
607 git -C $testroot/repo checkout -q master
608 echo "modified alpha on master" > $testroot/repo/alpha
609 git_commit $testroot/repo -m "committing to alpha on master"
611 got checkout -b master $testroot/repo $testroot/wt > /dev/null
613 if [ $ret -ne 0 ]; then
614 echo "got checkout failed unexpectedly" >&2
615 test_done "$testroot" "$ret"
619 (cd $testroot/wt && got merge newbranch \
620 > $testroot/stdout 2> $testroot/stderr)
622 if [ $ret -ne 0 ]; then
623 echo "got merge failed unexpectedly" >&2
624 test_done "$testroot" "$ret"
627 echo "Already up-to-date" > $testroot/stdout.expected
628 cmp -s $testroot/stdout.expected $testroot/stdout
630 if [ $ret -ne 0 ]; then
631 diff -u $testroot/stdout.expected $testroot/stdout
632 test_done "$testroot" "$ret"
635 test_done "$testroot" "$ret"
638 test_merge_continue() {
639 local testroot=`test_init merge_continue`
640 local commit0=`git_show_head $testroot/repo`
641 local commit0_author_time=`git_show_author_time $testroot/repo`
643 git -C $testroot/repo checkout -q -b newbranch
644 echo "modified delta on branch" > $testroot/repo/gamma/delta
645 git_commit $testroot/repo -m "committing to delta on newbranch"
646 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
648 echo "modified alpha on branch" > $testroot/repo/alpha
649 git_commit $testroot/repo -m "committing to alpha on newbranch"
650 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
651 git -C $testroot/repo rm -q beta
652 git_commit $testroot/repo -m "removing beta on newbranch"
653 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
654 echo "new file on branch" > $testroot/repo/epsilon/new
655 git -C $testroot/repo add epsilon/new
656 git_commit $testroot/repo -m "adding new file on newbranch"
657 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
659 got checkout -b master $testroot/repo $testroot/wt > /dev/null
661 if [ $ret -ne 0 ]; then
662 echo "got checkout failed unexpectedly" >&2
663 test_done "$testroot" "$ret"
667 # create a conflicting commit
668 git -C $testroot/repo checkout -q master
669 echo "modified alpha on master" > $testroot/repo/alpha
670 git_commit $testroot/repo -m "committing to alpha on master"
671 local master_commit=`git_show_head $testroot/repo`
673 # need an up-to-date work tree for 'got merge'
674 (cd $testroot/wt && got update > /dev/null)
676 if [ $ret -ne 0 ]; then
677 echo "got update failed unexpectedly" >&2
678 test_done "$testroot" "$ret"
682 (cd $testroot/wt && got merge newbranch \
683 > $testroot/stdout 2> $testroot/stderr)
685 if [ $ret -eq 0 ]; then
686 echo "got merge succeeded unexpectedly" >&2
687 test_done "$testroot" "1"
691 echo "C alpha" >> $testroot/stdout.expected
692 echo "D beta" >> $testroot/stdout.expected
693 echo "A epsilon/new" >> $testroot/stdout.expected
694 echo "G gamma/delta" >> $testroot/stdout.expected
695 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
696 cmp -s $testroot/stdout.expected $testroot/stdout
698 if [ $ret -ne 0 ]; then
699 diff -u $testroot/stdout.expected $testroot/stdout
700 test_done "$testroot" "$ret"
704 echo "got: conflicts must be resolved before merging can continue" \
705 > $testroot/stderr.expected
706 cmp -s $testroot/stderr.expected $testroot/stderr
708 if [ $ret -ne 0 ]; then
709 diff -u $testroot/stderr.expected $testroot/stderr
710 test_done "$testroot" "$ret"
714 (cd $testroot/wt && got status > $testroot/stdout)
716 echo "C alpha" > $testroot/stdout.expected
717 echo "D beta" >> $testroot/stdout.expected
718 echo "A epsilon/new" >> $testroot/stdout.expected
719 echo "M gamma/delta" >> $testroot/stdout.expected
720 cmp -s $testroot/stdout.expected $testroot/stdout
722 if [ $ret -ne 0 ]; then
723 diff -u $testroot/stdout.expected $testroot/stdout
724 test_done "$testroot" "$ret"
728 echo '<<<<<<<' > $testroot/content.expected
729 echo "modified alpha on master" >> $testroot/content.expected
730 echo "||||||| 3-way merge base: commit $commit0" \
731 >> $testroot/content.expected
732 echo "alpha" >> $testroot/content.expected
733 echo "=======" >> $testroot/content.expected
734 echo "modified alpha on branch" >> $testroot/content.expected
735 echo ">>>>>>> merged change: commit $branch_commit3" \
736 >> $testroot/content.expected
737 cat $testroot/wt/alpha > $testroot/content
738 cmp -s $testroot/content.expected $testroot/content
740 if [ $ret -ne 0 ]; then
741 diff -u $testroot/content.expected $testroot/content
742 test_done "$testroot" "$ret"
746 # resolve the conflict
747 echo "modified alpha by both branches" > $testroot/wt/alpha
749 (cd $testroot/wt && got merge -c > $testroot/stdout)
751 if [ $ret -ne 0 ]; then
752 echo "got merge failed unexpectedly" >&2
753 test_done "$testroot" "$ret"
757 local merge_commit=`git_show_head $testroot/repo`
759 echo "M alpha" > $testroot/stdout.expected
760 echo "D beta" >> $testroot/stdout.expected
761 echo "A epsilon/new" >> $testroot/stdout.expected
762 echo "M gamma/delta" >> $testroot/stdout.expected
763 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
764 >> $testroot/stdout.expected
765 echo $merge_commit >> $testroot/stdout.expected
767 cmp -s $testroot/stdout.expected $testroot/stdout
769 if [ $ret -ne 0 ]; then
770 diff -u $testroot/stdout.expected $testroot/stdout
771 test_done "$testroot" "$ret"
775 echo "modified delta on branch" > $testroot/content.expected
776 cat $testroot/wt/gamma/delta > $testroot/content
777 cmp -s $testroot/content.expected $testroot/content
779 if [ $ret -ne 0 ]; then
780 diff -u $testroot/content.expected $testroot/content
781 test_done "$testroot" "$ret"
785 echo "modified alpha by both branches" > $testroot/content.expected
786 cat $testroot/wt/alpha > $testroot/content
787 cmp -s $testroot/content.expected $testroot/content
789 if [ $ret -ne 0 ]; then
790 diff -u $testroot/content.expected $testroot/content
791 test_done "$testroot" "$ret"
795 if [ -e $testroot/wt/beta ]; then
796 echo "removed file beta still exists on disk" >&2
797 test_done "$testroot" "1"
801 echo "new file on branch" > $testroot/content.expected
802 cat $testroot/wt/epsilon/new > $testroot/content
803 cmp -s $testroot/content.expected $testroot/content
805 if [ $ret -ne 0 ]; then
806 diff -u $testroot/content.expected $testroot/content
807 test_done "$testroot" "$ret"
811 (cd $testroot/wt && got status > $testroot/stdout)
813 echo -n > $testroot/stdout.expected
814 cmp -s $testroot/stdout.expected $testroot/stdout
816 if [ $ret -ne 0 ]; then
817 diff -u $testroot/stdout.expected $testroot/stdout
818 test_done "$testroot" "$ret"
822 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
823 echo "commit $merge_commit (master)" > $testroot/stdout.expected
824 echo "commit $master_commit" >> $testroot/stdout.expected
825 echo "commit $commit0" >> $testroot/stdout.expected
826 cmp -s $testroot/stdout.expected $testroot/stdout
828 if [ $ret -ne 0 ]; then
829 diff -u $testroot/stdout.expected $testroot/stdout
830 test_done "$testroot" "$ret"
834 (cd $testroot/wt && got update > $testroot/stdout)
836 echo 'Already up-to-date' > $testroot/stdout.expected
837 cmp -s $testroot/stdout.expected $testroot/stdout
839 if [ $ret -ne 0 ]; then
840 diff -u $testroot/stdout.expected $testroot/stdout
841 test_done "$testroot" "$ret"
845 # We should have created a merge commit with two parents.
846 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
847 echo "parent 1: $master_commit" > $testroot/stdout.expected
848 echo "parent 2: $branch_commit3" >> $testroot/stdout.expected
849 cmp -s $testroot/stdout.expected $testroot/stdout
851 if [ $ret -ne 0 ]; then
852 diff -u $testroot/stdout.expected $testroot/stdout
854 test_done "$testroot" "$ret"
857 test_merge_continue_new_commit() {
858 # "got merge -c" should refuse to run if the current branch tip has
859 # changed since the merge was started, to avoid clobbering the changes.
860 local testroot=`test_init merge_continue_new_commit`
862 git -C $testroot/repo checkout -q -b newbranch
863 echo "modified delta on branch" > $testroot/repo/gamma/delta
864 git_commit $testroot/repo -m "committing to delta on newbranch"
866 git -C $testroot/repo checkout -q master
867 echo "modified alpha on master" > $testroot/repo/alpha
868 git_commit $testroot/repo -m "committing to alpha on master"
870 got checkout -b master $testroot/repo $testroot/wt > /dev/null
872 if [ $ret -ne 0 ]; then
873 echo "got checkout failed unexpectedly" >&2
874 test_done "$testroot" "$ret"
878 (cd $testroot/wt && got merge -n newbranch >/dev/null)
880 if [ $ret -ne 0 ]; then
881 echo "got merge failed unexpectedly" >&2
882 test_done "$testroot" "$ret"
886 echo "modified alpha again on master" > $testroot/repo/alpha
887 git_commit $testroot/repo -m "committing to alpha on master again"
889 (cd $testroot/wt && got merge -c > $testroot/stdout 2> $testroot/stderr)
891 if [ $ret -eq 0 ]; then
892 echo "got merge succeeded unexpectedly" >&2
893 test_done "$testroot" "1"
897 echo -n > $testroot/stdout.expected
898 cmp -s $testroot/stdout.expected $testroot/stdout
900 if [ $ret -ne 0 ]; then
901 diff -u $testroot/stdout.expected $testroot/stdout
902 test_done "$testroot" "$ret"
906 echo -n "got: merging cannot proceed because the work tree is no " \
907 > $testroot/stderr.expected
908 echo "longer up-to-date; merge must be aborted and retried" \
909 >> $testroot/stderr.expected
910 cmp -s $testroot/stderr.expected $testroot/stderr
912 if [ $ret -ne 0 ]; then
913 diff -u $testroot/stderr.expected $testroot/stderr
915 test_done "$testroot" "$ret"
919 local testroot=`test_init merge_abort`
920 local commit0=`git_show_head $testroot/repo`
921 local commit0_author_time=`git_show_author_time $testroot/repo`
923 git -C $testroot/repo checkout -q -b newbranch
924 echo "modified delta on branch" > $testroot/repo/gamma/delta
925 git_commit $testroot/repo -m "committing to delta on newbranch"
926 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
928 echo "modified alpha on branch" > $testroot/repo/alpha
929 git_commit $testroot/repo -m "committing to alpha on newbranch"
930 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
931 git -C $testroot/repo rm -q beta
932 git_commit $testroot/repo -m "removing beta on newbranch"
933 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
934 echo "new file on branch" > $testroot/repo/epsilon/new
935 git -C $testroot/repo add epsilon/new
936 git_commit $testroot/repo -m "adding new file on newbranch"
937 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
938 (cd $testroot/repo && ln -s alpha symlink)
939 git -C $testroot/repo add symlink
940 git_commit $testroot/repo -m "adding symlink on newbranch"
941 local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
943 got checkout -b master $testroot/repo $testroot/wt > /dev/null
945 if [ $ret -ne 0 ]; then
946 echo "got checkout failed unexpectedly" >&2
947 test_done "$testroot" "$ret"
951 # unrelated unversioned file in work tree
952 touch $testroot/wt/unversioned-file
954 # create a conflicting commit
955 git -C $testroot/repo checkout -q master
956 echo "modified alpha on master" > $testroot/repo/alpha
957 git_commit $testroot/repo -m "committing to alpha on master"
958 local master_commit=`git_show_head $testroot/repo`
960 # need an up-to-date work tree for 'got merge'
961 (cd $testroot/wt && got update > /dev/null)
963 if [ $ret -ne 0 ]; then
964 echo "got update failed unexpectedly" >&2
965 test_done "$testroot" "$ret"
969 (cd $testroot/wt && got merge newbranch \
970 > $testroot/stdout 2> $testroot/stderr)
972 if [ $ret -eq 0 ]; then
973 echo "got merge succeeded unexpectedly" >&2
974 test_done "$testroot" "1"
978 echo "C alpha" >> $testroot/stdout.expected
979 echo "D beta" >> $testroot/stdout.expected
980 echo "A epsilon/new" >> $testroot/stdout.expected
981 echo "G gamma/delta" >> $testroot/stdout.expected
982 echo "A symlink" >> $testroot/stdout.expected
983 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
984 cmp -s $testroot/stdout.expected $testroot/stdout
986 if [ $ret -ne 0 ]; then
987 diff -u $testroot/stdout.expected $testroot/stdout
988 test_done "$testroot" "$ret"
992 echo "got: conflicts must be resolved before merging can continue" \
993 > $testroot/stderr.expected
994 cmp -s $testroot/stderr.expected $testroot/stderr
996 if [ $ret -ne 0 ]; then
997 diff -u $testroot/stderr.expected $testroot/stderr
998 test_done "$testroot" "$ret"
1002 # unrelated added file added during conflict resolution
1003 touch $testroot/wt/added-file
1004 (cd $testroot/wt && got add added-file > /dev/null)
1006 (cd $testroot/wt && got status > $testroot/stdout)
1008 echo "A added-file" > $testroot/stdout.expected
1009 echo "C alpha" >> $testroot/stdout.expected
1010 echo "D beta" >> $testroot/stdout.expected
1011 echo "A epsilon/new" >> $testroot/stdout.expected
1012 echo "M gamma/delta" >> $testroot/stdout.expected
1013 echo "A symlink" >> $testroot/stdout.expected
1014 echo "? unversioned-file" >> $testroot/stdout.expected
1015 cmp -s $testroot/stdout.expected $testroot/stdout
1017 if [ $ret -ne 0 ]; then
1018 diff -u $testroot/stdout.expected $testroot/stdout
1019 test_done "$testroot" "$ret"
1023 (cd $testroot/wt && got merge -a > $testroot/stdout)
1025 if [ $ret -ne 0 ]; then
1026 echo "got merge failed unexpectedly" >&2
1027 test_done "$testroot" "$ret"
1031 echo "R added-file" > $testroot/stdout.expected
1032 echo "R alpha" >> $testroot/stdout.expected
1033 echo "R beta" >> $testroot/stdout.expected
1034 echo "R epsilon/new" >> $testroot/stdout.expected
1035 echo "R gamma/delta" >> $testroot/stdout.expected
1036 echo "R symlink" >> $testroot/stdout.expected
1037 echo "G added-file" >> $testroot/stdout.expected
1038 echo "Merge of refs/heads/newbranch aborted" \
1039 >> $testroot/stdout.expected
1041 cmp -s $testroot/stdout.expected $testroot/stdout
1043 if [ $ret -ne 0 ]; then
1044 diff -u $testroot/stdout.expected $testroot/stdout
1045 test_done "$testroot" "$ret"
1049 echo "delta" > $testroot/content.expected
1050 cat $testroot/wt/gamma/delta > $testroot/content
1051 cmp -s $testroot/content.expected $testroot/content
1053 if [ $ret -ne 0 ]; then
1054 diff -u $testroot/content.expected $testroot/content
1055 test_done "$testroot" "$ret"
1059 echo "modified alpha on master" > $testroot/content.expected
1060 cat $testroot/wt/alpha > $testroot/content
1061 cmp -s $testroot/content.expected $testroot/content
1063 if [ $ret -ne 0 ]; then
1064 diff -u $testroot/content.expected $testroot/content
1065 test_done "$testroot" "$ret"
1069 echo "beta" > $testroot/content.expected
1070 cat $testroot/wt/beta > $testroot/content
1071 cmp -s $testroot/content.expected $testroot/content
1073 if [ $ret -ne 0 ]; then
1074 diff -u $testroot/content.expected $testroot/content
1075 test_done "$testroot" "$ret"
1079 if [ -e $testroot/wt/epsilon/new ]; then
1080 echo "reverted file epsilon/new still exists on disk" >&2
1081 test_done "$testroot" "1"
1085 if [ -e $testroot/wt/symlink ]; then
1086 echo "reverted symlink still exists on disk" >&2
1087 test_done "$testroot" "1"
1091 (cd $testroot/wt && got status > $testroot/stdout)
1093 echo "? added-file" > $testroot/stdout.expected
1094 echo "? unversioned-file" >> $testroot/stdout.expected
1095 cmp -s $testroot/stdout.expected $testroot/stdout
1097 if [ $ret -ne 0 ]; then
1098 diff -u $testroot/stdout.expected $testroot/stdout
1099 test_done "$testroot" "$ret"
1103 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1104 echo "commit $master_commit (master)" > $testroot/stdout.expected
1105 echo "commit $commit0" >> $testroot/stdout.expected
1106 cmp -s $testroot/stdout.expected $testroot/stdout
1108 if [ $ret -ne 0 ]; then
1109 diff -u $testroot/stdout.expected $testroot/stdout
1110 test_done "$testroot" "$ret"
1114 (cd $testroot/wt && got update > $testroot/stdout)
1116 echo 'Already up-to-date' > $testroot/stdout.expected
1117 cmp -s $testroot/stdout.expected $testroot/stdout
1119 if [ $ret -ne 0 ]; then
1120 diff -u $testroot/stdout.expected $testroot/stdout
1122 test_done "$testroot" "$ret"
1125 test_merge_in_progress() {
1126 local testroot=`test_init merge_in_progress`
1127 local commit0=`git_show_head $testroot/repo`
1128 local commit0_author_time=`git_show_author_time $testroot/repo`
1130 git -C $testroot/repo checkout -q -b newbranch
1131 echo "modified alpha on branch" > $testroot/repo/alpha
1132 git_commit $testroot/repo -m "committing to alpha on newbranch"
1133 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1135 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1137 if [ $ret -ne 0 ]; then
1138 echo "got checkout failed unexpectedly" >&2
1139 test_done "$testroot" "$ret"
1143 # create a conflicting commit
1144 git -C $testroot/repo checkout -q master
1145 echo "modified alpha on master" > $testroot/repo/alpha
1146 git_commit $testroot/repo -m "committing to alpha on master"
1147 local master_commit=`git_show_head $testroot/repo`
1149 # need an up-to-date work tree for 'got merge'
1150 (cd $testroot/wt && got update > /dev/null)
1152 if [ $ret -ne 0 ]; then
1153 echo "got update failed unexpectedly" >&2
1154 test_done "$testroot" "$ret"
1158 (cd $testroot/wt && got merge newbranch \
1159 > $testroot/stdout 2> $testroot/stderr)
1161 if [ $ret -eq 0 ]; then
1162 echo "got merge succeeded unexpectedly" >&2
1163 test_done "$testroot" "1"
1167 echo "C alpha" >> $testroot/stdout.expected
1168 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1169 cmp -s $testroot/stdout.expected $testroot/stdout
1171 if [ $ret -ne 0 ]; then
1172 diff -u $testroot/stdout.expected $testroot/stdout
1173 test_done "$testroot" "$ret"
1177 echo "got: conflicts must be resolved before merging can continue" \
1178 > $testroot/stderr.expected
1179 cmp -s $testroot/stderr.expected $testroot/stderr
1181 if [ $ret -ne 0 ]; then
1182 diff -u $testroot/stderr.expected $testroot/stderr
1183 test_done "$testroot" "$ret"
1187 (cd $testroot/wt && got status > $testroot/stdout)
1189 echo "C alpha" > $testroot/stdout.expected
1190 cmp -s $testroot/stdout.expected $testroot/stdout
1192 if [ $ret -ne 0 ]; then
1193 diff -u $testroot/stdout.expected $testroot/stdout
1194 test_done "$testroot" "$ret"
1198 for cmd in update commit histedit "rebase newbranch" \
1199 "integrate newbranch" "merge newbranch" "stage alpha"; do
1200 (cd $testroot/wt && got $cmd > $testroot/stdout \
1201 2> $testroot/stderr)
1203 if [ $ret -eq 0 ]; then
1204 echo "got $cmd succeeded unexpectedly" >&2
1205 test_done "$testroot" "1"
1209 echo -n > $testroot/stdout.expected
1210 cmp -s $testroot/stdout.expected $testroot/stdout
1212 if [ $ret -ne 0 ]; then
1213 diff -u $testroot/stdout.expected $testroot/stdout
1214 test_done "$testroot" "$ret"
1218 echo -n "got: a merge operation is in progress in this " \
1219 > $testroot/stderr.expected
1220 echo "work tree and must be continued or aborted first" \
1221 >> $testroot/stderr.expected
1222 cmp -s $testroot/stderr.expected $testroot/stderr
1224 if [ $ret -ne 0 ]; then
1225 diff -u $testroot/stderr.expected $testroot/stderr
1226 test_done "$testroot" "$ret"
1231 test_done "$testroot" "$ret"
1234 test_merge_path_prefix() {
1235 local testroot=`test_init merge_path_prefix`
1236 local commit0=`git_show_head $testroot/repo`
1237 local commit0_author_time=`git_show_author_time $testroot/repo`
1239 git -C $testroot/repo checkout -q -b newbranch
1240 echo "modified alpha on branch" > $testroot/repo/alpha
1241 git_commit $testroot/repo -m "committing to alpha on newbranch"
1242 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1244 got checkout -p epsilon -b master $testroot/repo $testroot/wt \
1247 if [ $ret -ne 0 ]; then
1248 echo "got checkout failed unexpectedly" >&2
1249 test_done "$testroot" "$ret"
1253 # create a conflicting commit
1254 git -C $testroot/repo checkout -q master
1255 echo "modified alpha on master" > $testroot/repo/alpha
1256 git_commit $testroot/repo -m "committing to alpha on master"
1257 local master_commit=`git_show_head $testroot/repo`
1259 # need an up-to-date work tree for 'got merge'
1260 (cd $testroot/wt && got update > /dev/null)
1262 if [ $ret -ne 0 ]; then
1263 echo "got update failed unexpectedly" >&2
1264 test_done "$testroot" "$ret"
1268 (cd $testroot/wt && got merge newbranch \
1269 > $testroot/stdout 2> $testroot/stderr)
1271 if [ $ret -eq 0 ]; then
1272 echo "got merge succeeded unexpectedly" >&2
1273 test_done "$testroot" "1"
1277 echo -n "got: cannot merge branch which contains changes outside " \
1278 > $testroot/stderr.expected
1279 echo "of this work tree's path prefix" >> $testroot/stderr.expected
1280 cmp -s $testroot/stderr.expected $testroot/stderr
1282 if [ $ret -ne 0 ]; then
1283 diff -u $testroot/stderr.expected $testroot/stderr
1285 test_done "$testroot" "$ret"
1288 test_merge_missing_file() {
1289 local testroot=`test_init merge_missing_file`
1290 local commit0=`git_show_head $testroot/repo`
1291 local commit0_author_time=`git_show_author_time $testroot/repo`
1293 git -C $testroot/repo checkout -q -b newbranch
1294 echo "modified alpha on branch" > $testroot/repo/alpha
1295 echo "modified delta on branch" > $testroot/repo/gamma/delta
1296 git_commit $testroot/repo -m "committing to alpha and delta"
1297 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1299 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1301 if [ $ret -ne 0 ]; then
1302 echo "got checkout failed unexpectedly" >&2
1303 test_done "$testroot" "$ret"
1307 # create a conflicting commit which renames alpha
1308 git -C $testroot/repo checkout -q master
1309 git -C $testroot/repo mv alpha epsilon/alpha-moved
1310 git_commit $testroot/repo -m "moving alpha on master"
1311 local master_commit=`git_show_head $testroot/repo`
1313 # need an up-to-date work tree for 'got merge'
1314 (cd $testroot/wt && got update > /dev/null)
1316 if [ $ret -ne 0 ]; then
1317 echo "got update failed unexpectedly" >&2
1318 test_done "$testroot" "$ret"
1322 (cd $testroot/wt && got merge newbranch \
1323 > $testroot/stdout 2> $testroot/stderr)
1325 if [ $ret -eq 0 ]; then
1326 echo "got merge succeeded unexpectedly" >&2
1327 test_done "$testroot" "1"
1331 echo "! alpha" > $testroot/stdout.expected
1332 echo "G gamma/delta" >> $testroot/stdout.expected
1333 echo -n "Files which had incoming changes but could not be found " \
1334 >> $testroot/stdout.expected
1335 echo "in the work tree: 1" >> $testroot/stdout.expected
1336 cmp -s $testroot/stdout.expected $testroot/stdout
1338 if [ $ret -ne 0 ]; then
1339 diff -u $testroot/stdout.expected $testroot/stdout
1340 test_done "$testroot" "$ret"
1344 echo -n "got: changes destined for some files " \
1345 > $testroot/stderr.expected
1346 echo -n "were not yet merged and should be merged manually if " \
1347 >> $testroot/stderr.expected
1348 echo "required before the merge operation is continued" \
1349 >> $testroot/stderr.expected
1350 cmp -s $testroot/stderr.expected $testroot/stderr
1352 if [ $ret -ne 0 ]; then
1353 diff -u $testroot/stderr.expected $testroot/stderr
1354 test_done "$testroot" "$ret"
1358 (cd $testroot/wt && got status > $testroot/stdout)
1360 echo "M gamma/delta" > $testroot/stdout.expected
1361 cmp -s $testroot/stdout.expected $testroot/stdout
1363 if [ $ret -ne 0 ]; then
1364 diff -u $testroot/stdout.expected $testroot/stdout
1365 test_done "$testroot" "$ret"
1369 test_done "$testroot" "$ret"
1372 test_merge_no_op() {
1373 local testroot=`test_init merge_no_op`
1374 local commit0=`git_show_head $testroot/repo`
1375 local commit0_author_time=`git_show_author_time $testroot/repo`
1377 git -C $testroot/repo checkout -q -b newbranch
1378 echo "modified alpha on branch" > $testroot/repo/alpha
1379 git_commit $testroot/repo -m "committing to alpha on newbranch"
1380 local branch_commit=`git_show_branch_head $testroot/repo newbranch`
1382 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1384 if [ $ret -ne 0 ]; then
1385 echo "got checkout failed unexpectedly" >&2
1386 test_done "$testroot" "$ret"
1390 # create a conflicting commit
1391 git -C $testroot/repo checkout -q master
1392 echo "modified alpha on master" > $testroot/repo/alpha
1393 git_commit $testroot/repo -m "committing to alpha on master"
1394 local master_commit=`git_show_head $testroot/repo`
1396 # need an up-to-date work tree for 'got merge'
1397 (cd $testroot/wt && got update > /dev/null)
1399 if [ $ret -ne 0 ]; then
1400 echo "got update failed unexpectedly" >&2
1401 test_done "$testroot" "$ret"
1405 (cd $testroot/wt && got merge newbranch \
1406 > $testroot/stdout 2> $testroot/stderr)
1408 if [ $ret -eq 0 ]; then
1409 echo "got merge succeeded unexpectedly" >&2
1410 test_done "$testroot" "1"
1414 echo "C alpha" >> $testroot/stdout.expected
1415 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1416 cmp -s $testroot/stdout.expected $testroot/stdout
1418 if [ $ret -ne 0 ]; then
1419 diff -u $testroot/stdout.expected $testroot/stdout
1420 test_done "$testroot" "$ret"
1424 echo "got: conflicts must be resolved before merging can continue" \
1425 > $testroot/stderr.expected
1426 cmp -s $testroot/stderr.expected $testroot/stderr
1428 if [ $ret -ne 0 ]; then
1429 diff -u $testroot/stderr.expected $testroot/stderr
1430 test_done "$testroot" "$ret"
1434 (cd $testroot/wt && got status > $testroot/stdout)
1436 echo "C alpha" > $testroot/stdout.expected
1437 cmp -s $testroot/stdout.expected $testroot/stdout
1439 if [ $ret -ne 0 ]; then
1440 diff -u $testroot/stdout.expected $testroot/stdout
1441 test_done "$testroot" "$ret"
1445 # resolve the conflict by reverting all changes; now it is no-op merge
1446 (cd $testroot/wt && got revert alpha > /dev/null)
1448 if [ $ret -ne 0 ]; then
1449 echo "got revert failed unexpectedly" >&2
1450 test_done "$testroot" "$ret"
1454 (cd $testroot/wt && got merge -c > $testroot/stdout \
1455 2> $testroot/stderr)
1457 if [ $ret -ne 0 ]; then
1458 echo "got merge failed unexpectedly" >&2
1459 test_done "$testroot" "$ret"
1463 echo -n '' > $testroot/stderr.expected
1464 cmp -s $testroot/stderr.expected $testroot/stderr
1466 if [ $ret -ne 0 ]; then
1467 diff -u $testroot/stderr.expected $testroot/stderr
1468 test_done "$testroot" "$ret"
1472 local merge_commit=`git_show_head $testroot/repo`
1473 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1474 > $testroot/stdout.expected
1475 echo $merge_commit >> $testroot/stdout.expected
1477 cmp -s $testroot/stdout.expected $testroot/stdout
1479 if [ $ret -ne 0 ]; then
1480 diff -u $testroot/stdout.expected $testroot/stdout
1481 test_done "$testroot" "$ret"
1485 (cd $testroot/wt && got status > $testroot/stdout)
1487 echo -n "" > $testroot/stdout.expected
1488 cmp -s $testroot/stdout.expected $testroot/stdout
1490 if [ $ret -ne 0 ]; then
1491 diff -u $testroot/stdout.expected $testroot/stdout
1492 test_done "$testroot" "$ret"
1496 # We should have created a merge commit with two parents.
1497 got log -r $testroot/repo -l1 -c $merge_commit | grep ^parent \
1499 echo "parent 1: $master_commit" > $testroot/stdout.expected
1500 echo "parent 2: $branch_commit" >> $testroot/stdout.expected
1501 cmp -s $testroot/stdout.expected $testroot/stdout
1503 if [ $ret -ne 0 ]; then
1504 diff -u $testroot/stdout.expected $testroot/stdout
1506 test_done "$testroot" "$ret"
1509 test_merge_imported_branch() {
1510 local testroot=`test_init merge_import`
1511 local commit0=`git_show_head $testroot/repo`
1512 local commit0_author_time=`git_show_author_time $testroot/repo`
1514 # import a new sub-tree to the 'files' branch such that
1515 # none of the files added here collide with existing ones
1516 mkdir -p $testroot/tree/there
1517 mkdir -p $testroot/tree/be/lots
1518 mkdir -p $testroot/tree/files
1519 echo "there should" > $testroot/tree/there/should
1520 echo "be lots of" > $testroot/tree/be/lots/of
1521 echo "files here" > $testroot/tree/files/here
1522 got import -r $testroot/repo -b files -m 'import files' \
1523 $testroot/tree > /dev/null
1525 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1527 if [ $ret -ne 0 ]; then
1528 echo "got checkout failed unexpectedly" >&2
1529 test_done "$testroot" "$ret"
1533 (cd $testroot/wt && got merge files > $testroot/stdout)
1535 if [ $ret -ne 0 ]; then
1536 echo "got merge failed unexpectedly" >&2
1537 test_done "$testroot" "$ret"
1541 local merge_commit0=`git_show_head $testroot/repo`
1542 cat > $testroot/stdout.expected <<EOF
1546 Merged refs/heads/files into refs/heads/master: $merge_commit0
1548 cmp -s $testroot/stdout.expected $testroot/stdout
1550 if [ $ret -ne 0 ]; then
1551 diff -u $testroot/stdout.expected $testroot/stdout
1552 test_done "$testroot" "$ret"
1556 # try to merge again while no new changes are available
1557 (cd $testroot/wt && got merge files > $testroot/stdout)
1559 if [ $ret -ne 0 ]; then
1560 echo "got merge failed unexpectedly" >&2
1561 test_done "$testroot" "$ret"
1564 echo "Already up-to-date" > $testroot/stdout.expected
1565 cmp -s $testroot/stdout.expected $testroot/stdout
1567 if [ $ret -ne 0 ]; then
1568 diff -u $testroot/stdout.expected $testroot/stdout
1569 test_done "$testroot" "$ret"
1573 # update the 'files' branch
1574 git -C $testroot/repo reset -q --hard master
1575 git -C $testroot/repo checkout -q files
1576 echo "indeed" > $testroot/repo/indeed
1577 git -C $testroot/repo add indeed
1578 git_commit $testroot/repo -m "adding another file indeed"
1579 echo "be lots and lots of" > $testroot/repo/be/lots/of
1580 git_commit $testroot/repo -m "lots of changes"
1582 (cd $testroot/wt && got update > /dev/null)
1584 if [ $ret -ne 0 ]; then
1585 echo "got update failed unexpectedly" >&2
1586 test_done "$testroot" "$ret"
1590 # we should now be able to merge more changes from files branch
1591 (cd $testroot/wt && got merge files > $testroot/stdout)
1593 if [ $ret -ne 0 ]; then
1594 echo "got merge failed unexpectedly" >&2
1595 test_done "$testroot" "$ret"
1599 local merge_commit1=`git_show_branch_head $testroot/repo master`
1600 cat > $testroot/stdout.expected <<EOF
1603 Merged refs/heads/files into refs/heads/master: $merge_commit1
1606 cmp -s $testroot/stdout.expected $testroot/stdout
1608 if [ $ret -ne 0 ]; then
1609 diff -u $testroot/stdout.expected $testroot/stdout
1611 test_done "$testroot" "$ret"
1614 test_merge_interrupt() {
1615 local testroot=`test_init merge_interrupt`
1616 local commit0=`git_show_head $testroot/repo`
1617 local commit0_author_time=`git_show_author_time $testroot/repo`
1619 git -C $testroot/repo checkout -q -b newbranch
1620 echo "modified alpha on branch" > $testroot/repo/alpha
1621 git_commit $testroot/repo -m "committing to alpha on newbranch"
1622 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1624 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1626 if [ $ret -ne 0 ]; then
1627 echo "got checkout failed unexpectedly" >&2
1628 test_done "$testroot" "$ret"
1632 # create a non-conflicting commit
1633 git -C $testroot/repo checkout -q master
1634 echo "modified beta on master" > $testroot/repo/beta
1635 git_commit $testroot/repo -m "committing to beta on master"
1636 local master_commit=`git_show_head $testroot/repo`
1638 # need an up-to-date work tree for 'got merge'
1639 (cd $testroot/wt && got update > /dev/null)
1641 if [ $ret -ne 0 ]; then
1642 echo "got update failed unexpectedly" >&2
1643 test_done "$testroot" "$ret"
1647 (cd $testroot/wt && got merge -n newbranch \
1648 > $testroot/stdout 2> $testroot/stderr)
1650 if [ $ret -ne 0 ]; then
1651 echo "got merge failed unexpectedly" >&2
1652 test_done "$testroot" "1"
1656 echo "G alpha" > $testroot/stdout.expected
1657 echo "Merge of refs/heads/newbranch interrupted on request" \
1658 >> $testroot/stdout.expected
1659 cmp -s $testroot/stdout.expected $testroot/stdout
1661 if [ $ret -ne 0 ]; then
1662 diff -u $testroot/stdout.expected $testroot/stdout
1663 test_done "$testroot" "$ret"
1667 (cd $testroot/wt && got status > $testroot/stdout)
1669 echo "M alpha" > $testroot/stdout.expected
1670 cmp -s $testroot/stdout.expected $testroot/stdout
1672 if [ $ret -ne 0 ]; then
1673 diff -u $testroot/stdout.expected $testroot/stdout
1674 test_done "$testroot" "$ret"
1678 echo "modified alpha on branch" > $testroot/content.expected
1679 cat $testroot/wt/alpha > $testroot/content
1680 cmp -s $testroot/content.expected $testroot/content
1682 if [ $ret -ne 0 ]; then
1683 diff -u $testroot/content.expected $testroot/content
1684 test_done "$testroot" "$ret"
1688 # adjust merge result
1689 echo "adjusted merge result" > $testroot/wt/alpha
1691 # continue the merge
1692 (cd $testroot/wt && got merge -c > $testroot/stdout)
1694 if [ $ret -ne 0 ]; then
1695 echo "got merge failed unexpectedly" >&2
1696 test_done "$testroot" "$ret"
1700 local merge_commit=`git_show_head $testroot/repo`
1702 echo "M alpha" > $testroot/stdout.expected
1703 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1704 >> $testroot/stdout.expected
1705 echo $merge_commit >> $testroot/stdout.expected
1707 cmp -s $testroot/stdout.expected $testroot/stdout
1709 if [ $ret -ne 0 ]; then
1710 diff -u $testroot/stdout.expected $testroot/stdout
1711 test_done "$testroot" "$ret"
1715 (cd $testroot/wt && got status > $testroot/stdout)
1717 echo -n > $testroot/stdout.expected
1718 cmp -s $testroot/stdout.expected $testroot/stdout
1720 if [ $ret -ne 0 ]; then
1721 diff -u $testroot/stdout.expected $testroot/stdout
1722 test_done "$testroot" "$ret"
1726 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1727 echo "commit $merge_commit (master)" > $testroot/stdout.expected
1728 echo "commit $master_commit" >> $testroot/stdout.expected
1729 echo "commit $commit0" >> $testroot/stdout.expected
1730 cmp -s $testroot/stdout.expected $testroot/stdout
1732 if [ $ret -ne 0 ]; then
1733 diff -u $testroot/stdout.expected $testroot/stdout
1734 test_done "$testroot" "$ret"
1738 (cd $testroot/wt && got update > $testroot/stdout)
1740 echo 'Already up-to-date' > $testroot/stdout.expected
1741 cmp -s $testroot/stdout.expected $testroot/stdout
1743 if [ $ret -ne 0 ]; then
1744 diff -u $testroot/stdout.expected $testroot/stdout
1745 test_done "$testroot" "$ret"
1749 # We should have created a merge commit with two parents.
1750 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
1751 echo "parent 1: $master_commit" > $testroot/stdout.expected
1752 echo "parent 2: $branch_commit0" >> $testroot/stdout.expected
1753 cmp -s $testroot/stdout.expected $testroot/stdout
1755 if [ $ret -ne 0 ]; then
1756 diff -u $testroot/stdout.expected $testroot/stdout
1758 test_done "$testroot" "$ret"
1761 test_merge_umask() {
1762 local testroot=`test_init merge_umask`
1764 git -C $testroot/repo checkout -q -b newbranch
1765 echo "modified alpha on branch" >$testroot/repo/alpha
1766 git_commit "$testroot/repo" -m "committing alpha on newbranch"
1767 echo "modified delta on branch" >$testroot/repo/gamma/delta
1768 git_commit "$testroot/repo" -m "committing delta on newbranch"
1770 # diverge from newbranch
1771 git -C "$testroot/repo" checkout -q master
1772 echo "modified beta on master" >$testroot/repo/beta
1773 git_commit "$testroot/repo" -m "committing zeto no master"
1775 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1777 # using a subshell to avoid clobbering global umask
1778 (umask 077 && cd "$testroot/wt" && got merge newbranch) >/dev/null
1780 for f in alpha gamma/delta; do
1781 ls -l "$testroot/wt/$f" | grep -q ^-rw-------
1782 if [ $? -ne 0 ]; then
1783 echo "$f is not 0600 after merge" >&2
1784 ls -l "$testroot/wt/$f" >&2
1785 test_done "$testroot" 1
1789 test_done "$testroot" 0
1792 test_merge_gitconfig_author() {
1793 local testroot=`test_init merge_gitconfig_author`
1795 git -C $testroot/repo config user.name 'Flan Luck'
1796 git -C $testroot/repo config user.email 'flan_luck@openbsd.org'
1798 git -C $testroot/repo checkout -q -b newbranch
1799 echo "modified alpha on branch" >$testroot/repo/alpha
1800 git_commit "$testroot/repo" -m "committing alpha on newbranch"
1801 echo "modified delta on branch" >$testroot/repo/gamma/delta
1802 git_commit "$testroot/repo" -m "committing delta on newbranch"
1804 # diverge from newbranch
1805 git -C "$testroot/repo" checkout -q master
1806 echo "modified beta on master" >$testroot/repo/beta
1807 git_commit "$testroot/repo" -m "committing zeto no master"
1809 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1811 # unset in a subshell to avoid affecting our environment
1812 (unset GOT_IGNORE_GITCONFIG && cd $testroot/wt && \
1813 got merge newbranch > /dev/null)
1815 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
1817 if [ $ret -ne 0 ]; then
1818 test_done "$testroot" "$ret"
1822 echo "from: Flan Luck <flan_luck@openbsd.org>" \
1823 > $testroot/stdout.expected
1824 cmp -s $testroot/stdout.expected $testroot/stdout
1826 if [ $ret -ne 0 ]; then
1827 diff -u $testroot/stdout.expected $testroot/stdout
1829 test_done "$testroot" "$ret"
1832 test_merge_fetched_branch() {
1833 local testroot=`test_init merge_fetched_branch`
1834 local testurl=ssh://127.0.0.1/$testroot
1835 local commit_id=`git_show_head $testroot/repo`
1837 got clone -q $testurl/repo $testroot/repo-clone
1839 if [ $ret -ne 0 ]; then
1840 echo "got clone command failed unexpectedly" >&2
1841 test_done "$testroot" "$ret"
1845 echo "modified alpha" > $testroot/repo/alpha
1846 git_commit $testroot/repo -m "modified alpha"
1847 local commit_id2=`git_show_head $testroot/repo`
1849 got fetch -q -r $testroot/repo-clone > $testroot/stdout
1851 if [ $ret -ne 0 ]; then
1852 echo "got fetch command failed unexpectedly" >&2
1853 test_done "$testroot" "$ret"
1857 echo -n > $testroot/stdout.expected
1859 cmp -s $testroot/stdout $testroot/stdout.expected
1861 if [ $ret -ne 0 ]; then
1862 diff -u $testroot/stdout.expected $testroot/stdout
1863 test_done "$testroot" "$ret"
1867 got ref -l -r $testroot/repo-clone > $testroot/stdout
1869 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1870 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1871 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1872 >> $testroot/stdout.expected
1873 echo "refs/remotes/origin/master: $commit_id2" \
1874 >> $testroot/stdout.expected
1876 cmp -s $testroot/stdout $testroot/stdout.expected
1878 if [ $ret -ne 0 ]; then
1879 diff -u $testroot/stdout.expected $testroot/stdout
1880 test_done "$testroot" "$ret"
1884 got checkout $testroot/repo-clone $testroot/wt > /dev/null
1886 echo "modified beta" > $testroot/wt/beta
1887 (cd $testroot/wt && got commit -m "modified beta" > /dev/null)
1888 local commit_id3=`git_show_head $testroot/repo-clone`
1890 (cd $testroot/wt && got update > /dev/null)
1891 (cd $testroot/wt && got merge origin/master > $testroot/stdout)
1892 local merge_commit_id=`git_show_head $testroot/repo-clone`
1894 cat > $testroot/stdout.expected <<EOF
1896 Merged refs/remotes/origin/master into refs/heads/master: $merge_commit_id
1899 cmp -s $testroot/stdout $testroot/stdout.expected
1901 if [ $ret -ne 0 ]; then
1902 diff -u $testroot/stdout.expected $testroot/stdout
1904 test_done "$testroot" "$ret"
1907 test_merge_fetched_branch_remote() {
1908 local testroot=`test_init merge_fetched_branch_remote`
1909 local testurl=ssh://127.0.0.1/$testroot
1910 local commit_id=`git_show_head $testroot/repo`
1912 got clone -q $testurl/repo $testroot/repo-clone
1914 if [ $ret -ne 0 ]; then
1915 echo "got clone command failed unexpectedly" >&2
1916 test_done "$testroot" "$ret"
1920 echo "modified alpha" > $testroot/repo/alpha
1921 git_commit $testroot/repo -m "modified alpha"
1922 local commit_id2=`git_show_head $testroot/repo`
1924 got fetch -q -r $testroot/repo-clone > $testroot/stdout
1926 if [ $ret -ne 0 ]; then
1927 echo "got fetch command failed unexpectedly" >&2
1928 test_done "$testroot" "$ret"
1932 echo -n > $testroot/stdout.expected
1934 cmp -s $testroot/stdout $testroot/stdout.expected
1936 if [ $ret -ne 0 ]; then
1937 diff -u $testroot/stdout.expected $testroot/stdout
1938 test_done "$testroot" "$ret"
1942 got ref -l -r $testroot/repo-clone > $testroot/stdout
1944 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1945 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1946 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1947 >> $testroot/stdout.expected
1948 echo "refs/remotes/origin/master: $commit_id2" \
1949 >> $testroot/stdout.expected
1951 cmp -s $testroot/stdout $testroot/stdout.expected
1953 if [ $ret -ne 0 ]; then
1954 diff -u $testroot/stdout.expected $testroot/stdout
1955 test_done "$testroot" "$ret"
1959 got checkout $testroot/repo-clone $testroot/wt > /dev/null
1961 echo "modified beta" > $testroot/wt/beta
1962 (cd $testroot/wt && got commit -m "modified beta" > /dev/null)
1963 local commit_id3=`git_show_head $testroot/repo-clone`
1965 (cd $testroot/wt && got update -b origin/master > /dev/null)
1966 (cd $testroot/wt && got merge master > \
1967 $testroot/stdout 2> $testroot/stderr)
1968 local merge_commit_id=`git_show_head $testroot/repo-clone`
1970 echo -n > $testroot/stdout.expected
1972 cmp -s $testroot/stdout $testroot/stdout.expected
1974 if [ $ret -ne 0 ]; then
1975 diff -u $testroot/stdout.expected $testroot/stdout
1976 test_done "$testroot" "$ret"
1980 echo -n "got: work tree's current branch refs/remotes/origin/master " \
1981 > $testroot/stderr.expected
1982 echo -n 'is outside the "refs/heads/" reference namespace; ' \
1983 >> $testroot/stderr.expected
1984 echo -n "update -b required: will not commit to a branch " \
1985 >> $testroot/stderr.expected
1986 echo 'outside the "refs/heads/" reference namespace' \
1987 >> $testroot/stderr.expected
1989 cmp -s $testroot/stderr $testroot/stderr.expected
1991 if [ $ret -ne 0 ]; then
1992 diff -u $testroot/stderr.expected $testroot/stderr
1994 test_done "$testroot" "$ret"
1998 run_test test_merge_basic
1999 run_test test_merge_forward
2000 run_test test_merge_forward_commit
2001 run_test test_merge_forward_interrupt
2002 run_test test_merge_backward
2003 run_test test_merge_continue
2004 run_test test_merge_continue_new_commit
2005 run_test test_merge_abort
2006 run_test test_merge_in_progress
2007 run_test test_merge_path_prefix
2008 run_test test_merge_missing_file
2009 run_test test_merge_no_op
2010 run_test test_merge_imported_branch
2011 run_test test_merge_interrupt
2012 run_test test_merge_umask
2013 run_test test_merge_gitconfig_author
2014 run_test test_merge_fetched_branch
2015 run_test test_merge_fetched_branch_remote