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" != "0" ]; then
50 echo "got checkout failed unexpectedly" >&2
51 test_done "$testroot" "$ret"
55 # need a divergant commit on the main branch for 'got merge'
56 (cd $testroot/wt && got merge newbranch \
57 > $testroot/stdout 2> $testroot/stderr)
59 if [ "$ret" == "0" ]; then
60 echo "got merge succeeded unexpectedly" >&2
61 test_done "$testroot" "1"
64 echo -n "got: cannot create a merge commit because " \
65 > $testroot/stderr.expected
66 echo -n "refs/heads/newbranch is based on refs/heads/master; " \
67 >> $testroot/stderr.expected
68 echo -n "refs/heads/newbranch can be integrated with " \
69 >> $testroot/stderr.expected
70 echo "'got integrate' instead" >> $testroot/stderr.expected
71 cmp -s $testroot/stderr.expected $testroot/stderr
73 if [ "$ret" != "0" ]; then
74 diff -u $testroot/stderr.expected $testroot/stderr
75 test_done "$testroot" "$ret"
79 # create the required dirvergant commit
80 (cd $testroot/repo && git checkout -q master)
81 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
82 git_commit $testroot/repo -m "committing to zeta on master"
83 local master_commit=`git_show_head $testroot/repo`
85 # need an up-to-date work tree for 'got merge'
86 (cd $testroot/wt && got merge newbranch \
87 > $testroot/stdout 2> $testroot/stderr)
89 if [ "$ret" == "0" ]; then
90 echo "got merge succeeded unexpectedly" >&2
91 test_done "$testroot" "$ret"
94 echo -n "got: work tree must be updated before it can be used " \
95 > $testroot/stderr.expected
96 echo "to merge a branch" >> $testroot/stderr.expected
97 cmp -s $testroot/stderr.expected $testroot/stderr
99 if [ "$ret" != "0" ]; then
100 diff -u $testroot/stderr.expected $testroot/stderr
101 test_done "$testroot" "$ret"
105 (cd $testroot/wt && got update > /dev/null)
107 if [ "$ret" != "0" ]; then
108 echo "got update failed unexpectedly" >&2
109 test_done "$testroot" "$ret"
113 # must not use a mixed-commit work tree with 'got merge'
114 (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
116 if [ "$ret" != "0" ]; then
117 echo "got update failed unexpectedly" >&2
118 test_done "$testroot" "$ret"
121 (cd $testroot/wt && got merge newbranch \
122 > $testroot/stdout 2> $testroot/stderr)
124 if [ "$ret" == "0" ]; then
125 echo "got merge succeeded unexpectedly" >&2
126 test_done "$testroot" "$ret"
129 echo -n "got: work tree contains files from multiple base commits; " \
130 > $testroot/stderr.expected
131 echo "the entire work tree must be updated first" \
132 >> $testroot/stderr.expected
133 cmp -s $testroot/stderr.expected $testroot/stderr
135 if [ "$ret" != "0" ]; then
136 diff -u $testroot/stderr.expected $testroot/stderr
137 test_done "$testroot" "$ret"
141 (cd $testroot/wt && got update > /dev/null)
143 if [ "$ret" != "0" ]; then
144 echo "got update failed unexpectedly" >&2
145 test_done "$testroot" "$ret"
149 # must not have staged files with 'got merge'
150 echo "modified file alpha" > $testroot/wt/alpha
151 (cd $testroot/wt && got stage alpha > /dev/null)
153 if [ "$ret" != "0" ]; then
154 echo "got stage failed unexpectedly" >&2
155 test_done "$testroot" "$ret"
158 (cd $testroot/wt && got merge newbranch \
159 > $testroot/stdout 2> $testroot/stderr)
161 if [ "$ret" == "0" ]; then
162 echo "got merge succeeded unexpectedly" >&2
163 test_done "$testroot" "$ret"
166 echo "got: alpha: file is staged" > $testroot/stderr.expected
167 cmp -s $testroot/stderr.expected $testroot/stderr
169 if [ "$ret" != "0" ]; then
170 diff -u $testroot/stderr.expected $testroot/stderr
171 test_done "$testroot" "$ret"
174 (cd $testroot/wt && got unstage alpha > /dev/null)
176 if [ "$ret" != "0" ]; then
177 echo "got unstage failed unexpectedly" >&2
178 test_done "$testroot" "$ret"
182 # must not have local changes with 'got merge'
183 (cd $testroot/wt && got merge newbranch \
184 > $testroot/stdout 2> $testroot/stderr)
186 if [ "$ret" == "0" ]; then
187 echo "got merge succeeded unexpectedly" >&2
188 test_done "$testroot" "$ret"
191 echo -n "got: work tree contains local changes; " \
192 > $testroot/stderr.expected
193 echo "these changes must be committed or reverted first" \
194 >> $testroot/stderr.expected
195 cmp -s $testroot/stderr.expected $testroot/stderr
197 if [ "$ret" != "0" ]; then
198 diff -u $testroot/stderr.expected $testroot/stderr
199 test_done "$testroot" "$ret"
203 (cd $testroot/wt && got revert alpha > /dev/null)
205 if [ "$ret" != "0" ]; then
206 echo "got revert failed unexpectedly" >&2
207 test_done "$testroot" "$ret"
211 (cd $testroot/wt && got merge newbranch > $testroot/stdout)
213 if [ "$ret" != "0" ]; then
214 echo "got merge failed unexpectedly" >&2
215 test_done "$testroot" "$ret"
219 local merge_commit=`git_show_head $testroot/repo`
221 echo "G alpha" >> $testroot/stdout.expected
222 echo "D beta" >> $testroot/stdout.expected
223 echo "A dotgotbar.link" >> $testroot/stdout.expected
224 echo "A epsilon/new" >> $testroot/stdout.expected
225 echo "G gamma/delta" >> $testroot/stdout.expected
226 echo "A symlink" >> $testroot/stdout.expected
227 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
228 >> $testroot/stdout.expected
229 echo $merge_commit >> $testroot/stdout.expected
231 cmp -s $testroot/stdout.expected $testroot/stdout
233 if [ "$ret" != "0" ]; then
234 diff -u $testroot/stdout.expected $testroot/stdout
235 test_done "$testroot" "$ret"
239 echo "modified delta on branch" > $testroot/content.expected
240 cat $testroot/wt/gamma/delta > $testroot/content
241 cmp -s $testroot/content.expected $testroot/content
243 if [ "$ret" != "0" ]; then
244 diff -u $testroot/content.expected $testroot/content
245 test_done "$testroot" "$ret"
249 echo "modified alpha on branch" > $testroot/content.expected
250 cat $testroot/wt/alpha > $testroot/content
251 cmp -s $testroot/content.expected $testroot/content
253 if [ "$ret" != "0" ]; then
254 diff -u $testroot/content.expected $testroot/content
255 test_done "$testroot" "$ret"
259 if [ -e $testroot/wt/beta ]; then
260 echo "removed file beta still exists on disk" >&2
261 test_done "$testroot" "1"
265 echo "new file on branch" > $testroot/content.expected
266 cat $testroot/wt/epsilon/new > $testroot/content
267 cmp -s $testroot/content.expected $testroot/content
269 if [ "$ret" != "0" ]; then
270 diff -u $testroot/content.expected $testroot/content
271 test_done "$testroot" "$ret"
275 if [ ! -h $testroot/wt/dotgotbar.link ]; then
276 echo "dotgotbar.link is not a symlink"
277 test_done "$testroot" "1"
281 readlink $testroot/wt/symlink > $testroot/stdout
282 echo "alpha" > $testroot/stdout.expected
283 cmp -s $testroot/stdout.expected $testroot/stdout
285 if [ "$ret" != "0" ]; then
286 diff -u $testroot/stdout.expected $testroot/stdout
287 test_done "$testroot" "$ret"
291 (cd $testroot/wt && got status > $testroot/stdout)
293 echo -n > $testroot/stdout.expected
294 cmp -s $testroot/stdout.expected $testroot/stdout
296 if [ "$ret" != "0" ]; then
297 diff -u $testroot/stdout.expected $testroot/stdout
298 test_done "$testroot" "$ret"
302 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
303 echo "commit $merge_commit (master)" > $testroot/stdout.expected
304 echo "commit $master_commit" >> $testroot/stdout.expected
305 echo "commit $commit0" >> $testroot/stdout.expected
306 cmp -s $testroot/stdout.expected $testroot/stdout
308 if [ "$ret" != "0" ]; then
309 diff -u $testroot/stdout.expected $testroot/stdout
310 test_done "$testroot" "$ret"
314 (cd $testroot/wt && got update > $testroot/stdout)
316 echo 'U dotgotbar.link' > $testroot/stdout.expected
317 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
318 git_show_head $testroot/repo >> $testroot/stdout.expected
319 echo >> $testroot/stdout.expected
320 cmp -s $testroot/stdout.expected $testroot/stdout
322 if [ "$ret" != "0" ]; then
323 diff -u $testroot/stdout.expected $testroot/stdout
324 test_done "$testroot" "$ret"
328 # update has changed the bad symlink into a regular file
329 if [ -h $testroot/wt/dotgotbar.link ]; then
330 echo "dotgotbar.link is a symlink"
331 test_done "$testroot" "1"
335 # We should have created a merge commit with two parents.
336 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
337 echo "parent 1: $master_commit" > $testroot/stdout.expected
338 echo "parent 2: $branch_commit5" >> $testroot/stdout.expected
339 cmp -s $testroot/stdout.expected $testroot/stdout
341 if [ "$ret" != "0" ]; then
342 diff -u $testroot/stdout.expected $testroot/stdout
343 test_done "$testroot" "$ret"
347 got tree -r $testroot/repo -c $merge_commit -R > $testroot/stdout
349 if [ "$ret" != "0" ]; then
350 echo "got tree failed unexpectedly" >&2
351 test_done "$testroot" "$ret"
355 # bad symlink dotgotbar.link appears as a symlink in the merge commit:
356 cat > $testroot/stdout.expected <<EOF
358 dotgotbar.link@ -> .got/bar
366 cmp -s $testroot/stdout.expected $testroot/stdout
368 if [ "$ret" != "0" ]; then
369 diff -u $testroot/stdout.expected $testroot/stdout
371 test_done "$testroot" "$ret"
374 test_merge_continue() {
375 local testroot=`test_init merge_continue`
376 local commit0=`git_show_head $testroot/repo`
377 local commit0_author_time=`git_show_author_time $testroot/repo`
379 (cd $testroot/repo && git checkout -q -b newbranch)
380 echo "modified delta on branch" > $testroot/repo/gamma/delta
381 git_commit $testroot/repo -m "committing to delta on newbranch"
382 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
384 echo "modified alpha on branch" > $testroot/repo/alpha
385 git_commit $testroot/repo -m "committing to alpha on newbranch"
386 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
387 (cd $testroot/repo && git rm -q beta)
388 git_commit $testroot/repo -m "removing beta on newbranch"
389 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
390 echo "new file on branch" > $testroot/repo/epsilon/new
391 (cd $testroot/repo && git add epsilon/new)
392 git_commit $testroot/repo -m "adding new file on newbranch"
393 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
395 got checkout -b master $testroot/repo $testroot/wt > /dev/null
397 if [ "$ret" != "0" ]; then
398 echo "got checkout failed unexpectedly" >&2
399 test_done "$testroot" "$ret"
403 # create a conflicting commit
404 (cd $testroot/repo && git checkout -q master)
405 echo "modified alpha on master" > $testroot/repo/alpha
406 git_commit $testroot/repo -m "committing to alpha on master"
407 local master_commit=`git_show_head $testroot/repo`
409 # need an up-to-date work tree for 'got merge'
410 (cd $testroot/wt && got update > /dev/null)
412 if [ "$ret" != "0" ]; then
413 echo "got update failed unexpectedly" >&2
414 test_done "$testroot" "$ret"
418 (cd $testroot/wt && got merge newbranch \
419 > $testroot/stdout 2> $testroot/stderr)
421 if [ "$ret" == "0" ]; then
422 echo "got merge succeeded unexpectedly" >&2
423 test_done "$testroot" "1"
427 echo "C alpha" >> $testroot/stdout.expected
428 echo "D beta" >> $testroot/stdout.expected
429 echo "A epsilon/new" >> $testroot/stdout.expected
430 echo "G gamma/delta" >> $testroot/stdout.expected
431 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
432 cmp -s $testroot/stdout.expected $testroot/stdout
434 if [ "$ret" != "0" ]; then
435 diff -u $testroot/stdout.expected $testroot/stdout
436 test_done "$testroot" "$ret"
440 echo "got: conflicts must be resolved before merging can continue" \
441 > $testroot/stderr.expected
442 cmp -s $testroot/stderr.expected $testroot/stderr
444 if [ "$ret" != "0" ]; then
445 diff -u $testroot/stderr.expected $testroot/stderr
446 test_done "$testroot" "$ret"
450 (cd $testroot/wt && got status > $testroot/stdout)
452 echo "C alpha" > $testroot/stdout.expected
453 echo "D beta" >> $testroot/stdout.expected
454 echo "A epsilon/new" >> $testroot/stdout.expected
455 echo "M gamma/delta" >> $testroot/stdout.expected
456 cmp -s $testroot/stdout.expected $testroot/stdout
458 if [ "$ret" != "0" ]; then
459 diff -u $testroot/stdout.expected $testroot/stdout
460 test_done "$testroot" "$ret"
464 echo '<<<<<<<' > $testroot/content.expected
465 echo "modified alpha on master" >> $testroot/content.expected
466 echo "||||||| 3-way merge base: commit $commit0" \
467 >> $testroot/content.expected
468 echo "alpha" >> $testroot/content.expected
469 echo "=======" >> $testroot/content.expected
470 echo "modified alpha on branch" >> $testroot/content.expected
471 echo ">>>>>>> merged change: commit $branch_commit3" \
472 >> $testroot/content.expected
473 cat $testroot/wt/alpha > $testroot/content
474 cmp -s $testroot/content.expected $testroot/content
476 if [ "$ret" != "0" ]; then
477 diff -u $testroot/content.expected $testroot/content
478 test_done "$testroot" "$ret"
482 # resolve the conflict
483 echo "modified alpha by both branches" > $testroot/wt/alpha
485 (cd $testroot/wt && got merge -c > $testroot/stdout)
487 if [ "$ret" != "0" ]; then
488 echo "got merge failed unexpectedly" >&2
489 test_done "$testroot" "$ret"
493 local merge_commit=`git_show_head $testroot/repo`
495 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
496 > $testroot/stdout.expected
497 echo $merge_commit >> $testroot/stdout.expected
499 cmp -s $testroot/stdout.expected $testroot/stdout
501 if [ "$ret" != "0" ]; then
502 diff -u $testroot/stdout.expected $testroot/stdout
503 test_done "$testroot" "$ret"
507 echo "modified delta on branch" > $testroot/content.expected
508 cat $testroot/wt/gamma/delta > $testroot/content
509 cmp -s $testroot/content.expected $testroot/content
511 if [ "$ret" != "0" ]; then
512 diff -u $testroot/content.expected $testroot/content
513 test_done "$testroot" "$ret"
517 echo "modified alpha by both branches" > $testroot/content.expected
518 cat $testroot/wt/alpha > $testroot/content
519 cmp -s $testroot/content.expected $testroot/content
521 if [ "$ret" != "0" ]; then
522 diff -u $testroot/content.expected $testroot/content
523 test_done "$testroot" "$ret"
527 if [ -e $testroot/wt/beta ]; then
528 echo "removed file beta still exists on disk" >&2
529 test_done "$testroot" "1"
533 echo "new file on branch" > $testroot/content.expected
534 cat $testroot/wt/epsilon/new > $testroot/content
535 cmp -s $testroot/content.expected $testroot/content
537 if [ "$ret" != "0" ]; then
538 diff -u $testroot/content.expected $testroot/content
539 test_done "$testroot" "$ret"
543 (cd $testroot/wt && got status > $testroot/stdout)
545 echo -n > $testroot/stdout.expected
546 cmp -s $testroot/stdout.expected $testroot/stdout
548 if [ "$ret" != "0" ]; then
549 diff -u $testroot/stdout.expected $testroot/stdout
550 test_done "$testroot" "$ret"
554 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
555 echo "commit $merge_commit (master)" > $testroot/stdout.expected
556 echo "commit $master_commit" >> $testroot/stdout.expected
557 echo "commit $commit0" >> $testroot/stdout.expected
558 cmp -s $testroot/stdout.expected $testroot/stdout
560 if [ "$ret" != "0" ]; then
561 diff -u $testroot/stdout.expected $testroot/stdout
562 test_done "$testroot" "$ret"
566 (cd $testroot/wt && got update > $testroot/stdout)
568 echo 'Already up-to-date' > $testroot/stdout.expected
569 cmp -s $testroot/stdout.expected $testroot/stdout
571 if [ "$ret" != "0" ]; then
572 diff -u $testroot/stdout.expected $testroot/stdout
573 test_done "$testroot" "$ret"
577 # We should have created a merge commit with two parents.
578 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
579 echo "parent 1: $master_commit" > $testroot/stdout.expected
580 echo "parent 2: $branch_commit3" >> $testroot/stdout.expected
581 cmp -s $testroot/stdout.expected $testroot/stdout
583 if [ "$ret" != "0" ]; then
584 diff -u $testroot/stdout.expected $testroot/stdout
586 test_done "$testroot" "$ret"
590 local testroot=`test_init merge_abort`
591 local commit0=`git_show_head $testroot/repo`
592 local commit0_author_time=`git_show_author_time $testroot/repo`
594 (cd $testroot/repo && git checkout -q -b newbranch)
595 echo "modified delta on branch" > $testroot/repo/gamma/delta
596 git_commit $testroot/repo -m "committing to delta on newbranch"
597 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
599 echo "modified alpha on branch" > $testroot/repo/alpha
600 git_commit $testroot/repo -m "committing to alpha on newbranch"
601 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
602 (cd $testroot/repo && git rm -q beta)
603 git_commit $testroot/repo -m "removing beta on newbranch"
604 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
605 echo "new file on branch" > $testroot/repo/epsilon/new
606 (cd $testroot/repo && git add epsilon/new)
607 git_commit $testroot/repo -m "adding new file on newbranch"
608 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
609 (cd $testroot/repo && ln -s alpha symlink && git add symlink)
610 git_commit $testroot/repo -m "adding symlink on newbranch"
611 local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
613 got checkout -b master $testroot/repo $testroot/wt > /dev/null
615 if [ "$ret" != "0" ]; then
616 echo "got checkout failed unexpectedly" >&2
617 test_done "$testroot" "$ret"
621 # create a conflicting commit
622 (cd $testroot/repo && git checkout -q master)
623 echo "modified alpha on master" > $testroot/repo/alpha
624 git_commit $testroot/repo -m "committing to alpha on master"
625 local master_commit=`git_show_head $testroot/repo`
627 # need an up-to-date work tree for 'got merge'
628 (cd $testroot/wt && got update > /dev/null)
630 if [ "$ret" != "0" ]; then
631 echo "got update failed unexpectedly" >&2
632 test_done "$testroot" "$ret"
636 (cd $testroot/wt && got merge newbranch \
637 > $testroot/stdout 2> $testroot/stderr)
639 if [ "$ret" == "0" ]; then
640 echo "got merge succeeded unexpectedly" >&2
641 test_done "$testroot" "1"
645 echo "C alpha" >> $testroot/stdout.expected
646 echo "D beta" >> $testroot/stdout.expected
647 echo "A epsilon/new" >> $testroot/stdout.expected
648 echo "G gamma/delta" >> $testroot/stdout.expected
649 echo "A symlink" >> $testroot/stdout.expected
650 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
651 cmp -s $testroot/stdout.expected $testroot/stdout
653 if [ "$ret" != "0" ]; then
654 diff -u $testroot/stdout.expected $testroot/stdout
655 test_done "$testroot" "$ret"
659 echo "got: conflicts must be resolved before merging can continue" \
660 > $testroot/stderr.expected
661 cmp -s $testroot/stderr.expected $testroot/stderr
663 if [ "$ret" != "0" ]; then
664 diff -u $testroot/stderr.expected $testroot/stderr
665 test_done "$testroot" "$ret"
669 (cd $testroot/wt && got status > $testroot/stdout)
671 echo "C alpha" > $testroot/stdout.expected
672 echo "D beta" >> $testroot/stdout.expected
673 echo "A epsilon/new" >> $testroot/stdout.expected
674 echo "M gamma/delta" >> $testroot/stdout.expected
675 echo "A symlink" >> $testroot/stdout.expected
676 cmp -s $testroot/stdout.expected $testroot/stdout
678 if [ "$ret" != "0" ]; then
679 diff -u $testroot/stdout.expected $testroot/stdout
680 test_done "$testroot" "$ret"
684 (cd $testroot/wt && got merge -a > $testroot/stdout)
686 if [ "$ret" != "0" ]; then
687 echo "got merge failed unexpectedly" >&2
688 test_done "$testroot" "$ret"
692 echo "R alpha" > $testroot/stdout.expected
693 echo "R beta" >> $testroot/stdout.expected
694 echo "R epsilon/new" >> $testroot/stdout.expected
695 echo "R gamma/delta" >> $testroot/stdout.expected
696 echo "R symlink" >> $testroot/stdout.expected
697 echo "Merge of refs/heads/newbranch aborted" \
698 >> $testroot/stdout.expected
700 cmp -s $testroot/stdout.expected $testroot/stdout
702 if [ "$ret" != "0" ]; then
703 diff -u $testroot/stdout.expected $testroot/stdout
704 test_done "$testroot" "$ret"
708 echo "delta" > $testroot/content.expected
709 cat $testroot/wt/gamma/delta > $testroot/content
710 cmp -s $testroot/content.expected $testroot/content
712 if [ "$ret" != "0" ]; then
713 diff -u $testroot/content.expected $testroot/content
714 test_done "$testroot" "$ret"
718 echo "modified alpha on master" > $testroot/content.expected
719 cat $testroot/wt/alpha > $testroot/content
720 cmp -s $testroot/content.expected $testroot/content
722 if [ "$ret" != "0" ]; then
723 diff -u $testroot/content.expected $testroot/content
724 test_done "$testroot" "$ret"
728 echo "beta" > $testroot/content.expected
729 cat $testroot/wt/beta > $testroot/content
730 cmp -s $testroot/content.expected $testroot/content
732 if [ "$ret" != "0" ]; then
733 diff -u $testroot/content.expected $testroot/content
734 test_done "$testroot" "$ret"
738 if [ -e $testroot/wt/epsilon/new ]; then
739 echo "reverted file epsilon/new still exists on disk" >&2
740 test_done "$testroot" "1"
744 if [ -e $testroot/wt/symlink ]; then
745 echo "reverted symlink still exists on disk" >&2
746 test_done "$testroot" "1"
750 (cd $testroot/wt && got status > $testroot/stdout)
752 echo -n "" > $testroot/stdout.expected
753 cmp -s $testroot/stdout.expected $testroot/stdout
755 if [ "$ret" != "0" ]; then
756 diff -u $testroot/stdout.expected $testroot/stdout
757 test_done "$testroot" "$ret"
761 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
762 echo "commit $master_commit (master)" > $testroot/stdout.expected
763 echo "commit $commit0" >> $testroot/stdout.expected
764 cmp -s $testroot/stdout.expected $testroot/stdout
766 if [ "$ret" != "0" ]; then
767 diff -u $testroot/stdout.expected $testroot/stdout
768 test_done "$testroot" "$ret"
772 (cd $testroot/wt && got update > $testroot/stdout)
774 echo 'Already up-to-date' > $testroot/stdout.expected
775 cmp -s $testroot/stdout.expected $testroot/stdout
777 if [ "$ret" != "0" ]; then
778 diff -u $testroot/stdout.expected $testroot/stdout
780 test_done "$testroot" "$ret"
783 test_merge_in_progress() {
784 local testroot=`test_init merge_in_progress`
785 local commit0=`git_show_head $testroot/repo`
786 local commit0_author_time=`git_show_author_time $testroot/repo`
788 (cd $testroot/repo && git checkout -q -b newbranch)
789 echo "modified alpha on branch" > $testroot/repo/alpha
790 git_commit $testroot/repo -m "committing to alpha on newbranch"
791 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
793 got checkout -b master $testroot/repo $testroot/wt > /dev/null
795 if [ "$ret" != "0" ]; then
796 echo "got checkout failed unexpectedly" >&2
797 test_done "$testroot" "$ret"
801 # create a conflicting commit
802 (cd $testroot/repo && git checkout -q master)
803 echo "modified alpha on master" > $testroot/repo/alpha
804 git_commit $testroot/repo -m "committing to alpha on master"
805 local master_commit=`git_show_head $testroot/repo`
807 # need an up-to-date work tree for 'got merge'
808 (cd $testroot/wt && got update > /dev/null)
810 if [ "$ret" != "0" ]; then
811 echo "got update failed unexpectedly" >&2
812 test_done "$testroot" "$ret"
816 (cd $testroot/wt && got merge newbranch \
817 > $testroot/stdout 2> $testroot/stderr)
819 if [ "$ret" == "0" ]; then
820 echo "got merge succeeded unexpectedly" >&2
821 test_done "$testroot" "1"
825 echo "C alpha" >> $testroot/stdout.expected
826 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
827 cmp -s $testroot/stdout.expected $testroot/stdout
829 if [ "$ret" != "0" ]; then
830 diff -u $testroot/stdout.expected $testroot/stdout
831 test_done "$testroot" "$ret"
835 echo "got: conflicts must be resolved before merging can continue" \
836 > $testroot/stderr.expected
837 cmp -s $testroot/stderr.expected $testroot/stderr
839 if [ "$ret" != "0" ]; then
840 diff -u $testroot/stderr.expected $testroot/stderr
841 test_done "$testroot" "$ret"
845 (cd $testroot/wt && got status > $testroot/stdout)
847 echo "C alpha" > $testroot/stdout.expected
848 cmp -s $testroot/stdout.expected $testroot/stdout
850 if [ "$ret" != "0" ]; then
851 diff -u $testroot/stdout.expected $testroot/stdout
852 test_done "$testroot" "$ret"
856 for cmd in update commit histedit "rebase newbranch" \
857 "integrate newbranch" "stage alpha"; do
858 (cd $testroot/wt && got $cmd > $testroot/stdout \
861 echo -n > $testroot/stdout.expected
862 cmp -s $testroot/stdout.expected $testroot/stdout
864 if [ "$ret" != "0" ]; then
865 diff -u $testroot/stdout.expected $testroot/stdout
866 test_done "$testroot" "$ret"
870 echo -n "got: a merge operation is in progress in this " \
871 > $testroot/stderr.expected
872 echo "work tree and must be continued or aborted first" \
873 >> $testroot/stderr.expected
874 cmp -s $testroot/stderr.expected $testroot/stderr
876 if [ "$ret" != "0" ]; then
877 diff -u $testroot/stderr.expected $testroot/stderr
878 test_done "$testroot" "$ret"
883 test_done "$testroot" "$ret"
886 test_merge_path_prefix() {
887 local testroot=`test_init merge_path_prefix`
888 local commit0=`git_show_head $testroot/repo`
889 local commit0_author_time=`git_show_author_time $testroot/repo`
891 (cd $testroot/repo && git checkout -q -b newbranch)
892 echo "modified alpha on branch" > $testroot/repo/alpha
893 git_commit $testroot/repo -m "committing to alpha on newbranch"
894 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
896 got checkout -p epsilon -b master $testroot/repo $testroot/wt \
899 if [ "$ret" != "0" ]; then
900 echo "got checkout failed unexpectedly" >&2
901 test_done "$testroot" "$ret"
905 # create a conflicting commit
906 (cd $testroot/repo && git checkout -q master)
907 echo "modified alpha on master" > $testroot/repo/alpha
908 git_commit $testroot/repo -m "committing to alpha on master"
909 local master_commit=`git_show_head $testroot/repo`
911 # need an up-to-date work tree for 'got merge'
912 (cd $testroot/wt && got update > /dev/null)
914 if [ "$ret" != "0" ]; then
915 echo "got update failed unexpectedly" >&2
916 test_done "$testroot" "$ret"
920 (cd $testroot/wt && got merge newbranch \
921 > $testroot/stdout 2> $testroot/stderr)
923 if [ "$ret" == "0" ]; then
924 echo "got merge succeeded unexpectedly" >&2
925 test_done "$testroot" "1"
929 echo -n "got: cannot merge branch which contains changes outside " \
930 > $testroot/stderr.expected
931 echo "of this work tree's path prefix" >> $testroot/stderr.expected
932 cmp -s $testroot/stderr.expected $testroot/stderr
934 if [ "$ret" != "0" ]; then
935 diff -u $testroot/stderr.expected $testroot/stderr
937 test_done "$testroot" "$ret"
940 test_merge_missing_file() {
941 local testroot=`test_init merge_missing_file`
942 local commit0=`git_show_head $testroot/repo`
943 local commit0_author_time=`git_show_author_time $testroot/repo`
945 (cd $testroot/repo && git checkout -q -b newbranch)
946 echo "modified alpha on branch" > $testroot/repo/alpha
947 echo "modified delta on branch" > $testroot/repo/gamma/delta
948 git_commit $testroot/repo -m "committing to alpha and delta"
949 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
951 got checkout -b master $testroot/repo $testroot/wt > /dev/null
953 if [ "$ret" != "0" ]; then
954 echo "got checkout failed unexpectedly" >&2
955 test_done "$testroot" "$ret"
959 # create a conflicting commit which renames alpha
960 (cd $testroot/repo && git checkout -q master)
961 (cd $testroot/repo && git mv alpha epsilon/alpha-moved)
962 git_commit $testroot/repo -m "moving alpha on master"
963 local master_commit=`git_show_head $testroot/repo`
965 # need an up-to-date work tree for 'got merge'
966 (cd $testroot/wt && got update > /dev/null)
968 if [ "$ret" != "0" ]; then
969 echo "got update failed unexpectedly" >&2
970 test_done "$testroot" "$ret"
974 (cd $testroot/wt && got merge newbranch \
975 > $testroot/stdout 2> $testroot/stderr)
977 if [ "$ret" == "0" ]; then
978 echo "got merge succeeded unexpectedly" >&2
979 test_done "$testroot" "1"
983 echo "! alpha" > $testroot/stdout.expected
984 echo "G gamma/delta" >> $testroot/stdout.expected
985 cmp -s $testroot/stdout.expected $testroot/stdout
987 if [ "$ret" != "0" ]; then
988 diff -u $testroot/stdout.expected $testroot/stdout
989 test_done "$testroot" "$ret"
993 echo -n "got: changes destined for missing files " \
994 > $testroot/stderr.expected
995 echo -n "were not yet merged and should be merged manually if " \
996 >> $testroot/stderr.expected
997 echo "required before the merge operation is continued" \
998 >> $testroot/stderr.expected
999 cmp -s $testroot/stderr.expected $testroot/stderr
1001 if [ "$ret" != "0" ]; then
1002 diff -u $testroot/stderr.expected $testroot/stderr
1003 test_done "$testroot" "$ret"
1007 (cd $testroot/wt && got status > $testroot/stdout)
1009 echo "M gamma/delta" > $testroot/stdout.expected
1010 cmp -s $testroot/stdout.expected $testroot/stdout
1012 if [ "$ret" != "0" ]; then
1013 diff -u $testroot/stdout.expected $testroot/stdout
1014 test_done "$testroot" "$ret"
1018 test_done "$testroot" "$ret"
1021 test_merge_no_op() {
1022 local testroot=`test_init merge_no_op`
1023 local commit0=`git_show_head $testroot/repo`
1024 local commit0_author_time=`git_show_author_time $testroot/repo`
1026 (cd $testroot/repo && git checkout -q -b newbranch)
1027 echo "modified alpha on branch" > $testroot/repo/alpha
1028 git_commit $testroot/repo -m "committing to alpha on newbranch"
1029 local branch_commitk=`git_show_branch_head $testroot/repo newbranch`
1031 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1033 if [ "$ret" != "0" ]; then
1034 echo "got checkout failed unexpectedly" >&2
1035 test_done "$testroot" "$ret"
1039 # create a conflicting commit
1040 (cd $testroot/repo && git checkout -q master)
1041 echo "modified alpha on master" > $testroot/repo/alpha
1042 git_commit $testroot/repo -m "committing to alpha on master"
1043 local master_commit=`git_show_head $testroot/repo`
1045 # need an up-to-date work tree for 'got merge'
1046 (cd $testroot/wt && got update > /dev/null)
1048 if [ "$ret" != "0" ]; then
1049 echo "got update failed unexpectedly" >&2
1050 test_done "$testroot" "$ret"
1054 (cd $testroot/wt && got merge newbranch \
1055 > $testroot/stdout 2> $testroot/stderr)
1057 if [ "$ret" == "0" ]; then
1058 echo "got merge succeeded unexpectedly" >&2
1059 test_done "$testroot" "1"
1063 echo "C alpha" >> $testroot/stdout.expected
1064 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1065 cmp -s $testroot/stdout.expected $testroot/stdout
1067 if [ "$ret" != "0" ]; then
1068 diff -u $testroot/stdout.expected $testroot/stdout
1069 test_done "$testroot" "$ret"
1073 echo "got: conflicts must be resolved before merging can continue" \
1074 > $testroot/stderr.expected
1075 cmp -s $testroot/stderr.expected $testroot/stderr
1077 if [ "$ret" != "0" ]; then
1078 diff -u $testroot/stderr.expected $testroot/stderr
1079 test_done "$testroot" "$ret"
1083 (cd $testroot/wt && got status > $testroot/stdout)
1085 echo "C alpha" > $testroot/stdout.expected
1086 cmp -s $testroot/stdout.expected $testroot/stdout
1088 if [ "$ret" != "0" ]; then
1089 diff -u $testroot/stdout.expected $testroot/stdout
1090 test_done "$testroot" "$ret"
1094 # resolve the conflict by reverting all changes; now it is no-op merge
1095 (cd $testroot/wt && got revert alpha > /dev/null)
1097 if [ "$ret" != "0" ]; then
1098 echo "got revert failed unexpectedly" >&2
1099 test_done "$testroot" "$ret"
1103 (cd $testroot/wt && got merge -c > $testroot/stdout \
1104 2> $testroot/stderr)
1106 if [ "$ret" == "0" ]; then
1107 echo "got merge succeeded unexpectedly" >&2
1108 test_done "$testroot" "$ret"
1112 echo -n "got: merge of refs/heads/newbranch cannot proceed: " \
1113 > $testroot/stderr.expected
1114 echo "no changes to commit" >> $testroot/stderr.expected
1115 cmp -s $testroot/stderr.expected $testroot/stderr
1117 if [ "$ret" != "0" ]; then
1118 diff -u $testroot/stderr.expected $testroot/stderr
1119 test_done "$testroot" "$ret"
1123 (cd $testroot/wt && got status > $testroot/stdout)
1125 echo -n "" > $testroot/stdout.expected
1126 cmp -s $testroot/stdout.expected $testroot/stdout
1128 if [ "$ret" != "0" ]; then
1129 diff -u $testroot/stdout.expected $testroot/stdout
1131 test_done "$testroot" "$ret"
1135 run_test test_merge_basic
1136 run_test test_merge_continue
1137 run_test test_merge_abort
1138 run_test test_merge_in_progress
1139 run_test test_merge_path_prefix
1140 run_test test_merge_missing_file
1141 run_test test_merge_no_op