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 (cd $testroot/repo && git 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 (cd $testroot/repo && git 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 (cd $testroot/repo && git 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 && git add symlink)
40 git_commit $testroot/repo -m "adding symlink on newbranch"
41 local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
42 (cd $testroot/repo && ln -sf .got/bar dotgotbar.link)
43 (cd $testroot/repo && git add dotgotbar.link)
44 git_commit $testroot/repo -m "adding a bad symlink on newbranch"
45 local branch_commit5=`git_show_branch_head $testroot/repo newbranch`
47 got checkout -b master $testroot/repo $testroot/wt > /dev/null
49 if [ $ret -ne 0 ]; then
50 echo "got checkout failed unexpectedly" >&2
51 test_done "$testroot" "$ret"
55 # create a divergent commit
56 (cd $testroot/repo && git checkout -q master)
57 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
58 git_commit $testroot/repo -m "committing to zeta on master"
59 local master_commit=`git_show_head $testroot/repo`
61 # need an up-to-date work tree for 'got merge'
62 (cd $testroot/wt && got merge newbranch \
63 > $testroot/stdout 2> $testroot/stderr)
65 if [ $ret -eq 0 ]; then
66 echo "got merge succeeded unexpectedly" >&2
67 test_done "$testroot" "1"
70 echo -n "got: work tree must be updated before it can be used " \
71 > $testroot/stderr.expected
72 echo "to merge a branch" >> $testroot/stderr.expected
73 cmp -s $testroot/stderr.expected $testroot/stderr
75 if [ $ret -ne 0 ]; then
76 diff -u $testroot/stderr.expected $testroot/stderr
77 test_done "$testroot" "$ret"
81 (cd $testroot/wt && got update > /dev/null)
83 if [ $ret -ne 0 ]; then
84 echo "got update failed unexpectedly" >&2
85 test_done "$testroot" "$ret"
89 # must not use a mixed-commit work tree with 'got merge'
90 (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
92 if [ $ret -ne 0 ]; then
93 echo "got update failed unexpectedly" >&2
94 test_done "$testroot" "$ret"
97 (cd $testroot/wt && got merge newbranch \
98 > $testroot/stdout 2> $testroot/stderr)
100 if [ $ret -eq 0 ]; then
101 echo "got merge succeeded unexpectedly" >&2
102 test_done "$testroot" "1"
105 echo -n "got: work tree contains files from multiple base commits; " \
106 > $testroot/stderr.expected
107 echo "the entire work tree must be updated first" \
108 >> $testroot/stderr.expected
109 cmp -s $testroot/stderr.expected $testroot/stderr
111 if [ $ret -ne 0 ]; then
112 diff -u $testroot/stderr.expected $testroot/stderr
113 test_done "$testroot" "$ret"
117 (cd $testroot/wt && got update > /dev/null)
119 if [ $ret -ne 0 ]; then
120 echo "got update failed unexpectedly" >&2
121 test_done "$testroot" "$ret"
125 # must not have staged files with 'got merge'
126 echo "modified file alpha" > $testroot/wt/alpha
127 (cd $testroot/wt && got stage alpha > /dev/null)
129 if [ $ret -ne 0 ]; then
130 echo "got stage failed unexpectedly" >&2
131 test_done "$testroot" "$ret"
134 (cd $testroot/wt && got merge newbranch \
135 > $testroot/stdout 2> $testroot/stderr)
137 if [ $ret -eq 0 ]; then
138 echo "got merge succeeded unexpectedly" >&2
139 test_done "$testroot" "1"
142 echo "got: alpha: file is staged" > $testroot/stderr.expected
143 cmp -s $testroot/stderr.expected $testroot/stderr
145 if [ $ret -ne 0 ]; then
146 diff -u $testroot/stderr.expected $testroot/stderr
147 test_done "$testroot" "$ret"
150 (cd $testroot/wt && got unstage alpha > /dev/null)
152 if [ $ret -ne 0 ]; then
153 echo "got unstage failed unexpectedly" >&2
154 test_done "$testroot" "$ret"
158 # must not have local changes with 'got merge'
159 (cd $testroot/wt && got merge newbranch \
160 > $testroot/stdout 2> $testroot/stderr)
162 if [ $ret -eq 0 ]; then
163 echo "got merge succeeded unexpectedly" >&2
164 test_done "$testroot" "1"
167 echo -n "got: work tree contains local changes; " \
168 > $testroot/stderr.expected
169 echo "these changes must be committed or reverted first" \
170 >> $testroot/stderr.expected
171 cmp -s $testroot/stderr.expected $testroot/stderr
173 if [ $ret -ne 0 ]; then
174 diff -u $testroot/stderr.expected $testroot/stderr
175 test_done "$testroot" "$ret"
179 (cd $testroot/wt && got revert alpha > /dev/null)
181 if [ $ret -ne 0 ]; then
182 echo "got revert failed unexpectedly" >&2
183 test_done "$testroot" "$ret"
187 (cd $testroot/wt && got merge newbranch > $testroot/stdout)
189 if [ $ret -ne 0 ]; then
190 echo "got merge failed unexpectedly" >&2
191 test_done "$testroot" "$ret"
195 local merge_commit=`git_show_head $testroot/repo`
197 echo "G alpha" >> $testroot/stdout.expected
198 echo "D beta" >> $testroot/stdout.expected
199 echo "A dotgotbar.link" >> $testroot/stdout.expected
200 echo "A epsilon/new" >> $testroot/stdout.expected
201 echo "G gamma/delta" >> $testroot/stdout.expected
202 echo "A symlink" >> $testroot/stdout.expected
203 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
204 >> $testroot/stdout.expected
205 echo $merge_commit >> $testroot/stdout.expected
207 cmp -s $testroot/stdout.expected $testroot/stdout
209 if [ $ret -ne 0 ]; then
210 diff -u $testroot/stdout.expected $testroot/stdout
211 test_done "$testroot" "$ret"
215 echo "modified delta on branch" > $testroot/content.expected
216 cat $testroot/wt/gamma/delta > $testroot/content
217 cmp -s $testroot/content.expected $testroot/content
219 if [ $ret -ne 0 ]; then
220 diff -u $testroot/content.expected $testroot/content
221 test_done "$testroot" "$ret"
225 echo "modified alpha on branch" > $testroot/content.expected
226 cat $testroot/wt/alpha > $testroot/content
227 cmp -s $testroot/content.expected $testroot/content
229 if [ $ret -ne 0 ]; then
230 diff -u $testroot/content.expected $testroot/content
231 test_done "$testroot" "$ret"
235 if [ -e $testroot/wt/beta ]; then
236 echo "removed file beta still exists on disk" >&2
237 test_done "$testroot" "1"
241 echo "new file on branch" > $testroot/content.expected
242 cat $testroot/wt/epsilon/new > $testroot/content
243 cmp -s $testroot/content.expected $testroot/content
245 if [ $ret -ne 0 ]; then
246 diff -u $testroot/content.expected $testroot/content
247 test_done "$testroot" "$ret"
251 if [ ! -h $testroot/wt/dotgotbar.link ]; then
252 echo "dotgotbar.link is not a symlink"
253 test_done "$testroot" "1"
257 readlink $testroot/wt/symlink > $testroot/stdout
258 echo "alpha" > $testroot/stdout.expected
259 cmp -s $testroot/stdout.expected $testroot/stdout
261 if [ $ret -ne 0 ]; then
262 diff -u $testroot/stdout.expected $testroot/stdout
263 test_done "$testroot" "$ret"
267 (cd $testroot/wt && got status > $testroot/stdout)
269 echo -n > $testroot/stdout.expected
270 cmp -s $testroot/stdout.expected $testroot/stdout
272 if [ $ret -ne 0 ]; then
273 diff -u $testroot/stdout.expected $testroot/stdout
274 test_done "$testroot" "$ret"
278 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
279 echo "commit $merge_commit (master)" > $testroot/stdout.expected
280 echo "commit $master_commit" >> $testroot/stdout.expected
281 echo "commit $commit0" >> $testroot/stdout.expected
282 cmp -s $testroot/stdout.expected $testroot/stdout
284 if [ $ret -ne 0 ]; then
285 diff -u $testroot/stdout.expected $testroot/stdout
286 test_done "$testroot" "$ret"
290 (cd $testroot/wt && got update > $testroot/stdout)
292 echo 'U dotgotbar.link' > $testroot/stdout.expected
293 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
294 git_show_head $testroot/repo >> $testroot/stdout.expected
295 echo >> $testroot/stdout.expected
296 cmp -s $testroot/stdout.expected $testroot/stdout
298 if [ $ret -ne 0 ]; then
299 diff -u $testroot/stdout.expected $testroot/stdout
300 test_done "$testroot" "$ret"
304 # update has changed the bad symlink into a regular file
305 if [ -h $testroot/wt/dotgotbar.link ]; then
306 echo "dotgotbar.link is a symlink"
307 test_done "$testroot" "1"
311 # We should have created a merge commit with two parents.
312 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
313 echo "parent 1: $master_commit" > $testroot/stdout.expected
314 echo "parent 2: $branch_commit5" >> $testroot/stdout.expected
315 cmp -s $testroot/stdout.expected $testroot/stdout
317 if [ $ret -ne 0 ]; then
318 diff -u $testroot/stdout.expected $testroot/stdout
319 test_done "$testroot" "$ret"
323 got tree -r $testroot/repo -c $merge_commit -R > $testroot/stdout
325 if [ $ret -ne 0 ]; then
326 echo "got tree failed unexpectedly" >&2
327 test_done "$testroot" "$ret"
331 # bad symlink dotgotbar.link appears as a symlink in the merge commit:
332 cat > $testroot/stdout.expected <<EOF
334 dotgotbar.link@ -> .got/bar
342 cmp -s $testroot/stdout.expected $testroot/stdout
344 if [ $ret -ne 0 ]; then
345 diff -u $testroot/stdout.expected $testroot/stdout
347 test_done "$testroot" "$ret"
350 test_merge_forward() {
351 local testroot=`test_init merge_forward`
352 local commit0=`git_show_head $testroot/repo`
354 # Create a commit before branching, which will be used to help test
355 # preconditions for "got merge".
356 echo "modified alpha" > $testroot/repo/alpha
357 git_commit $testroot/repo -m "common commit"
358 local commit1=`git_show_head $testroot/repo`
360 (cd $testroot/repo && git checkout -q -b newbranch)
361 echo "modified beta on branch" > $testroot/repo/beta
362 git_commit $testroot/repo -m "committing to beta on newbranch"
363 local commit2=`git_show_head $testroot/repo`
365 got checkout -b master $testroot/repo $testroot/wt > /dev/null
367 if [ $ret -ne 0 ]; then
368 echo "got checkout failed unexpectedly" >&2
369 test_done "$testroot" "$ret"
373 # must not use a mixed-commit work tree with 'got merge'
374 (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
376 if [ $ret -ne 0 ]; then
377 echo "got update failed unexpectedly" >&2
378 test_done "$testroot" "$ret"
381 (cd $testroot/wt && got merge newbranch \
382 > $testroot/stdout 2> $testroot/stderr)
384 if [ $ret -eq 0 ]; then
385 echo "got merge succeeded unexpectedly" >&2
386 test_done "$testroot" "$ret"
389 echo -n "got: work tree contains files from multiple base commits; " \
390 > $testroot/stderr.expected
391 echo "the entire work tree must be updated first" \
392 >> $testroot/stderr.expected
393 cmp -s $testroot/stderr.expected $testroot/stderr
395 if [ $ret -ne 0 ]; then
396 diff -u $testroot/stderr.expected $testroot/stderr
397 test_done "$testroot" "$ret"
401 (cd $testroot/wt && got update > /dev/null)
403 if [ $ret -ne 0 ]; then
404 echo "got update failed unexpectedly" >&2
405 test_done "$testroot" "$ret"
409 # 'got merge -n' refuses to fast-forward
410 (cd $testroot/wt && got merge -n newbranch \
411 > $testroot/stdout 2> $testroot/stderr)
413 if [ $ret -eq 0 ]; then
414 echo "got merge succeeded unexpectedly" >&2
415 test_done "$testroot" "1"
419 echo -n "got: there are no changes to merge since " \
420 > $testroot/stderr.expected
421 echo -n "refs/heads/newbranch is already based on " \
422 >> $testroot/stderr.expected
423 echo -n "refs/heads/master; merge cannot be interrupted " \
424 >> $testroot/stderr.expected
425 echo "for amending; -n: option cannot be used" \
426 >> $testroot/stderr.expected
428 cmp -s $testroot/stderr.expected $testroot/stderr
430 if [ $ret -ne 0 ]; then
431 diff -u $testroot/stderr.expected $testroot/stderr
432 test_done "$testroot" "$ret"
436 (cd $testroot/wt && got merge newbranch \
437 > $testroot/stdout 2> $testroot/stderr)
439 if [ $ret -ne 0 ]; then
440 echo "got merge failed unexpectedly" >&2
441 test_done "$testroot" "$ret"
445 echo "Forwarding refs/heads/master to refs/heads/newbranch" \
446 > $testroot/stdout.expected
447 echo "U beta" >> $testroot/stdout.expected
448 echo "Updated to commit $commit2" \
449 >> $testroot/stdout.expected
450 cmp -s $testroot/stdout.expected $testroot/stdout
452 if [ $ret -ne 0 ]; then
453 diff -u $testroot/stdout.expected $testroot/stdout
454 test_done "$testroot" "$ret"
458 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
459 echo -n "commit $commit2 " > $testroot/stdout.expected
460 echo "(master, newbranch)" >> $testroot/stdout.expected
461 echo "commit $commit1" >> $testroot/stdout.expected
462 echo "commit $commit0" >> $testroot/stdout.expected
463 cmp -s $testroot/stdout.expected $testroot/stdout
465 if [ $ret -ne 0 ]; then
466 diff -u $testroot/stdout.expected $testroot/stdout
467 test_done "$testroot" "$ret"
470 test_done "$testroot" "$ret"
473 test_merge_forward_commit() {
474 local testroot=`test_init merge_forward_commit`
475 local commit0=`git_show_head $testroot/repo`
477 (cd $testroot/repo && git checkout -q -b newbranch)
478 echo "modified alpha on branch" > $testroot/repo/alpha
479 git_commit $testroot/repo -m "committing to alpha on newbranch"
480 local commit1=`git_show_head $testroot/repo`
482 got checkout -b master $testroot/repo $testroot/wt > /dev/null
484 if [ $ret -ne 0 ]; then
485 echo "got checkout failed unexpectedly" >&2
486 test_done "$testroot" "$ret"
490 (cd $testroot/wt && got merge -M newbranch > $testroot/stdout)
492 if [ $ret -ne 0 ]; then
493 echo "got merge failed unexpectedly" >&2
494 test_done "$testroot" "$ret"
498 local merge_commit=`git_show_branch_head $testroot/repo master`
500 echo "G alpha" >> $testroot/stdout.expected
501 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
502 >> $testroot/stdout.expected
503 echo $merge_commit >> $testroot/stdout.expected
505 cmp -s $testroot/stdout.expected $testroot/stdout
507 if [ $ret -ne 0 ]; then
508 diff -u $testroot/stdout.expected $testroot/stdout
509 test_done "$testroot" "$ret"
513 # We should have created a merge commit with two parents.
514 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
515 echo "parent 1: $commit0" > $testroot/stdout.expected
516 echo "parent 2: $commit1" >> $testroot/stdout.expected
517 cmp -s $testroot/stdout.expected $testroot/stdout
519 if [ $ret -ne 0 ]; then
520 diff -u $testroot/stdout.expected $testroot/stdout
521 test_done "$testroot" "$ret"
525 test_done "$testroot" "$ret"
528 test_merge_forward_interrupt() {
529 # Test -M and -n options together.
530 local testroot=`test_init merge_forward_commit`
531 local commit0=`git_show_head $testroot/repo`
533 (cd $testroot/repo && git checkout -q -b newbranch)
534 echo "modified alpha on branch" > $testroot/repo/alpha
535 git_commit $testroot/repo -m "committing to alpha on newbranch"
536 local commit1=`git_show_head $testroot/repo`
538 got checkout -b master $testroot/repo $testroot/wt > /dev/null
540 if [ $ret -ne 0 ]; then
541 echo "got checkout failed unexpectedly" >&2
542 test_done "$testroot" "$ret"
546 (cd $testroot/wt && got merge -M -n newbranch > $testroot/stdout)
548 if [ $ret -ne 0 ]; then
549 echo "got merge failed unexpectedly" >&2
550 test_done "$testroot" "$ret"
554 echo "G alpha" > $testroot/stdout.expected
555 echo "Merge of refs/heads/newbranch interrupted on request" \
556 >> $testroot/stdout.expected
557 cmp -s $testroot/stdout.expected $testroot/stdout
559 if [ $ret -ne 0 ]; then
560 diff -u $testroot/stdout.expected $testroot/stdout
561 test_done "$testroot" "$ret"
565 # Continue the merge.
566 (cd $testroot/wt && got merge -c > $testroot/stdout)
568 if [ $ret -ne 0 ]; then
569 echo "got merge failed unexpectedly" >&2
570 test_done "$testroot" "$ret"
574 local merge_commit=`git_show_branch_head $testroot/repo master`
576 echo "M alpha" > $testroot/stdout.expected
577 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
578 >> $testroot/stdout.expected
579 echo $merge_commit >> $testroot/stdout.expected
581 cmp -s $testroot/stdout.expected $testroot/stdout
583 if [ $ret -ne 0 ]; then
584 diff -u $testroot/stdout.expected $testroot/stdout
585 test_done "$testroot" "$ret"
589 # We should have created a merge commit with two parents.
590 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
591 echo "parent 1: $commit0" > $testroot/stdout.expected
592 echo "parent 2: $commit1" >> $testroot/stdout.expected
593 cmp -s $testroot/stdout.expected $testroot/stdout
595 if [ $ret -ne 0 ]; then
596 diff -u $testroot/stdout.expected $testroot/stdout
598 test_done "$testroot" "$ret"
601 test_merge_backward() {
602 local testroot=`test_init merge_backward`
603 local commit0=`git_show_head $testroot/repo`
605 (cd $testroot/repo && git checkout -q -b newbranch)
606 (cd $testroot/repo && git checkout -q master)
607 echo "modified alpha on master" > $testroot/repo/alpha
608 git_commit $testroot/repo -m "committing to alpha on master"
610 got checkout -b master $testroot/repo $testroot/wt > /dev/null
612 if [ $ret -ne 0 ]; then
613 echo "got checkout failed unexpectedly" >&2
614 test_done "$testroot" "$ret"
618 (cd $testroot/wt && got merge newbranch \
619 > $testroot/stdout 2> $testroot/stderr)
621 if [ $ret -ne 0 ]; then
622 echo "got merge failed unexpectedly" >&2
623 test_done "$testroot" "$ret"
626 echo "Already up-to-date" > $testroot/stdout.expected
627 cmp -s $testroot/stdout.expected $testroot/stdout
629 if [ $ret -ne 0 ]; then
630 diff -u $testroot/stdout.expected $testroot/stdout
631 test_done "$testroot" "$ret"
634 test_done "$testroot" "$ret"
637 test_merge_continue() {
638 local testroot=`test_init merge_continue`
639 local commit0=`git_show_head $testroot/repo`
640 local commit0_author_time=`git_show_author_time $testroot/repo`
642 (cd $testroot/repo && git checkout -q -b newbranch)
643 echo "modified delta on branch" > $testroot/repo/gamma/delta
644 git_commit $testroot/repo -m "committing to delta on newbranch"
645 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
647 echo "modified alpha on branch" > $testroot/repo/alpha
648 git_commit $testroot/repo -m "committing to alpha on newbranch"
649 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
650 (cd $testroot/repo && git rm -q beta)
651 git_commit $testroot/repo -m "removing beta on newbranch"
652 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
653 echo "new file on branch" > $testroot/repo/epsilon/new
654 (cd $testroot/repo && git add epsilon/new)
655 git_commit $testroot/repo -m "adding new file on newbranch"
656 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
658 got checkout -b master $testroot/repo $testroot/wt > /dev/null
660 if [ $ret -ne 0 ]; then
661 echo "got checkout failed unexpectedly" >&2
662 test_done "$testroot" "$ret"
666 # create a conflicting commit
667 (cd $testroot/repo && git checkout -q master)
668 echo "modified alpha on master" > $testroot/repo/alpha
669 git_commit $testroot/repo -m "committing to alpha on master"
670 local master_commit=`git_show_head $testroot/repo`
672 # need an up-to-date work tree for 'got merge'
673 (cd $testroot/wt && got update > /dev/null)
675 if [ $ret -ne 0 ]; then
676 echo "got update failed unexpectedly" >&2
677 test_done "$testroot" "$ret"
681 (cd $testroot/wt && got merge newbranch \
682 > $testroot/stdout 2> $testroot/stderr)
684 if [ $ret -eq 0 ]; then
685 echo "got merge succeeded unexpectedly" >&2
686 test_done "$testroot" "1"
690 echo "C alpha" >> $testroot/stdout.expected
691 echo "D beta" >> $testroot/stdout.expected
692 echo "A epsilon/new" >> $testroot/stdout.expected
693 echo "G gamma/delta" >> $testroot/stdout.expected
694 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
695 cmp -s $testroot/stdout.expected $testroot/stdout
697 if [ $ret -ne 0 ]; then
698 diff -u $testroot/stdout.expected $testroot/stdout
699 test_done "$testroot" "$ret"
703 echo "got: conflicts must be resolved before merging can continue" \
704 > $testroot/stderr.expected
705 cmp -s $testroot/stderr.expected $testroot/stderr
707 if [ $ret -ne 0 ]; then
708 diff -u $testroot/stderr.expected $testroot/stderr
709 test_done "$testroot" "$ret"
713 (cd $testroot/wt && got status > $testroot/stdout)
715 echo "C alpha" > $testroot/stdout.expected
716 echo "D beta" >> $testroot/stdout.expected
717 echo "A epsilon/new" >> $testroot/stdout.expected
718 echo "M gamma/delta" >> $testroot/stdout.expected
719 cmp -s $testroot/stdout.expected $testroot/stdout
721 if [ $ret -ne 0 ]; then
722 diff -u $testroot/stdout.expected $testroot/stdout
723 test_done "$testroot" "$ret"
727 echo '<<<<<<<' > $testroot/content.expected
728 echo "modified alpha on master" >> $testroot/content.expected
729 echo "||||||| 3-way merge base: commit $commit0" \
730 >> $testroot/content.expected
731 echo "alpha" >> $testroot/content.expected
732 echo "=======" >> $testroot/content.expected
733 echo "modified alpha on branch" >> $testroot/content.expected
734 echo ">>>>>>> merged change: commit $branch_commit3" \
735 >> $testroot/content.expected
736 cat $testroot/wt/alpha > $testroot/content
737 cmp -s $testroot/content.expected $testroot/content
739 if [ $ret -ne 0 ]; then
740 diff -u $testroot/content.expected $testroot/content
741 test_done "$testroot" "$ret"
745 # resolve the conflict
746 echo "modified alpha by both branches" > $testroot/wt/alpha
748 (cd $testroot/wt && got merge -c > $testroot/stdout)
750 if [ $ret -ne 0 ]; then
751 echo "got merge failed unexpectedly" >&2
752 test_done "$testroot" "$ret"
756 local merge_commit=`git_show_head $testroot/repo`
758 echo "M alpha" > $testroot/stdout.expected
759 echo "D beta" >> $testroot/stdout.expected
760 echo "A epsilon/new" >> $testroot/stdout.expected
761 echo "M gamma/delta" >> $testroot/stdout.expected
762 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
763 >> $testroot/stdout.expected
764 echo $merge_commit >> $testroot/stdout.expected
766 cmp -s $testroot/stdout.expected $testroot/stdout
768 if [ $ret -ne 0 ]; then
769 diff -u $testroot/stdout.expected $testroot/stdout
770 test_done "$testroot" "$ret"
774 echo "modified delta on branch" > $testroot/content.expected
775 cat $testroot/wt/gamma/delta > $testroot/content
776 cmp -s $testroot/content.expected $testroot/content
778 if [ $ret -ne 0 ]; then
779 diff -u $testroot/content.expected $testroot/content
780 test_done "$testroot" "$ret"
784 echo "modified alpha by both branches" > $testroot/content.expected
785 cat $testroot/wt/alpha > $testroot/content
786 cmp -s $testroot/content.expected $testroot/content
788 if [ $ret -ne 0 ]; then
789 diff -u $testroot/content.expected $testroot/content
790 test_done "$testroot" "$ret"
794 if [ -e $testroot/wt/beta ]; then
795 echo "removed file beta still exists on disk" >&2
796 test_done "$testroot" "1"
800 echo "new file on branch" > $testroot/content.expected
801 cat $testroot/wt/epsilon/new > $testroot/content
802 cmp -s $testroot/content.expected $testroot/content
804 if [ $ret -ne 0 ]; then
805 diff -u $testroot/content.expected $testroot/content
806 test_done "$testroot" "$ret"
810 (cd $testroot/wt && got status > $testroot/stdout)
812 echo -n > $testroot/stdout.expected
813 cmp -s $testroot/stdout.expected $testroot/stdout
815 if [ $ret -ne 0 ]; then
816 diff -u $testroot/stdout.expected $testroot/stdout
817 test_done "$testroot" "$ret"
821 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
822 echo "commit $merge_commit (master)" > $testroot/stdout.expected
823 echo "commit $master_commit" >> $testroot/stdout.expected
824 echo "commit $commit0" >> $testroot/stdout.expected
825 cmp -s $testroot/stdout.expected $testroot/stdout
827 if [ $ret -ne 0 ]; then
828 diff -u $testroot/stdout.expected $testroot/stdout
829 test_done "$testroot" "$ret"
833 (cd $testroot/wt && got update > $testroot/stdout)
835 echo 'Already up-to-date' > $testroot/stdout.expected
836 cmp -s $testroot/stdout.expected $testroot/stdout
838 if [ $ret -ne 0 ]; then
839 diff -u $testroot/stdout.expected $testroot/stdout
840 test_done "$testroot" "$ret"
844 # We should have created a merge commit with two parents.
845 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
846 echo "parent 1: $master_commit" > $testroot/stdout.expected
847 echo "parent 2: $branch_commit3" >> $testroot/stdout.expected
848 cmp -s $testroot/stdout.expected $testroot/stdout
850 if [ $ret -ne 0 ]; then
851 diff -u $testroot/stdout.expected $testroot/stdout
853 test_done "$testroot" "$ret"
856 test_merge_continue_new_commit() {
857 # "got merge -c" should refuse to run if the current branch tip has
858 # changed since the merge was started, to avoid clobbering the changes.
859 local testroot=`test_init merge_continue_new_commit`
861 (cd $testroot/repo && git checkout -q -b newbranch)
862 echo "modified delta on branch" > $testroot/repo/gamma/delta
863 git_commit $testroot/repo -m "committing to delta on newbranch"
865 (cd $testroot/repo && git checkout -q master)
866 echo "modified alpha on master" > $testroot/repo/alpha
867 git_commit $testroot/repo -m "committing to alpha on master"
869 got checkout -b master $testroot/repo $testroot/wt > /dev/null
871 if [ $ret -ne 0 ]; then
872 echo "got checkout failed unexpectedly" >&2
873 test_done "$testroot" "$ret"
877 (cd $testroot/wt && got merge -n newbranch >/dev/null)
879 if [ $ret -ne 0 ]; then
880 echo "got merge failed unexpectedly" >&2
881 test_done "$testroot" "$ret"
885 echo "modified alpha again on master" > $testroot/repo/alpha
886 git_commit $testroot/repo -m "committing to alpha on master again"
888 (cd $testroot/wt && got merge -c > $testroot/stdout 2> $testroot/stderr)
890 if [ $ret -eq 0 ]; then
891 echo "got merge succeeded unexpectedly" >&2
892 test_done "$testroot" "1"
896 echo -n > $testroot/stdout.expected
897 cmp -s $testroot/stdout.expected $testroot/stdout
899 if [ $ret -ne 0 ]; then
900 diff -u $testroot/stdout.expected $testroot/stdout
901 test_done "$testroot" "$ret"
905 echo -n "got: merging cannot proceed because the work tree is no " \
906 > $testroot/stderr.expected
907 echo "longer up-to-date; merge must be aborted and retried" \
908 >> $testroot/stderr.expected
909 cmp -s $testroot/stderr.expected $testroot/stderr
911 if [ $ret -ne 0 ]; then
912 diff -u $testroot/stderr.expected $testroot/stderr
914 test_done "$testroot" "$ret"
918 local testroot=`test_init merge_abort`
919 local commit0=`git_show_head $testroot/repo`
920 local commit0_author_time=`git_show_author_time $testroot/repo`
922 (cd $testroot/repo && git checkout -q -b newbranch)
923 echo "modified delta on branch" > $testroot/repo/gamma/delta
924 git_commit $testroot/repo -m "committing to delta on newbranch"
925 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
927 echo "modified alpha on branch" > $testroot/repo/alpha
928 git_commit $testroot/repo -m "committing to alpha on newbranch"
929 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
930 (cd $testroot/repo && git rm -q beta)
931 git_commit $testroot/repo -m "removing beta on newbranch"
932 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
933 echo "new file on branch" > $testroot/repo/epsilon/new
934 (cd $testroot/repo && git add epsilon/new)
935 git_commit $testroot/repo -m "adding new file on newbranch"
936 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
937 (cd $testroot/repo && ln -s alpha symlink && git add symlink)
938 git_commit $testroot/repo -m "adding symlink on newbranch"
939 local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
941 got checkout -b master $testroot/repo $testroot/wt > /dev/null
943 if [ $ret -ne 0 ]; then
944 echo "got checkout failed unexpectedly" >&2
945 test_done "$testroot" "$ret"
949 # unrelated unversioned file in work tree
950 touch $testroot/wt/unversioned-file
952 # create a conflicting commit
953 (cd $testroot/repo && git checkout -q master)
954 echo "modified alpha on master" > $testroot/repo/alpha
955 git_commit $testroot/repo -m "committing to alpha on master"
956 local master_commit=`git_show_head $testroot/repo`
958 # need an up-to-date work tree for 'got merge'
959 (cd $testroot/wt && got update > /dev/null)
961 if [ $ret -ne 0 ]; then
962 echo "got update failed unexpectedly" >&2
963 test_done "$testroot" "$ret"
967 (cd $testroot/wt && got merge newbranch \
968 > $testroot/stdout 2> $testroot/stderr)
970 if [ $ret -eq 0 ]; then
971 echo "got merge succeeded unexpectedly" >&2
972 test_done "$testroot" "1"
976 echo "C alpha" >> $testroot/stdout.expected
977 echo "D beta" >> $testroot/stdout.expected
978 echo "A epsilon/new" >> $testroot/stdout.expected
979 echo "G gamma/delta" >> $testroot/stdout.expected
980 echo "A symlink" >> $testroot/stdout.expected
981 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
982 cmp -s $testroot/stdout.expected $testroot/stdout
984 if [ $ret -ne 0 ]; then
985 diff -u $testroot/stdout.expected $testroot/stdout
986 test_done "$testroot" "$ret"
990 echo "got: conflicts must be resolved before merging can continue" \
991 > $testroot/stderr.expected
992 cmp -s $testroot/stderr.expected $testroot/stderr
994 if [ $ret -ne 0 ]; then
995 diff -u $testroot/stderr.expected $testroot/stderr
996 test_done "$testroot" "$ret"
1000 # unrelated added file added during conflict resolution
1001 touch $testroot/wt/added-file
1002 (cd $testroot/wt && got add added-file > /dev/null)
1004 (cd $testroot/wt && got status > $testroot/stdout)
1006 echo "A added-file" > $testroot/stdout.expected
1007 echo "C alpha" >> $testroot/stdout.expected
1008 echo "D beta" >> $testroot/stdout.expected
1009 echo "A epsilon/new" >> $testroot/stdout.expected
1010 echo "M gamma/delta" >> $testroot/stdout.expected
1011 echo "A symlink" >> $testroot/stdout.expected
1012 echo "? unversioned-file" >> $testroot/stdout.expected
1013 cmp -s $testroot/stdout.expected $testroot/stdout
1015 if [ $ret -ne 0 ]; then
1016 diff -u $testroot/stdout.expected $testroot/stdout
1017 test_done "$testroot" "$ret"
1021 (cd $testroot/wt && got merge -a > $testroot/stdout)
1023 if [ $ret -ne 0 ]; then
1024 echo "got merge failed unexpectedly" >&2
1025 test_done "$testroot" "$ret"
1029 echo "R added-file" > $testroot/stdout.expected
1030 echo "R alpha" >> $testroot/stdout.expected
1031 echo "R beta" >> $testroot/stdout.expected
1032 echo "R epsilon/new" >> $testroot/stdout.expected
1033 echo "R gamma/delta" >> $testroot/stdout.expected
1034 echo "R symlink" >> $testroot/stdout.expected
1035 echo "G added-file" >> $testroot/stdout.expected
1036 echo "Merge of refs/heads/newbranch aborted" \
1037 >> $testroot/stdout.expected
1039 cmp -s $testroot/stdout.expected $testroot/stdout
1041 if [ $ret -ne 0 ]; then
1042 diff -u $testroot/stdout.expected $testroot/stdout
1043 test_done "$testroot" "$ret"
1047 echo "delta" > $testroot/content.expected
1048 cat $testroot/wt/gamma/delta > $testroot/content
1049 cmp -s $testroot/content.expected $testroot/content
1051 if [ $ret -ne 0 ]; then
1052 diff -u $testroot/content.expected $testroot/content
1053 test_done "$testroot" "$ret"
1057 echo "modified alpha on master" > $testroot/content.expected
1058 cat $testroot/wt/alpha > $testroot/content
1059 cmp -s $testroot/content.expected $testroot/content
1061 if [ $ret -ne 0 ]; then
1062 diff -u $testroot/content.expected $testroot/content
1063 test_done "$testroot" "$ret"
1067 echo "beta" > $testroot/content.expected
1068 cat $testroot/wt/beta > $testroot/content
1069 cmp -s $testroot/content.expected $testroot/content
1071 if [ $ret -ne 0 ]; then
1072 diff -u $testroot/content.expected $testroot/content
1073 test_done "$testroot" "$ret"
1077 if [ -e $testroot/wt/epsilon/new ]; then
1078 echo "reverted file epsilon/new still exists on disk" >&2
1079 test_done "$testroot" "1"
1083 if [ -e $testroot/wt/symlink ]; then
1084 echo "reverted symlink still exists on disk" >&2
1085 test_done "$testroot" "1"
1089 (cd $testroot/wt && got status > $testroot/stdout)
1091 echo "? added-file" > $testroot/stdout.expected
1092 echo "? unversioned-file" >> $testroot/stdout.expected
1093 cmp -s $testroot/stdout.expected $testroot/stdout
1095 if [ $ret -ne 0 ]; then
1096 diff -u $testroot/stdout.expected $testroot/stdout
1097 test_done "$testroot" "$ret"
1101 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1102 echo "commit $master_commit (master)" > $testroot/stdout.expected
1103 echo "commit $commit0" >> $testroot/stdout.expected
1104 cmp -s $testroot/stdout.expected $testroot/stdout
1106 if [ $ret -ne 0 ]; then
1107 diff -u $testroot/stdout.expected $testroot/stdout
1108 test_done "$testroot" "$ret"
1112 (cd $testroot/wt && got update > $testroot/stdout)
1114 echo 'Already up-to-date' > $testroot/stdout.expected
1115 cmp -s $testroot/stdout.expected $testroot/stdout
1117 if [ $ret -ne 0 ]; then
1118 diff -u $testroot/stdout.expected $testroot/stdout
1120 test_done "$testroot" "$ret"
1123 test_merge_in_progress() {
1124 local testroot=`test_init merge_in_progress`
1125 local commit0=`git_show_head $testroot/repo`
1126 local commit0_author_time=`git_show_author_time $testroot/repo`
1128 (cd $testroot/repo && git checkout -q -b newbranch)
1129 echo "modified alpha on branch" > $testroot/repo/alpha
1130 git_commit $testroot/repo -m "committing to alpha on newbranch"
1131 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1133 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1135 if [ $ret -ne 0 ]; then
1136 echo "got checkout failed unexpectedly" >&2
1137 test_done "$testroot" "$ret"
1141 # create a conflicting commit
1142 (cd $testroot/repo && git checkout -q master)
1143 echo "modified alpha on master" > $testroot/repo/alpha
1144 git_commit $testroot/repo -m "committing to alpha on master"
1145 local master_commit=`git_show_head $testroot/repo`
1147 # need an up-to-date work tree for 'got merge'
1148 (cd $testroot/wt && got update > /dev/null)
1150 if [ $ret -ne 0 ]; then
1151 echo "got update failed unexpectedly" >&2
1152 test_done "$testroot" "$ret"
1156 (cd $testroot/wt && got merge newbranch \
1157 > $testroot/stdout 2> $testroot/stderr)
1159 if [ $ret -eq 0 ]; then
1160 echo "got merge succeeded unexpectedly" >&2
1161 test_done "$testroot" "1"
1165 echo "C alpha" >> $testroot/stdout.expected
1166 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1167 cmp -s $testroot/stdout.expected $testroot/stdout
1169 if [ $ret -ne 0 ]; then
1170 diff -u $testroot/stdout.expected $testroot/stdout
1171 test_done "$testroot" "$ret"
1175 echo "got: conflicts must be resolved before merging can continue" \
1176 > $testroot/stderr.expected
1177 cmp -s $testroot/stderr.expected $testroot/stderr
1179 if [ $ret -ne 0 ]; then
1180 diff -u $testroot/stderr.expected $testroot/stderr
1181 test_done "$testroot" "$ret"
1185 (cd $testroot/wt && got status > $testroot/stdout)
1187 echo "C alpha" > $testroot/stdout.expected
1188 cmp -s $testroot/stdout.expected $testroot/stdout
1190 if [ $ret -ne 0 ]; then
1191 diff -u $testroot/stdout.expected $testroot/stdout
1192 test_done "$testroot" "$ret"
1196 for cmd in update commit histedit "rebase newbranch" \
1197 "integrate newbranch" "merge newbranch" "stage alpha"; do
1198 (cd $testroot/wt && got $cmd > $testroot/stdout \
1199 2> $testroot/stderr)
1201 if [ $ret -eq 0 ]; then
1202 echo "got $cmd succeeded unexpectedly" >&2
1203 test_done "$testroot" "1"
1207 echo -n > $testroot/stdout.expected
1208 cmp -s $testroot/stdout.expected $testroot/stdout
1210 if [ $ret -ne 0 ]; then
1211 diff -u $testroot/stdout.expected $testroot/stdout
1212 test_done "$testroot" "$ret"
1216 echo -n "got: a merge operation is in progress in this " \
1217 > $testroot/stderr.expected
1218 echo "work tree and must be continued or aborted first" \
1219 >> $testroot/stderr.expected
1220 cmp -s $testroot/stderr.expected $testroot/stderr
1222 if [ $ret -ne 0 ]; then
1223 diff -u $testroot/stderr.expected $testroot/stderr
1224 test_done "$testroot" "$ret"
1229 test_done "$testroot" "$ret"
1232 test_merge_path_prefix() {
1233 local testroot=`test_init merge_path_prefix`
1234 local commit0=`git_show_head $testroot/repo`
1235 local commit0_author_time=`git_show_author_time $testroot/repo`
1237 (cd $testroot/repo && git checkout -q -b newbranch)
1238 echo "modified alpha on branch" > $testroot/repo/alpha
1239 git_commit $testroot/repo -m "committing to alpha on newbranch"
1240 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1242 got checkout -p epsilon -b master $testroot/repo $testroot/wt \
1245 if [ $ret -ne 0 ]; then
1246 echo "got checkout failed unexpectedly" >&2
1247 test_done "$testroot" "$ret"
1251 # create a conflicting commit
1252 (cd $testroot/repo && git checkout -q master)
1253 echo "modified alpha on master" > $testroot/repo/alpha
1254 git_commit $testroot/repo -m "committing to alpha on master"
1255 local master_commit=`git_show_head $testroot/repo`
1257 # need an up-to-date work tree for 'got merge'
1258 (cd $testroot/wt && got update > /dev/null)
1260 if [ $ret -ne 0 ]; then
1261 echo "got update failed unexpectedly" >&2
1262 test_done "$testroot" "$ret"
1266 (cd $testroot/wt && got merge newbranch \
1267 > $testroot/stdout 2> $testroot/stderr)
1269 if [ $ret -eq 0 ]; then
1270 echo "got merge succeeded unexpectedly" >&2
1271 test_done "$testroot" "1"
1275 echo -n "got: cannot merge branch which contains changes outside " \
1276 > $testroot/stderr.expected
1277 echo "of this work tree's path prefix" >> $testroot/stderr.expected
1278 cmp -s $testroot/stderr.expected $testroot/stderr
1280 if [ $ret -ne 0 ]; then
1281 diff -u $testroot/stderr.expected $testroot/stderr
1283 test_done "$testroot" "$ret"
1286 test_merge_missing_file() {
1287 local testroot=`test_init merge_missing_file`
1288 local commit0=`git_show_head $testroot/repo`
1289 local commit0_author_time=`git_show_author_time $testroot/repo`
1291 (cd $testroot/repo && git checkout -q -b newbranch)
1292 echo "modified alpha on branch" > $testroot/repo/alpha
1293 echo "modified delta on branch" > $testroot/repo/gamma/delta
1294 git_commit $testroot/repo -m "committing to alpha and delta"
1295 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1297 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1299 if [ $ret -ne 0 ]; then
1300 echo "got checkout failed unexpectedly" >&2
1301 test_done "$testroot" "$ret"
1305 # create a conflicting commit which renames alpha
1306 (cd $testroot/repo && git checkout -q master)
1307 (cd $testroot/repo && git mv alpha epsilon/alpha-moved)
1308 git_commit $testroot/repo -m "moving alpha on master"
1309 local master_commit=`git_show_head $testroot/repo`
1311 # need an up-to-date work tree for 'got merge'
1312 (cd $testroot/wt && got update > /dev/null)
1314 if [ $ret -ne 0 ]; then
1315 echo "got update failed unexpectedly" >&2
1316 test_done "$testroot" "$ret"
1320 (cd $testroot/wt && got merge newbranch \
1321 > $testroot/stdout 2> $testroot/stderr)
1323 if [ $ret -eq 0 ]; then
1324 echo "got merge succeeded unexpectedly" >&2
1325 test_done "$testroot" "1"
1329 echo "! alpha" > $testroot/stdout.expected
1330 echo "G gamma/delta" >> $testroot/stdout.expected
1331 echo -n "Files which had incoming changes but could not be found " \
1332 >> $testroot/stdout.expected
1333 echo "in the work tree: 1" >> $testroot/stdout.expected
1334 cmp -s $testroot/stdout.expected $testroot/stdout
1336 if [ $ret -ne 0 ]; then
1337 diff -u $testroot/stdout.expected $testroot/stdout
1338 test_done "$testroot" "$ret"
1342 echo -n "got: changes destined for some files " \
1343 > $testroot/stderr.expected
1344 echo -n "were not yet merged and should be merged manually if " \
1345 >> $testroot/stderr.expected
1346 echo "required before the merge operation is continued" \
1347 >> $testroot/stderr.expected
1348 cmp -s $testroot/stderr.expected $testroot/stderr
1350 if [ $ret -ne 0 ]; then
1351 diff -u $testroot/stderr.expected $testroot/stderr
1352 test_done "$testroot" "$ret"
1356 (cd $testroot/wt && got status > $testroot/stdout)
1358 echo "M gamma/delta" > $testroot/stdout.expected
1359 cmp -s $testroot/stdout.expected $testroot/stdout
1361 if [ $ret -ne 0 ]; then
1362 diff -u $testroot/stdout.expected $testroot/stdout
1363 test_done "$testroot" "$ret"
1367 test_done "$testroot" "$ret"
1370 test_merge_no_op() {
1371 local testroot=`test_init merge_no_op`
1372 local commit0=`git_show_head $testroot/repo`
1373 local commit0_author_time=`git_show_author_time $testroot/repo`
1375 (cd $testroot/repo && git checkout -q -b newbranch)
1376 echo "modified alpha on branch" > $testroot/repo/alpha
1377 git_commit $testroot/repo -m "committing to alpha on newbranch"
1378 local branch_commit=`git_show_branch_head $testroot/repo newbranch`
1380 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1382 if [ $ret -ne 0 ]; then
1383 echo "got checkout failed unexpectedly" >&2
1384 test_done "$testroot" "$ret"
1388 # create a conflicting commit
1389 (cd $testroot/repo && git checkout -q master)
1390 echo "modified alpha on master" > $testroot/repo/alpha
1391 git_commit $testroot/repo -m "committing to alpha on master"
1392 local master_commit=`git_show_head $testroot/repo`
1394 # need an up-to-date work tree for 'got merge'
1395 (cd $testroot/wt && got update > /dev/null)
1397 if [ $ret -ne 0 ]; then
1398 echo "got update failed unexpectedly" >&2
1399 test_done "$testroot" "$ret"
1403 (cd $testroot/wt && got merge newbranch \
1404 > $testroot/stdout 2> $testroot/stderr)
1406 if [ $ret -eq 0 ]; then
1407 echo "got merge succeeded unexpectedly" >&2
1408 test_done "$testroot" "1"
1412 echo "C alpha" >> $testroot/stdout.expected
1413 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1414 cmp -s $testroot/stdout.expected $testroot/stdout
1416 if [ $ret -ne 0 ]; then
1417 diff -u $testroot/stdout.expected $testroot/stdout
1418 test_done "$testroot" "$ret"
1422 echo "got: conflicts must be resolved before merging can continue" \
1423 > $testroot/stderr.expected
1424 cmp -s $testroot/stderr.expected $testroot/stderr
1426 if [ $ret -ne 0 ]; then
1427 diff -u $testroot/stderr.expected $testroot/stderr
1428 test_done "$testroot" "$ret"
1432 (cd $testroot/wt && got status > $testroot/stdout)
1434 echo "C alpha" > $testroot/stdout.expected
1435 cmp -s $testroot/stdout.expected $testroot/stdout
1437 if [ $ret -ne 0 ]; then
1438 diff -u $testroot/stdout.expected $testroot/stdout
1439 test_done "$testroot" "$ret"
1443 # resolve the conflict by reverting all changes; now it is no-op merge
1444 (cd $testroot/wt && got revert alpha > /dev/null)
1446 if [ $ret -ne 0 ]; then
1447 echo "got revert failed unexpectedly" >&2
1448 test_done "$testroot" "$ret"
1452 (cd $testroot/wt && got merge -c > $testroot/stdout \
1453 2> $testroot/stderr)
1455 if [ $ret -ne 0 ]; then
1456 echo "got merge failed unexpectedly" >&2
1457 test_done "$testroot" "$ret"
1461 echo -n '' > $testroot/stderr.expected
1462 cmp -s $testroot/stderr.expected $testroot/stderr
1464 if [ $ret -ne 0 ]; then
1465 diff -u $testroot/stderr.expected $testroot/stderr
1466 test_done "$testroot" "$ret"
1470 local merge_commit=`git_show_head $testroot/repo`
1471 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1472 > $testroot/stdout.expected
1473 echo $merge_commit >> $testroot/stdout.expected
1475 cmp -s $testroot/stdout.expected $testroot/stdout
1477 if [ $ret -ne 0 ]; then
1478 diff -u $testroot/stdout.expected $testroot/stdout
1479 test_done "$testroot" "$ret"
1483 (cd $testroot/wt && got status > $testroot/stdout)
1485 echo -n "" > $testroot/stdout.expected
1486 cmp -s $testroot/stdout.expected $testroot/stdout
1488 if [ $ret -ne 0 ]; then
1489 diff -u $testroot/stdout.expected $testroot/stdout
1490 test_done "$testroot" "$ret"
1494 # We should have created a merge commit with two parents.
1495 got log -r $testroot/repo -l1 -c $merge_commit | grep ^parent \
1497 echo "parent 1: $master_commit" > $testroot/stdout.expected
1498 echo "parent 2: $branch_commit" >> $testroot/stdout.expected
1499 cmp -s $testroot/stdout.expected $testroot/stdout
1501 if [ $ret -ne 0 ]; then
1502 diff -u $testroot/stdout.expected $testroot/stdout
1504 test_done "$testroot" "$ret"
1507 test_merge_imported_branch() {
1508 local testroot=`test_init merge_import`
1509 local commit0=`git_show_head $testroot/repo`
1510 local commit0_author_time=`git_show_author_time $testroot/repo`
1512 # import a new sub-tree to the 'files' branch such that
1513 # none of the files added here collide with existing ones
1514 mkdir -p $testroot/tree/there
1515 mkdir -p $testroot/tree/be/lots
1516 mkdir -p $testroot/tree/files
1517 echo "there should" > $testroot/tree/there/should
1518 echo "be lots of" > $testroot/tree/be/lots/of
1519 echo "files here" > $testroot/tree/files/here
1520 got import -r $testroot/repo -b files -m 'import files' \
1521 $testroot/tree > /dev/null
1523 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1525 if [ $ret -ne 0 ]; then
1526 echo "got checkout failed unexpectedly" >&2
1527 test_done "$testroot" "$ret"
1531 (cd $testroot/wt && got merge files > $testroot/stdout)
1533 if [ $ret -ne 0 ]; then
1534 echo "got merge failed unexpectedly" >&2
1535 test_done "$testroot" "$ret"
1539 local merge_commit0=`git_show_head $testroot/repo`
1540 cat > $testroot/stdout.expected <<EOF
1544 Merged refs/heads/files into refs/heads/master: $merge_commit0
1546 cmp -s $testroot/stdout.expected $testroot/stdout
1548 if [ $ret -ne 0 ]; then
1549 diff -u $testroot/stdout.expected $testroot/stdout
1550 test_done "$testroot" "$ret"
1554 # try to merge again while no new changes are available
1555 (cd $testroot/wt && got merge files > $testroot/stdout)
1557 if [ $ret -ne 0 ]; then
1558 echo "got merge failed unexpectedly" >&2
1559 test_done "$testroot" "$ret"
1562 echo "Already up-to-date" > $testroot/stdout.expected
1563 cmp -s $testroot/stdout.expected $testroot/stdout
1565 if [ $ret -ne 0 ]; then
1566 diff -u $testroot/stdout.expected $testroot/stdout
1567 test_done "$testroot" "$ret"
1571 # update the 'files' branch
1572 (cd $testroot/repo && git reset -q --hard master)
1573 (cd $testroot/repo && git checkout -q files)
1574 echo "indeed" > $testroot/repo/indeed
1575 (cd $testroot/repo && git add indeed)
1576 git_commit $testroot/repo -m "adding another file indeed"
1577 echo "be lots and lots of" > $testroot/repo/be/lots/of
1578 git_commit $testroot/repo -m "lots of changes"
1580 (cd $testroot/wt && got update > /dev/null)
1582 if [ $ret -ne 0 ]; then
1583 echo "got update failed unexpectedly" >&2
1584 test_done "$testroot" "$ret"
1588 # we should now be able to merge more changes from files branch
1589 (cd $testroot/wt && got merge files > $testroot/stdout)
1591 if [ $ret -ne 0 ]; then
1592 echo "got merge failed unexpectedly" >&2
1593 test_done "$testroot" "$ret"
1597 local merge_commit1=`git_show_branch_head $testroot/repo master`
1598 cat > $testroot/stdout.expected <<EOF
1601 Merged refs/heads/files into refs/heads/master: $merge_commit1
1604 cmp -s $testroot/stdout.expected $testroot/stdout
1606 if [ $ret -ne 0 ]; then
1607 diff -u $testroot/stdout.expected $testroot/stdout
1609 test_done "$testroot" "$ret"
1612 test_merge_interrupt() {
1613 local testroot=`test_init merge_interrupt`
1614 local commit0=`git_show_head $testroot/repo`
1615 local commit0_author_time=`git_show_author_time $testroot/repo`
1617 (cd $testroot/repo && git checkout -q -b newbranch)
1618 echo "modified alpha on branch" > $testroot/repo/alpha
1619 git_commit $testroot/repo -m "committing to alpha on newbranch"
1620 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1622 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1624 if [ $ret -ne 0 ]; then
1625 echo "got checkout failed unexpectedly" >&2
1626 test_done "$testroot" "$ret"
1630 # create a non-conflicting commit
1631 (cd $testroot/repo && git checkout -q master)
1632 echo "modified beta on master" > $testroot/repo/beta
1633 git_commit $testroot/repo -m "committing to beta on master"
1634 local master_commit=`git_show_head $testroot/repo`
1636 # need an up-to-date work tree for 'got merge'
1637 (cd $testroot/wt && got update > /dev/null)
1639 if [ $ret -ne 0 ]; then
1640 echo "got update failed unexpectedly" >&2
1641 test_done "$testroot" "$ret"
1645 (cd $testroot/wt && got merge -n newbranch \
1646 > $testroot/stdout 2> $testroot/stderr)
1648 if [ $ret -ne 0 ]; then
1649 echo "got merge failed unexpectedly" >&2
1650 test_done "$testroot" "1"
1654 echo "G alpha" > $testroot/stdout.expected
1655 echo "Merge of refs/heads/newbranch interrupted on request" \
1656 >> $testroot/stdout.expected
1657 cmp -s $testroot/stdout.expected $testroot/stdout
1659 if [ $ret -ne 0 ]; then
1660 diff -u $testroot/stdout.expected $testroot/stdout
1661 test_done "$testroot" "$ret"
1665 (cd $testroot/wt && got status > $testroot/stdout)
1667 echo "M alpha" > $testroot/stdout.expected
1668 cmp -s $testroot/stdout.expected $testroot/stdout
1670 if [ $ret -ne 0 ]; then
1671 diff -u $testroot/stdout.expected $testroot/stdout
1672 test_done "$testroot" "$ret"
1676 echo "modified alpha on branch" > $testroot/content.expected
1677 cat $testroot/wt/alpha > $testroot/content
1678 cmp -s $testroot/content.expected $testroot/content
1680 if [ $ret -ne 0 ]; then
1681 diff -u $testroot/content.expected $testroot/content
1682 test_done "$testroot" "$ret"
1686 # adjust merge result
1687 echo "adjusted merge result" > $testroot/wt/alpha
1689 # continue the merge
1690 (cd $testroot/wt && got merge -c > $testroot/stdout)
1692 if [ $ret -ne 0 ]; then
1693 echo "got merge failed unexpectedly" >&2
1694 test_done "$testroot" "$ret"
1698 local merge_commit=`git_show_head $testroot/repo`
1700 echo "M alpha" > $testroot/stdout.expected
1701 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1702 >> $testroot/stdout.expected
1703 echo $merge_commit >> $testroot/stdout.expected
1705 cmp -s $testroot/stdout.expected $testroot/stdout
1707 if [ $ret -ne 0 ]; then
1708 diff -u $testroot/stdout.expected $testroot/stdout
1709 test_done "$testroot" "$ret"
1713 (cd $testroot/wt && got status > $testroot/stdout)
1715 echo -n > $testroot/stdout.expected
1716 cmp -s $testroot/stdout.expected $testroot/stdout
1718 if [ $ret -ne 0 ]; then
1719 diff -u $testroot/stdout.expected $testroot/stdout
1720 test_done "$testroot" "$ret"
1724 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1725 echo "commit $merge_commit (master)" > $testroot/stdout.expected
1726 echo "commit $master_commit" >> $testroot/stdout.expected
1727 echo "commit $commit0" >> $testroot/stdout.expected
1728 cmp -s $testroot/stdout.expected $testroot/stdout
1730 if [ $ret -ne 0 ]; then
1731 diff -u $testroot/stdout.expected $testroot/stdout
1732 test_done "$testroot" "$ret"
1736 (cd $testroot/wt && got update > $testroot/stdout)
1738 echo 'Already up-to-date' > $testroot/stdout.expected
1739 cmp -s $testroot/stdout.expected $testroot/stdout
1741 if [ $ret -ne 0 ]; then
1742 diff -u $testroot/stdout.expected $testroot/stdout
1743 test_done "$testroot" "$ret"
1747 # We should have created a merge commit with two parents.
1748 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
1749 echo "parent 1: $master_commit" > $testroot/stdout.expected
1750 echo "parent 2: $branch_commit0" >> $testroot/stdout.expected
1751 cmp -s $testroot/stdout.expected $testroot/stdout
1753 if [ $ret -ne 0 ]; then
1754 diff -u $testroot/stdout.expected $testroot/stdout
1756 test_done "$testroot" "$ret"
1759 test_merge_umask() {
1760 local testroot=`test_init merge_umask`
1762 (cd $testroot/repo && git checkout -q -b newbranch)
1763 echo "modified alpha on branch" >$testroot/repo/alpha
1764 git_commit "$testroot/repo" -m "committing alpha on newbranch"
1765 echo "modified delta on branch" >$testroot/repo/gamma/delta
1766 git_commit "$testroot/repo" -m "committing delta on newbranch"
1768 # diverge from newbranch
1769 (cd "$testroot/repo" && git checkout -q master)
1770 echo "modified beta on master" >$testroot/repo/beta
1771 git_commit "$testroot/repo" -m "committing zeto no master"
1773 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1775 # using a subshell to avoid clobbering global umask
1776 (umask 077 && cd "$testroot/wt" && got merge newbranch) >/dev/null
1778 for f in alpha gamma/delta; do
1779 ls -l "$testroot/wt/$f" | grep -q ^-rw-------
1780 if [ $? -ne 0 ]; then
1781 echo "$f is not 0600 after merge" >&2
1782 ls -l "$testroot/wt/$f" >&2
1783 test_done "$testroot" 1
1787 test_done "$testroot" 0
1790 test_merge_gitconfig_author() {
1791 local testroot=`test_init merge_gitconfig_author`
1793 (cd $testroot/repo && git config user.name 'Flan Luck')
1794 (cd $testroot/repo && git config user.email 'flan_luck@openbsd.org')
1796 (cd $testroot/repo && git checkout -q -b newbranch)
1797 echo "modified alpha on branch" >$testroot/repo/alpha
1798 git_commit "$testroot/repo" -m "committing alpha on newbranch"
1799 echo "modified delta on branch" >$testroot/repo/gamma/delta
1800 git_commit "$testroot/repo" -m "committing delta on newbranch"
1802 # diverge from newbranch
1803 (cd "$testroot/repo" && git checkout -q master)
1804 echo "modified beta on master" >$testroot/repo/beta
1805 git_commit "$testroot/repo" -m "committing zeto no master"
1807 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1809 # unset in a subshell to avoid affecting our environment
1810 (unset GOT_IGNORE_GITCONFIG && cd $testroot/wt && \
1811 got merge newbranch > /dev/null)
1813 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
1815 if [ $ret -ne 0 ]; then
1816 test_done "$testroot" "$ret"
1820 echo "from: Flan Luck <flan_luck@openbsd.org>" \
1821 > $testroot/stdout.expected
1822 cmp -s $testroot/stdout.expected $testroot/stdout
1824 if [ $ret -ne 0 ]; then
1825 diff -u $testroot/stdout.expected $testroot/stdout
1827 test_done "$testroot" "$ret"
1830 test_merge_fetched_branch() {
1831 local testroot=`test_init merge_fetched_branch`
1832 local testurl=ssh://127.0.0.1/$testroot
1833 local commit_id=`git_show_head $testroot/repo`
1835 got clone -q $testurl/repo $testroot/repo-clone
1837 if [ $ret -ne 0 ]; then
1838 echo "got clone command failed unexpectedly" >&2
1839 test_done "$testroot" "$ret"
1843 echo "modified alpha" > $testroot/repo/alpha
1844 git_commit $testroot/repo -m "modified alpha"
1845 local commit_id2=`git_show_head $testroot/repo`
1847 got fetch -q -r $testroot/repo-clone > $testroot/stdout
1849 if [ $ret -ne 0 ]; then
1850 echo "got fetch command failed unexpectedly" >&2
1851 test_done "$testroot" "$ret"
1855 echo -n > $testroot/stdout.expected
1857 cmp -s $testroot/stdout $testroot/stdout.expected
1859 if [ $ret -ne 0 ]; then
1860 diff -u $testroot/stdout.expected $testroot/stdout
1861 test_done "$testroot" "$ret"
1865 got ref -l -r $testroot/repo-clone > $testroot/stdout
1867 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1868 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1869 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1870 >> $testroot/stdout.expected
1871 echo "refs/remotes/origin/master: $commit_id2" \
1872 >> $testroot/stdout.expected
1874 cmp -s $testroot/stdout $testroot/stdout.expected
1876 if [ $ret -ne 0 ]; then
1877 diff -u $testroot/stdout.expected $testroot/stdout
1878 test_done "$testroot" "$ret"
1882 got checkout $testroot/repo-clone $testroot/wt > /dev/null
1884 echo "modified beta" > $testroot/wt/beta
1885 (cd $testroot/wt && got commit -m "modified beta" > /dev/null)
1886 local commit_id3=`git_show_head $testroot/repo-clone`
1888 (cd $testroot/wt && got update > /dev/null)
1889 (cd $testroot/wt && got merge origin/master > $testroot/stdout)
1890 local merge_commit_id=`git_show_head $testroot/repo-clone`
1892 cat > $testroot/stdout.expected <<EOF
1894 Merged refs/remotes/origin/master into refs/heads/master: $merge_commit_id
1897 cmp -s $testroot/stdout $testroot/stdout.expected
1899 if [ $ret -ne 0 ]; then
1900 diff -u $testroot/stdout.expected $testroot/stdout
1902 test_done "$testroot" "$ret"
1905 test_merge_fetched_branch_remote() {
1906 local testroot=`test_init merge_fetched_branch_remote`
1907 local testurl=ssh://127.0.0.1/$testroot
1908 local commit_id=`git_show_head $testroot/repo`
1910 got clone -q $testurl/repo $testroot/repo-clone
1912 if [ $ret -ne 0 ]; then
1913 echo "got clone command failed unexpectedly" >&2
1914 test_done "$testroot" "$ret"
1918 echo "modified alpha" > $testroot/repo/alpha
1919 git_commit $testroot/repo -m "modified alpha"
1920 local commit_id2=`git_show_head $testroot/repo`
1922 got fetch -q -r $testroot/repo-clone > $testroot/stdout
1924 if [ $ret -ne 0 ]; then
1925 echo "got fetch command failed unexpectedly" >&2
1926 test_done "$testroot" "$ret"
1930 echo -n > $testroot/stdout.expected
1932 cmp -s $testroot/stdout $testroot/stdout.expected
1934 if [ $ret -ne 0 ]; then
1935 diff -u $testroot/stdout.expected $testroot/stdout
1936 test_done "$testroot" "$ret"
1940 got ref -l -r $testroot/repo-clone > $testroot/stdout
1942 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1943 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1944 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1945 >> $testroot/stdout.expected
1946 echo "refs/remotes/origin/master: $commit_id2" \
1947 >> $testroot/stdout.expected
1949 cmp -s $testroot/stdout $testroot/stdout.expected
1951 if [ $ret -ne 0 ]; then
1952 diff -u $testroot/stdout.expected $testroot/stdout
1953 test_done "$testroot" "$ret"
1957 got checkout $testroot/repo-clone $testroot/wt > /dev/null
1959 echo "modified beta" > $testroot/wt/beta
1960 (cd $testroot/wt && got commit -m "modified beta" > /dev/null)
1961 local commit_id3=`git_show_head $testroot/repo-clone`
1963 (cd $testroot/wt && got update -b origin/master > /dev/null)
1964 (cd $testroot/wt && got merge master > \
1965 $testroot/stdout 2> $testroot/stderr)
1966 local merge_commit_id=`git_show_head $testroot/repo-clone`
1968 echo -n > $testroot/stdout.expected
1970 cmp -s $testroot/stdout $testroot/stdout.expected
1972 if [ $ret -ne 0 ]; then
1973 diff -u $testroot/stdout.expected $testroot/stdout
1974 test_done "$testroot" "$ret"
1978 echo -n "got: work tree's current branch refs/remotes/origin/master " \
1979 > $testroot/stderr.expected
1980 echo -n 'is outside the "refs/heads/" reference namespace; ' \
1981 >> $testroot/stderr.expected
1982 echo -n "update -b required: will not commit to a branch " \
1983 >> $testroot/stderr.expected
1984 echo 'outside the "refs/heads/" reference namespace' \
1985 >> $testroot/stderr.expected
1987 cmp -s $testroot/stderr $testroot/stderr.expected
1989 if [ $ret -ne 0 ]; then
1990 diff -u $testroot/stderr.expected $testroot/stderr
1992 test_done "$testroot" "$ret"
1996 run_test test_merge_basic
1997 run_test test_merge_forward
1998 run_test test_merge_forward_commit
1999 run_test test_merge_forward_interrupt
2000 run_test test_merge_backward
2001 run_test test_merge_continue
2002 run_test test_merge_continue_new_commit
2003 run_test test_merge_abort
2004 run_test test_merge_in_progress
2005 run_test test_merge_path_prefix
2006 run_test test_merge_missing_file
2007 run_test test_merge_no_op
2008 run_test test_merge_imported_branch
2009 run_test test_merge_interrupt
2010 run_test test_merge_umask
2011 run_test test_merge_gitconfig_author
2012 run_test test_merge_fetched_branch
2013 run_test test_merge_fetched_branch_remote