3 # Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 local testroot
=`test_init merge_basic`
21 local commit0
=`git_show_head $testroot/repo`
22 local commit0_author_time
=`git_show_author_time $testroot/repo`
24 git
-C $testroot/repo checkout
-q -b newbranch
25 echo "modified delta on branch" > $testroot/repo
/gamma
/delta
26 git_commit
$testroot/repo
-m "committing to delta on newbranch"
27 local branch_commit0
=`git_show_branch_head $testroot/repo newbranch`
29 echo "modified alpha on branch" > $testroot/repo
/alpha
30 git_commit
$testroot/repo
-m "committing to alpha on newbranch"
31 local branch_commit1
=`git_show_branch_head $testroot/repo newbranch`
32 git
-C $testroot/repo
rm -q beta
33 git_commit
$testroot/repo
-m "removing beta on newbranch"
34 local branch_commit2
=`git_show_branch_head $testroot/repo newbranch`
35 echo "new file on branch" > $testroot/repo
/epsilon
/new
36 git
-C $testroot/repo add epsilon
/new
37 git_commit
$testroot/repo
-m "adding new file on newbranch"
38 local branch_commit3
=`git_show_branch_head $testroot/repo newbranch`
39 (cd $testroot/repo
&& ln -s alpha symlink
)
40 git
-C $testroot/repo add symlink
41 git_commit
$testroot/repo
-m "adding symlink on newbranch"
42 local branch_commit4
=`git_show_branch_head $testroot/repo newbranch`
43 (cd $testroot/repo
&& ln -sf .got
/bar dotgotbar.link
)
44 git
-C $testroot/repo add dotgotbar.link
45 git_commit
$testroot/repo
-m "adding a bad symlink on newbranch"
46 local branch_commit5
=`git_show_branch_head $testroot/repo newbranch`
48 got checkout
-b master
$testroot/repo
$testroot/wt
> /dev
/null
50 if [ $ret -ne 0 ]; then
51 echo "got checkout failed unexpectedly" >&2
52 test_done
"$testroot" "$ret"
56 # create a divergent commit
57 git
-C $testroot/repo checkout
-q master
58 echo "modified zeta on master" > $testroot/repo
/epsilon
/zeta
59 git_commit
$testroot/repo
-m "committing to zeta on master"
60 local master_commit
=`git_show_head $testroot/repo`
62 # need an up-to-date work tree for 'got merge'
63 (cd $testroot/wt
&& got merge newbranch \
64 > $testroot/stdout
2> $testroot/stderr
)
66 if [ $ret -eq 0 ]; then
67 echo "got merge succeeded unexpectedly" >&2
68 test_done
"$testroot" "1"
71 echo -n "got: work tree must be updated before it can be used " \
72 > $testroot/stderr.expected
73 echo "to merge a branch" >> $testroot/stderr.expected
74 cmp -s $testroot/stderr.expected
$testroot/stderr
76 if [ $ret -ne 0 ]; then
77 diff -u $testroot/stderr.expected
$testroot/stderr
78 test_done
"$testroot" "$ret"
82 (cd $testroot/wt
&& got update
> /dev
/null
)
84 if [ $ret -ne 0 ]; then
85 echo "got update failed unexpectedly" >&2
86 test_done
"$testroot" "$ret"
90 # must not use a mixed-commit work tree with 'got merge'
91 (cd $testroot/wt
&& got update
-c $commit0 alpha
> /dev
/null
)
93 if [ $ret -ne 0 ]; then
94 echo "got update failed unexpectedly" >&2
95 test_done
"$testroot" "$ret"
98 (cd $testroot/wt
&& got merge newbranch \
99 > $testroot/stdout
2> $testroot/stderr
)
101 if [ $ret -eq 0 ]; then
102 echo "got merge succeeded unexpectedly" >&2
103 test_done
"$testroot" "1"
106 echo -n "got: work tree contains files from multiple base commits; " \
107 > $testroot/stderr.expected
108 echo "the entire work tree must be updated first" \
109 >> $testroot/stderr.expected
110 cmp -s $testroot/stderr.expected
$testroot/stderr
112 if [ $ret -ne 0 ]; then
113 diff -u $testroot/stderr.expected
$testroot/stderr
114 test_done
"$testroot" "$ret"
118 (cd $testroot/wt
&& got update
> /dev
/null
)
120 if [ $ret -ne 0 ]; then
121 echo "got update failed unexpectedly" >&2
122 test_done
"$testroot" "$ret"
126 # must not have staged files with 'got merge'
127 echo "modified file alpha" > $testroot/wt
/alpha
128 (cd $testroot/wt
&& got stage alpha
> /dev
/null
)
130 if [ $ret -ne 0 ]; then
131 echo "got stage failed unexpectedly" >&2
132 test_done
"$testroot" "$ret"
135 (cd $testroot/wt
&& got merge newbranch \
136 > $testroot/stdout
2> $testroot/stderr
)
138 if [ $ret -eq 0 ]; then
139 echo "got merge succeeded unexpectedly" >&2
140 test_done
"$testroot" "1"
143 echo "got: alpha: file is staged" > $testroot/stderr.expected
144 cmp -s $testroot/stderr.expected
$testroot/stderr
146 if [ $ret -ne 0 ]; then
147 diff -u $testroot/stderr.expected
$testroot/stderr
148 test_done
"$testroot" "$ret"
151 (cd $testroot/wt
&& got unstage alpha
> /dev
/null
)
153 if [ $ret -ne 0 ]; then
154 echo "got unstage failed unexpectedly" >&2
155 test_done
"$testroot" "$ret"
159 # must not have local changes with 'got merge'
160 (cd $testroot/wt
&& got merge newbranch \
161 > $testroot/stdout
2> $testroot/stderr
)
163 if [ $ret -eq 0 ]; then
164 echo "got merge succeeded unexpectedly" >&2
165 test_done
"$testroot" "1"
168 echo -n "got: work tree contains local changes; " \
169 > $testroot/stderr.expected
170 echo "these changes must be committed or reverted first" \
171 >> $testroot/stderr.expected
172 cmp -s $testroot/stderr.expected
$testroot/stderr
174 if [ $ret -ne 0 ]; then
175 diff -u $testroot/stderr.expected
$testroot/stderr
176 test_done
"$testroot" "$ret"
180 (cd $testroot/wt
&& got revert alpha
> /dev
/null
)
182 if [ $ret -ne 0 ]; then
183 echo "got revert failed unexpectedly" >&2
184 test_done
"$testroot" "$ret"
188 (cd $testroot/wt
&& got merge newbranch
> $testroot/stdout
)
190 if [ $ret -ne 0 ]; then
191 echo "got merge failed unexpectedly" >&2
192 test_done
"$testroot" "$ret"
196 local merge_commit
=`git_show_head $testroot/repo`
198 echo "G alpha" >> $testroot/stdout.expected
199 echo "D beta" >> $testroot/stdout.expected
200 echo "A dotgotbar.link" >> $testroot/stdout.expected
201 echo "A epsilon/new" >> $testroot/stdout.expected
202 echo "G gamma/delta" >> $testroot/stdout.expected
203 echo "A symlink" >> $testroot/stdout.expected
204 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
205 >> $testroot/stdout.expected
206 echo $merge_commit >> $testroot/stdout.expected
208 cmp -s $testroot/stdout.expected
$testroot/stdout
210 if [ $ret -ne 0 ]; then
211 diff -u $testroot/stdout.expected
$testroot/stdout
212 test_done
"$testroot" "$ret"
216 echo "modified delta on branch" > $testroot/content.expected
217 cat $testroot/wt
/gamma
/delta
> $testroot/content
218 cmp -s $testroot/content.expected
$testroot/content
220 if [ $ret -ne 0 ]; then
221 diff -u $testroot/content.expected
$testroot/content
222 test_done
"$testroot" "$ret"
226 echo "modified alpha on branch" > $testroot/content.expected
227 cat $testroot/wt
/alpha
> $testroot/content
228 cmp -s $testroot/content.expected
$testroot/content
230 if [ $ret -ne 0 ]; then
231 diff -u $testroot/content.expected
$testroot/content
232 test_done
"$testroot" "$ret"
236 if [ -e $testroot/wt
/beta
]; then
237 echo "removed file beta still exists on disk" >&2
238 test_done
"$testroot" "1"
242 echo "new file on branch" > $testroot/content.expected
243 cat $testroot/wt
/epsilon
/new
> $testroot/content
244 cmp -s $testroot/content.expected
$testroot/content
246 if [ $ret -ne 0 ]; then
247 diff -u $testroot/content.expected
$testroot/content
248 test_done
"$testroot" "$ret"
252 if [ ! -h $testroot/wt
/dotgotbar.link
]; then
253 echo "dotgotbar.link is not a symlink"
254 test_done
"$testroot" "1"
258 readlink
$testroot/wt
/symlink
> $testroot/stdout
259 echo "alpha" > $testroot/stdout.expected
260 cmp -s $testroot/stdout.expected
$testroot/stdout
262 if [ $ret -ne 0 ]; then
263 diff -u $testroot/stdout.expected
$testroot/stdout
264 test_done
"$testroot" "$ret"
268 (cd $testroot/wt
&& got status
> $testroot/stdout
)
270 echo -n > $testroot/stdout.expected
271 cmp -s $testroot/stdout.expected
$testroot/stdout
273 if [ $ret -ne 0 ]; then
274 diff -u $testroot/stdout.expected
$testroot/stdout
275 test_done
"$testroot" "$ret"
279 (cd $testroot/wt
&& got log
-l3 |
grep ^commit
> $testroot/stdout
)
280 echo "commit $merge_commit (master)" > $testroot/stdout.expected
281 echo "commit $master_commit" >> $testroot/stdout.expected
282 echo "commit $commit0" >> $testroot/stdout.expected
283 cmp -s $testroot/stdout.expected
$testroot/stdout
285 if [ $ret -ne 0 ]; then
286 diff -u $testroot/stdout.expected
$testroot/stdout
287 test_done
"$testroot" "$ret"
291 (cd $testroot/wt
&& got update
> $testroot/stdout
)
293 echo 'U dotgotbar.link' > $testroot/stdout.expected
294 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
295 git_show_head
$testroot/repo
>> $testroot/stdout.expected
296 echo >> $testroot/stdout.expected
297 cmp -s $testroot/stdout.expected
$testroot/stdout
299 if [ $ret -ne 0 ]; then
300 diff -u $testroot/stdout.expected
$testroot/stdout
301 test_done
"$testroot" "$ret"
305 # update has changed the bad symlink into a regular file
306 if [ -h $testroot/wt
/dotgotbar.link
]; then
307 echo "dotgotbar.link is a symlink"
308 test_done
"$testroot" "1"
312 # We should have created a merge commit with two parents.
313 (cd $testroot/wt
&& got log
-l1 |
grep ^parent
> $testroot/stdout
)
314 echo "parent 1: $master_commit" > $testroot/stdout.expected
315 echo "parent 2: $branch_commit5" >> $testroot/stdout.expected
316 cmp -s $testroot/stdout.expected
$testroot/stdout
318 if [ $ret -ne 0 ]; then
319 diff -u $testroot/stdout.expected
$testroot/stdout
320 test_done
"$testroot" "$ret"
324 got tree
-r $testroot/repo
-c $merge_commit -R > $testroot/stdout
326 if [ $ret -ne 0 ]; then
327 echo "got tree failed unexpectedly" >&2
328 test_done
"$testroot" "$ret"
332 # bad symlink dotgotbar.link appears as a symlink in the merge commit:
333 cat > $testroot/stdout.expected
<<EOF
335 dotgotbar.link@ -> .got/bar
343 cmp -s $testroot/stdout.expected
$testroot/stdout
345 if [ $ret -ne 0 ]; then
346 diff -u $testroot/stdout.expected
$testroot/stdout
348 test_done
"$testroot" "$ret"
351 test_merge_forward
() {
352 local testroot
=`test_init merge_forward`
353 local commit0
=`git_show_head $testroot/repo`
355 # Create a commit before branching, which will be used to help test
356 # preconditions for "got merge".
357 echo "modified alpha" > $testroot/repo
/alpha
358 git_commit
$testroot/repo
-m "common commit"
359 local commit1
=`git_show_head $testroot/repo`
361 git
-C $testroot/repo checkout
-q -b newbranch
362 echo "modified beta on branch" > $testroot/repo
/beta
363 git_commit
$testroot/repo
-m "committing to beta on newbranch"
364 local commit2
=`git_show_head $testroot/repo`
366 got checkout
-b master
$testroot/repo
$testroot/wt
> /dev
/null
368 if [ $ret -ne 0 ]; then
369 echo "got checkout failed unexpectedly" >&2
370 test_done
"$testroot" "$ret"
374 # must not use a mixed-commit work tree with 'got merge'
375 (cd $testroot/wt
&& got update
-c $commit0 alpha
> /dev
/null
)
377 if [ $ret -ne 0 ]; then
378 echo "got update failed unexpectedly" >&2
379 test_done
"$testroot" "$ret"
382 (cd $testroot/wt
&& got merge newbranch \
383 > $testroot/stdout
2> $testroot/stderr
)
385 if [ $ret -eq 0 ]; then
386 echo "got merge succeeded unexpectedly" >&2
387 test_done
"$testroot" "$ret"
390 echo -n "got: work tree contains files from multiple base commits; " \
391 > $testroot/stderr.expected
392 echo "the entire work tree must be updated first" \
393 >> $testroot/stderr.expected
394 cmp -s $testroot/stderr.expected
$testroot/stderr
396 if [ $ret -ne 0 ]; then
397 diff -u $testroot/stderr.expected
$testroot/stderr
398 test_done
"$testroot" "$ret"
402 (cd $testroot/wt
&& got update
> /dev
/null
)
404 if [ $ret -ne 0 ]; then
405 echo "got update failed unexpectedly" >&2
406 test_done
"$testroot" "$ret"
410 # 'got merge -n' refuses to fast-forward
411 (cd $testroot/wt
&& got merge
-n newbranch \
412 > $testroot/stdout
2> $testroot/stderr
)
414 if [ $ret -eq 0 ]; then
415 echo "got merge succeeded unexpectedly" >&2
416 test_done
"$testroot" "1"
420 echo -n "got: there are no changes to merge since " \
421 > $testroot/stderr.expected
422 echo -n "refs/heads/newbranch is already based on " \
423 >> $testroot/stderr.expected
424 echo -n "refs/heads/master; merge cannot be interrupted " \
425 >> $testroot/stderr.expected
426 echo "for amending; -n: option cannot be used" \
427 >> $testroot/stderr.expected
429 cmp -s $testroot/stderr.expected
$testroot/stderr
431 if [ $ret -ne 0 ]; then
432 diff -u $testroot/stderr.expected
$testroot/stderr
433 test_done
"$testroot" "$ret"
437 (cd $testroot/wt
&& got merge newbranch \
438 > $testroot/stdout
2> $testroot/stderr
)
440 if [ $ret -ne 0 ]; then
441 echo "got merge failed unexpectedly" >&2
442 test_done
"$testroot" "$ret"
446 echo "Forwarding refs/heads/master to refs/heads/newbranch" \
447 > $testroot/stdout.expected
448 echo "U beta" >> $testroot/stdout.expected
449 echo "Updated to commit $commit2" \
450 >> $testroot/stdout.expected
451 cmp -s $testroot/stdout.expected
$testroot/stdout
453 if [ $ret -ne 0 ]; then
454 diff -u $testroot/stdout.expected
$testroot/stdout
455 test_done
"$testroot" "$ret"
459 (cd $testroot/wt
&& got log |
grep ^commit
> $testroot/stdout
)
460 echo -n "commit $commit2 " > $testroot/stdout.expected
461 echo "(master, newbranch)" >> $testroot/stdout.expected
462 echo "commit $commit1" >> $testroot/stdout.expected
463 echo "commit $commit0" >> $testroot/stdout.expected
464 cmp -s $testroot/stdout.expected
$testroot/stdout
466 if [ $ret -ne 0 ]; then
467 diff -u $testroot/stdout.expected
$testroot/stdout
468 test_done
"$testroot" "$ret"
471 test_done
"$testroot" "$ret"
474 test_merge_forward_commit
() {
475 local testroot
=`test_init merge_forward_commit`
476 local commit0
=`git_show_head $testroot/repo`
478 git
-C $testroot/repo checkout
-q -b newbranch
479 echo "modified alpha on branch" > $testroot/repo
/alpha
480 git_commit
$testroot/repo
-m "committing to alpha on newbranch"
481 local commit1
=`git_show_head $testroot/repo`
483 got checkout
-b master
$testroot/repo
$testroot/wt
> /dev
/null
485 if [ $ret -ne 0 ]; then
486 echo "got checkout failed unexpectedly" >&2
487 test_done
"$testroot" "$ret"
491 (cd $testroot/wt
&& got merge
-M newbranch
> $testroot/stdout
)
493 if [ $ret -ne 0 ]; then
494 echo "got merge failed unexpectedly" >&2
495 test_done
"$testroot" "$ret"
499 local merge_commit
=`git_show_branch_head $testroot/repo master`
501 echo "G alpha" >> $testroot/stdout.expected
502 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
503 >> $testroot/stdout.expected
504 echo $merge_commit >> $testroot/stdout.expected
506 cmp -s $testroot/stdout.expected
$testroot/stdout
508 if [ $ret -ne 0 ]; then
509 diff -u $testroot/stdout.expected
$testroot/stdout
510 test_done
"$testroot" "$ret"
514 # We should have created a merge commit with two parents.
515 (cd $testroot/wt
&& got log
-l1 |
grep ^parent
> $testroot/stdout
)
516 echo "parent 1: $commit0" > $testroot/stdout.expected
517 echo "parent 2: $commit1" >> $testroot/stdout.expected
518 cmp -s $testroot/stdout.expected
$testroot/stdout
520 if [ $ret -ne 0 ]; then
521 diff -u $testroot/stdout.expected
$testroot/stdout
522 test_done
"$testroot" "$ret"
526 test_done
"$testroot" "$ret"
529 test_merge_forward_interrupt
() {
530 # Test -M and -n options together.
531 local testroot
=`test_init merge_forward_commit`
532 local commit0
=`git_show_head $testroot/repo`
534 git
-C $testroot/repo checkout
-q -b newbranch
535 echo "modified alpha on branch" > $testroot/repo
/alpha
536 git_commit
$testroot/repo
-m "committing to alpha on newbranch"
537 local commit1
=`git_show_head $testroot/repo`
539 got checkout
-b master
$testroot/repo
$testroot/wt
> /dev
/null
541 if [ $ret -ne 0 ]; then
542 echo "got checkout failed unexpectedly" >&2
543 test_done
"$testroot" "$ret"
547 (cd $testroot/wt
&& got merge
-M -n newbranch
> $testroot/stdout
)
549 if [ $ret -ne 0 ]; then
550 echo "got merge failed unexpectedly" >&2
551 test_done
"$testroot" "$ret"
555 echo "G alpha" > $testroot/stdout.expected
556 echo "Merge of refs/heads/newbranch interrupted on request" \
557 >> $testroot/stdout.expected
558 cmp -s $testroot/stdout.expected
$testroot/stdout
560 if [ $ret -ne 0 ]; then
561 diff -u $testroot/stdout.expected
$testroot/stdout
562 test_done
"$testroot" "$ret"
566 # Continue the merge.
567 (cd $testroot/wt
&& got merge
-c > $testroot/stdout
)
569 if [ $ret -ne 0 ]; then
570 echo "got merge failed unexpectedly" >&2
571 test_done
"$testroot" "$ret"
575 local merge_commit
=`git_show_branch_head $testroot/repo master`
577 echo "M alpha" > $testroot/stdout.expected
578 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
579 >> $testroot/stdout.expected
580 echo $merge_commit >> $testroot/stdout.expected
582 cmp -s $testroot/stdout.expected
$testroot/stdout
584 if [ $ret -ne 0 ]; then
585 diff -u $testroot/stdout.expected
$testroot/stdout
586 test_done
"$testroot" "$ret"
590 # We should have created a merge commit with two parents.
591 (cd $testroot/wt
&& got log
-l1 |
grep ^parent
> $testroot/stdout
)
592 echo "parent 1: $commit0" > $testroot/stdout.expected
593 echo "parent 2: $commit1" >> $testroot/stdout.expected
594 cmp -s $testroot/stdout.expected
$testroot/stdout
596 if [ $ret -ne 0 ]; then
597 diff -u $testroot/stdout.expected
$testroot/stdout
599 test_done
"$testroot" "$ret"
602 test_merge_backward
() {
603 local testroot
=`test_init merge_backward`
604 local commit0
=`git_show_head $testroot/repo`
606 git
-C $testroot/repo checkout
-q -b newbranch
607 git
-C $testroot/repo checkout
-q master
608 echo "modified alpha on master" > $testroot/repo
/alpha
609 git_commit
$testroot/repo
-m "committing to alpha on master"
611 got checkout
-b master
$testroot/repo
$testroot/wt
> /dev
/null
613 if [ $ret -ne 0 ]; then
614 echo "got checkout failed unexpectedly" >&2
615 test_done
"$testroot" "$ret"
619 (cd $testroot/wt
&& got merge newbranch \
620 > $testroot/stdout
2> $testroot/stderr
)
622 if [ $ret -ne 0 ]; then
623 echo "got merge failed unexpectedly" >&2
624 test_done
"$testroot" "$ret"
627 echo "Already up-to-date" > $testroot/stdout.expected
628 cmp -s $testroot/stdout.expected
$testroot/stdout
630 if [ $ret -ne 0 ]; then
631 diff -u $testroot/stdout.expected
$testroot/stdout
632 test_done
"$testroot" "$ret"
635 test_done
"$testroot" "$ret"
638 test_merge_continue
() {
639 local testroot
=`test_init merge_continue`
640 local commit0
=`git_show_head $testroot/repo`
641 local commit0_author_time
=`git_show_author_time $testroot/repo`
643 git
-C $testroot/repo checkout
-q -b newbranch
644 echo "modified delta on branch" > $testroot/repo
/gamma
/delta
645 git_commit
$testroot/repo
-m "committing to delta on newbranch"
646 local branch_commit0
=`git_show_branch_head $testroot/repo newbranch`
648 echo "modified alpha on branch" > $testroot/repo
/alpha
649 git_commit
$testroot/repo
-m "committing to alpha on newbranch"
650 local branch_commit1
=`git_show_branch_head $testroot/repo newbranch`
651 git
-C $testroot/repo
rm -q beta
652 git_commit
$testroot/repo
-m "removing beta on newbranch"
653 local branch_commit2
=`git_show_branch_head $testroot/repo newbranch`
654 echo "new file on branch" > $testroot/repo
/epsilon
/new
655 git
-C $testroot/repo add epsilon
/new
656 git_commit
$testroot/repo
-m "adding new file on newbranch"
657 local branch_commit3
=`git_show_branch_head $testroot/repo newbranch`
659 got checkout
-b master
$testroot/repo
$testroot/wt
> /dev
/null
661 if [ $ret -ne 0 ]; then
662 echo "got checkout failed unexpectedly" >&2
663 test_done
"$testroot" "$ret"
667 # create a conflicting commit
668 git
-C $testroot/repo checkout
-q master
669 echo "modified alpha on master" > $testroot/repo
/alpha
670 git_commit
$testroot/repo
-m "committing to alpha on master"
671 local master_commit
=`git_show_head $testroot/repo`
673 # need an up-to-date work tree for 'got merge'
674 (cd $testroot/wt
&& got update
> /dev
/null
)
676 if [ $ret -ne 0 ]; then
677 echo "got update failed unexpectedly" >&2
678 test_done
"$testroot" "$ret"
682 (cd $testroot/wt
&& got merge newbranch \
683 > $testroot/stdout
2> $testroot/stderr
)
685 if [ $ret -eq 0 ]; then
686 echo "got merge succeeded unexpectedly" >&2
687 test_done
"$testroot" "1"
691 echo "C alpha" >> $testroot/stdout.expected
692 echo "D beta" >> $testroot/stdout.expected
693 echo "A epsilon/new" >> $testroot/stdout.expected
694 echo "G gamma/delta" >> $testroot/stdout.expected
695 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
696 cmp -s $testroot/stdout.expected
$testroot/stdout
698 if [ $ret -ne 0 ]; then
699 diff -u $testroot/stdout.expected
$testroot/stdout
700 test_done
"$testroot" "$ret"
704 echo "got: conflicts must be resolved before merging can continue" \
705 > $testroot/stderr.expected
706 cmp -s $testroot/stderr.expected
$testroot/stderr
708 if [ $ret -ne 0 ]; then
709 diff -u $testroot/stderr.expected
$testroot/stderr
710 test_done
"$testroot" "$ret"
714 (cd $testroot/wt
&& got status
> $testroot/stdout
)
716 cat > $testroot/stdout.expected
<<EOF
721 Work tree is merging refs/heads/newbranch into refs/heads/master
723 cmp -s $testroot/stdout.expected
$testroot/stdout
725 if [ $ret -ne 0 ]; then
726 diff -u $testroot/stdout.expected
$testroot/stdout
727 test_done
"$testroot" "$ret"
731 echo '<<<<<<<' > $testroot/content.expected
732 echo "modified alpha on master" >> $testroot/content.expected
733 echo "||||||| 3-way merge base: commit $commit0" \
734 >> $testroot/content.expected
735 echo "alpha" >> $testroot/content.expected
736 echo "=======" >> $testroot/content.expected
737 echo "modified alpha on branch" >> $testroot/content.expected
738 echo ">>>>>>> merged change: commit $branch_commit3" \
739 >> $testroot/content.expected
740 cat $testroot/wt
/alpha
> $testroot/content
741 cmp -s $testroot/content.expected
$testroot/content
743 if [ $ret -ne 0 ]; then
744 diff -u $testroot/content.expected
$testroot/content
745 test_done
"$testroot" "$ret"
749 # resolve the conflict
750 echo "modified alpha by both branches" > $testroot/wt
/alpha
752 (cd $testroot/wt
&& got merge
-c > $testroot/stdout
)
754 if [ $ret -ne 0 ]; then
755 echo "got merge failed unexpectedly" >&2
756 test_done
"$testroot" "$ret"
760 local merge_commit
=`git_show_head $testroot/repo`
762 echo "M alpha" > $testroot/stdout.expected
763 echo "D beta" >> $testroot/stdout.expected
764 echo "A epsilon/new" >> $testroot/stdout.expected
765 echo "M gamma/delta" >> $testroot/stdout.expected
766 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
767 >> $testroot/stdout.expected
768 echo $merge_commit >> $testroot/stdout.expected
770 cmp -s $testroot/stdout.expected
$testroot/stdout
772 if [ $ret -ne 0 ]; then
773 diff -u $testroot/stdout.expected
$testroot/stdout
774 test_done
"$testroot" "$ret"
778 echo "modified delta on branch" > $testroot/content.expected
779 cat $testroot/wt
/gamma
/delta
> $testroot/content
780 cmp -s $testroot/content.expected
$testroot/content
782 if [ $ret -ne 0 ]; then
783 diff -u $testroot/content.expected
$testroot/content
784 test_done
"$testroot" "$ret"
788 echo "modified alpha by both branches" > $testroot/content.expected
789 cat $testroot/wt
/alpha
> $testroot/content
790 cmp -s $testroot/content.expected
$testroot/content
792 if [ $ret -ne 0 ]; then
793 diff -u $testroot/content.expected
$testroot/content
794 test_done
"$testroot" "$ret"
798 if [ -e $testroot/wt
/beta
]; then
799 echo "removed file beta still exists on disk" >&2
800 test_done
"$testroot" "1"
804 echo "new file on branch" > $testroot/content.expected
805 cat $testroot/wt
/epsilon
/new
> $testroot/content
806 cmp -s $testroot/content.expected
$testroot/content
808 if [ $ret -ne 0 ]; then
809 diff -u $testroot/content.expected
$testroot/content
810 test_done
"$testroot" "$ret"
814 (cd $testroot/wt
&& got status
> $testroot/stdout
)
816 echo -n > $testroot/stdout.expected
817 cmp -s $testroot/stdout.expected
$testroot/stdout
819 if [ $ret -ne 0 ]; then
820 diff -u $testroot/stdout.expected
$testroot/stdout
821 test_done
"$testroot" "$ret"
825 (cd $testroot/wt
&& got log
-l3 |
grep ^commit
> $testroot/stdout
)
826 echo "commit $merge_commit (master)" > $testroot/stdout.expected
827 echo "commit $master_commit" >> $testroot/stdout.expected
828 echo "commit $commit0" >> $testroot/stdout.expected
829 cmp -s $testroot/stdout.expected
$testroot/stdout
831 if [ $ret -ne 0 ]; then
832 diff -u $testroot/stdout.expected
$testroot/stdout
833 test_done
"$testroot" "$ret"
837 (cd $testroot/wt
&& got update
> $testroot/stdout
)
839 echo 'Already up-to-date' > $testroot/stdout.expected
840 cmp -s $testroot/stdout.expected
$testroot/stdout
842 if [ $ret -ne 0 ]; then
843 diff -u $testroot/stdout.expected
$testroot/stdout
844 test_done
"$testroot" "$ret"
848 # We should have created a merge commit with two parents.
849 (cd $testroot/wt
&& got log
-l1 |
grep ^parent
> $testroot/stdout
)
850 echo "parent 1: $master_commit" > $testroot/stdout.expected
851 echo "parent 2: $branch_commit3" >> $testroot/stdout.expected
852 cmp -s $testroot/stdout.expected
$testroot/stdout
854 if [ $ret -ne 0 ]; then
855 diff -u $testroot/stdout.expected
$testroot/stdout
857 test_done
"$testroot" "$ret"
860 test_merge_continue_new_commit
() {
861 # "got merge -c" should refuse to run if the current branch tip has
862 # changed since the merge was started, to avoid clobbering the changes.
863 local testroot
=`test_init merge_continue_new_commit`
865 git
-C $testroot/repo checkout
-q -b newbranch
866 echo "modified delta on branch" > $testroot/repo
/gamma
/delta
867 git_commit
$testroot/repo
-m "committing to delta on newbranch"
869 git
-C $testroot/repo checkout
-q master
870 echo "modified alpha on master" > $testroot/repo
/alpha
871 git_commit
$testroot/repo
-m "committing to alpha on master"
873 got checkout
-b master
$testroot/repo
$testroot/wt
> /dev
/null
875 if [ $ret -ne 0 ]; then
876 echo "got checkout failed unexpectedly" >&2
877 test_done
"$testroot" "$ret"
881 (cd $testroot/wt
&& got merge
-n newbranch
>/dev
/null
)
883 if [ $ret -ne 0 ]; then
884 echo "got merge failed unexpectedly" >&2
885 test_done
"$testroot" "$ret"
889 echo "modified alpha again on master" > $testroot/repo
/alpha
890 git_commit
$testroot/repo
-m "committing to alpha on master again"
892 (cd $testroot/wt
&& got merge
-c > $testroot/stdout
2> $testroot/stderr
)
894 if [ $ret -eq 0 ]; then
895 echo "got merge succeeded unexpectedly" >&2
896 test_done
"$testroot" "1"
900 echo -n > $testroot/stdout.expected
901 cmp -s $testroot/stdout.expected
$testroot/stdout
903 if [ $ret -ne 0 ]; then
904 diff -u $testroot/stdout.expected
$testroot/stdout
905 test_done
"$testroot" "$ret"
909 echo -n "got: merging cannot proceed because the work tree is no " \
910 > $testroot/stderr.expected
911 echo "longer up-to-date; merge must be aborted and retried" \
912 >> $testroot/stderr.expected
913 cmp -s $testroot/stderr.expected
$testroot/stderr
915 if [ $ret -ne 0 ]; then
916 diff -u $testroot/stderr.expected
$testroot/stderr
918 test_done
"$testroot" "$ret"
922 local testroot
=`test_init merge_abort`
923 local commit0
=`git_show_head $testroot/repo`
924 local commit0_author_time
=`git_show_author_time $testroot/repo`
926 git
-C $testroot/repo checkout
-q -b newbranch
927 echo "modified delta on branch" > $testroot/repo
/gamma
/delta
928 git_commit
$testroot/repo
-m "committing to delta on newbranch"
929 local branch_commit0
=`git_show_branch_head $testroot/repo newbranch`
931 echo "modified alpha on branch" > $testroot/repo
/alpha
932 git_commit
$testroot/repo
-m "committing to alpha on newbranch"
933 local branch_commit1
=`git_show_branch_head $testroot/repo newbranch`
934 git
-C $testroot/repo
rm -q beta
935 git_commit
$testroot/repo
-m "removing beta on newbranch"
936 local branch_commit2
=`git_show_branch_head $testroot/repo newbranch`
937 echo "new file on branch" > $testroot/repo
/epsilon
/new
938 git
-C $testroot/repo add epsilon
/new
939 git_commit
$testroot/repo
-m "adding new file on newbranch"
940 local branch_commit3
=`git_show_branch_head $testroot/repo newbranch`
941 (cd $testroot/repo
&& ln -s alpha symlink
)
942 git
-C $testroot/repo add symlink
943 git_commit
$testroot/repo
-m "adding symlink on newbranch"
944 local branch_commit4
=`git_show_branch_head $testroot/repo newbranch`
946 got checkout
-b master
$testroot/repo
$testroot/wt
> /dev
/null
948 if [ $ret -ne 0 ]; then
949 echo "got checkout failed unexpectedly" >&2
950 test_done
"$testroot" "$ret"
954 # unrelated unversioned file in work tree
955 touch $testroot/wt
/unversioned-file
957 # create a conflicting commit
958 git
-C $testroot/repo checkout
-q master
959 echo "modified alpha on master" > $testroot/repo
/alpha
960 git_commit
$testroot/repo
-m "committing to alpha on master"
961 local master_commit
=`git_show_head $testroot/repo`
963 # need an up-to-date work tree for 'got merge'
964 (cd $testroot/wt
&& got update
> /dev
/null
)
966 if [ $ret -ne 0 ]; then
967 echo "got update failed unexpectedly" >&2
968 test_done
"$testroot" "$ret"
972 (cd $testroot/wt
&& got merge newbranch \
973 > $testroot/stdout
2> $testroot/stderr
)
975 if [ $ret -eq 0 ]; then
976 echo "got merge succeeded unexpectedly" >&2
977 test_done
"$testroot" "1"
981 echo "C alpha" >> $testroot/stdout.expected
982 echo "D beta" >> $testroot/stdout.expected
983 echo "A epsilon/new" >> $testroot/stdout.expected
984 echo "G gamma/delta" >> $testroot/stdout.expected
985 echo "A symlink" >> $testroot/stdout.expected
986 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
987 cmp -s $testroot/stdout.expected
$testroot/stdout
989 if [ $ret -ne 0 ]; then
990 diff -u $testroot/stdout.expected
$testroot/stdout
991 test_done
"$testroot" "$ret"
995 echo "got: conflicts must be resolved before merging can continue" \
996 > $testroot/stderr.expected
997 cmp -s $testroot/stderr.expected
$testroot/stderr
999 if [ $ret -ne 0 ]; then
1000 diff -u $testroot/stderr.expected
$testroot/stderr
1001 test_done
"$testroot" "$ret"
1005 # unrelated added file added during conflict resolution
1006 touch $testroot/wt
/added-file
1007 (cd $testroot/wt
&& got add added-file
> /dev
/null
)
1009 (cd $testroot/wt
&& got status
> $testroot/stdout
)
1011 cat > $testroot/stdout.expected
<<EOF
1019 Work tree is merging refs/heads/newbranch into refs/heads/master
1021 cmp -s $testroot/stdout.expected
$testroot/stdout
1023 if [ $ret -ne 0 ]; then
1024 diff -u $testroot/stdout.expected
$testroot/stdout
1025 test_done
"$testroot" "$ret"
1029 (cd $testroot/wt
&& got merge
-a > $testroot/stdout
)
1031 if [ $ret -ne 0 ]; then
1032 echo "got merge failed unexpectedly" >&2
1033 test_done
"$testroot" "$ret"
1037 echo "R added-file" > $testroot/stdout.expected
1038 echo "R alpha" >> $testroot/stdout.expected
1039 echo "R beta" >> $testroot/stdout.expected
1040 echo "R epsilon/new" >> $testroot/stdout.expected
1041 echo "R gamma/delta" >> $testroot/stdout.expected
1042 echo "R symlink" >> $testroot/stdout.expected
1043 echo "G added-file" >> $testroot/stdout.expected
1044 echo "Merge of refs/heads/newbranch aborted" \
1045 >> $testroot/stdout.expected
1047 cmp -s $testroot/stdout.expected
$testroot/stdout
1049 if [ $ret -ne 0 ]; then
1050 diff -u $testroot/stdout.expected
$testroot/stdout
1051 test_done
"$testroot" "$ret"
1055 echo "delta" > $testroot/content.expected
1056 cat $testroot/wt
/gamma
/delta
> $testroot/content
1057 cmp -s $testroot/content.expected
$testroot/content
1059 if [ $ret -ne 0 ]; then
1060 diff -u $testroot/content.expected
$testroot/content
1061 test_done
"$testroot" "$ret"
1065 echo "modified alpha on master" > $testroot/content.expected
1066 cat $testroot/wt
/alpha
> $testroot/content
1067 cmp -s $testroot/content.expected
$testroot/content
1069 if [ $ret -ne 0 ]; then
1070 diff -u $testroot/content.expected
$testroot/content
1071 test_done
"$testroot" "$ret"
1075 echo "beta" > $testroot/content.expected
1076 cat $testroot/wt
/beta
> $testroot/content
1077 cmp -s $testroot/content.expected
$testroot/content
1079 if [ $ret -ne 0 ]; then
1080 diff -u $testroot/content.expected
$testroot/content
1081 test_done
"$testroot" "$ret"
1085 if [ -e $testroot/wt
/epsilon
/new
]; then
1086 echo "reverted file epsilon/new still exists on disk" >&2
1087 test_done
"$testroot" "1"
1091 if [ -e $testroot/wt
/symlink
]; then
1092 echo "reverted symlink still exists on disk" >&2
1093 test_done
"$testroot" "1"
1097 (cd $testroot/wt
&& got status
> $testroot/stdout
)
1099 echo "? added-file" > $testroot/stdout.expected
1100 echo "? unversioned-file" >> $testroot/stdout.expected
1101 cmp -s $testroot/stdout.expected
$testroot/stdout
1103 if [ $ret -ne 0 ]; then
1104 diff -u $testroot/stdout.expected
$testroot/stdout
1105 test_done
"$testroot" "$ret"
1109 (cd $testroot/wt
&& got log
-l3 |
grep ^commit
> $testroot/stdout
)
1110 echo "commit $master_commit (master)" > $testroot/stdout.expected
1111 echo "commit $commit0" >> $testroot/stdout.expected
1112 cmp -s $testroot/stdout.expected
$testroot/stdout
1114 if [ $ret -ne 0 ]; then
1115 diff -u $testroot/stdout.expected
$testroot/stdout
1116 test_done
"$testroot" "$ret"
1120 (cd $testroot/wt
&& got update
> $testroot/stdout
)
1122 echo 'Already up-to-date' > $testroot/stdout.expected
1123 cmp -s $testroot/stdout.expected
$testroot/stdout
1125 if [ $ret -ne 0 ]; then
1126 diff -u $testroot/stdout.expected
$testroot/stdout
1128 test_done
"$testroot" "$ret"
1131 test_merge_in_progress
() {
1132 local testroot
=`test_init merge_in_progress`
1133 local commit0
=`git_show_head $testroot/repo`
1134 local commit0_author_time
=`git_show_author_time $testroot/repo`
1136 git
-C $testroot/repo checkout
-q -b newbranch
1137 echo "modified alpha on branch" > $testroot/repo
/alpha
1138 git_commit
$testroot/repo
-m "committing to alpha on newbranch"
1139 local branch_commit0
=`git_show_branch_head $testroot/repo newbranch`
1141 got checkout
-b master
$testroot/repo
$testroot/wt
> /dev
/null
1143 if [ $ret -ne 0 ]; then
1144 echo "got checkout failed unexpectedly" >&2
1145 test_done
"$testroot" "$ret"
1149 # create a conflicting commit
1150 git
-C $testroot/repo checkout
-q master
1151 echo "modified alpha on master" > $testroot/repo
/alpha
1152 git_commit
$testroot/repo
-m "committing to alpha on master"
1153 local master_commit
=`git_show_head $testroot/repo`
1155 # need an up-to-date work tree for 'got merge'
1156 (cd $testroot/wt
&& got update
> /dev
/null
)
1158 if [ $ret -ne 0 ]; then
1159 echo "got update failed unexpectedly" >&2
1160 test_done
"$testroot" "$ret"
1164 (cd $testroot/wt
&& got merge newbranch \
1165 > $testroot/stdout
2> $testroot/stderr
)
1167 if [ $ret -eq 0 ]; then
1168 echo "got merge succeeded unexpectedly" >&2
1169 test_done
"$testroot" "1"
1173 echo "C alpha" >> $testroot/stdout.expected
1174 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1175 cmp -s $testroot/stdout.expected
$testroot/stdout
1177 if [ $ret -ne 0 ]; then
1178 diff -u $testroot/stdout.expected
$testroot/stdout
1179 test_done
"$testroot" "$ret"
1183 echo "got: conflicts must be resolved before merging can continue" \
1184 > $testroot/stderr.expected
1185 cmp -s $testroot/stderr.expected
$testroot/stderr
1187 if [ $ret -ne 0 ]; then
1188 diff -u $testroot/stderr.expected
$testroot/stderr
1189 test_done
"$testroot" "$ret"
1193 (cd $testroot/wt
&& got status
> $testroot/stdout
)
1195 cat > $testroot/stdout.expected
<<EOF
1197 Work tree is merging refs/heads/newbranch into refs/heads/master
1199 cmp -s $testroot/stdout.expected
$testroot/stdout
1201 if [ $ret -ne 0 ]; then
1202 diff -u $testroot/stdout.expected
$testroot/stdout
1203 test_done
"$testroot" "$ret"
1207 for cmd
in update commit histedit
"rebase newbranch" \
1208 "integrate newbranch" "merge newbranch" "stage alpha"; do
1209 (cd $testroot/wt
&& got
$cmd > $testroot/stdout \
1210 2> $testroot/stderr
)
1212 if [ $ret -eq 0 ]; then
1213 echo "got $cmd succeeded unexpectedly" >&2
1214 test_done
"$testroot" "1"
1218 echo -n > $testroot/stdout.expected
1219 cmp -s $testroot/stdout.expected
$testroot/stdout
1221 if [ $ret -ne 0 ]; then
1222 diff -u $testroot/stdout.expected
$testroot/stdout
1223 test_done
"$testroot" "$ret"
1227 echo -n "got: a merge operation is in progress in this " \
1228 > $testroot/stderr.expected
1229 echo "work tree and must be continued or aborted first" \
1230 >> $testroot/stderr.expected
1231 cmp -s $testroot/stderr.expected
$testroot/stderr
1233 if [ $ret -ne 0 ]; then
1234 diff -u $testroot/stderr.expected
$testroot/stderr
1235 test_done
"$testroot" "$ret"
1240 test_done
"$testroot" "$ret"
1243 test_merge_path_prefix
() {
1244 local testroot
=`test_init merge_path_prefix`
1245 local commit0
=`git_show_head $testroot/repo`
1246 local commit0_author_time
=`git_show_author_time $testroot/repo`
1248 git
-C $testroot/repo checkout
-q -b newbranch
1249 echo "modified alpha on branch" > $testroot/repo
/alpha
1250 git_commit
$testroot/repo
-m "committing to alpha on newbranch"
1251 local branch_commit0
=`git_show_branch_head $testroot/repo newbranch`
1253 got checkout
-p epsilon
-b master
$testroot/repo
$testroot/wt \
1256 if [ $ret -ne 0 ]; then
1257 echo "got checkout failed unexpectedly" >&2
1258 test_done
"$testroot" "$ret"
1262 # create a conflicting commit
1263 git
-C $testroot/repo checkout
-q master
1264 echo "modified alpha on master" > $testroot/repo
/alpha
1265 git_commit
$testroot/repo
-m "committing to alpha on master"
1266 local master_commit
=`git_show_head $testroot/repo`
1268 # need an up-to-date work tree for 'got merge'
1269 (cd $testroot/wt
&& got update
> /dev
/null
)
1271 if [ $ret -ne 0 ]; then
1272 echo "got update failed unexpectedly" >&2
1273 test_done
"$testroot" "$ret"
1277 (cd $testroot/wt
&& got merge newbranch \
1278 > $testroot/stdout
2> $testroot/stderr
)
1280 if [ $ret -eq 0 ]; then
1281 echo "got merge succeeded unexpectedly" >&2
1282 test_done
"$testroot" "1"
1286 echo -n "got: cannot merge branch which contains changes outside " \
1287 > $testroot/stderr.expected
1288 echo "of this work tree's path prefix" >> $testroot/stderr.expected
1289 cmp -s $testroot/stderr.expected
$testroot/stderr
1291 if [ $ret -ne 0 ]; then
1292 diff -u $testroot/stderr.expected
$testroot/stderr
1294 test_done
"$testroot" "$ret"
1297 test_merge_missing_file
() {
1298 local testroot
=`test_init merge_missing_file`
1299 local commit0
=`git_show_head $testroot/repo`
1300 local commit0_author_time
=`git_show_author_time $testroot/repo`
1302 git
-C $testroot/repo checkout
-q -b newbranch
1303 echo "modified alpha on branch" > $testroot/repo
/alpha
1304 echo "modified delta on branch" > $testroot/repo
/gamma
/delta
1305 git_commit
$testroot/repo
-m "committing to alpha and delta"
1306 local branch_commit0
=`git_show_branch_head $testroot/repo newbranch`
1308 got checkout
-b master
$testroot/repo
$testroot/wt
> /dev
/null
1310 if [ $ret -ne 0 ]; then
1311 echo "got checkout failed unexpectedly" >&2
1312 test_done
"$testroot" "$ret"
1316 # create a conflicting commit which renames alpha
1317 git
-C $testroot/repo checkout
-q master
1318 git
-C $testroot/repo
mv alpha epsilon
/alpha-moved
1319 git_commit
$testroot/repo
-m "moving alpha on master"
1320 local master_commit
=`git_show_head $testroot/repo`
1322 # need an up-to-date work tree for 'got merge'
1323 (cd $testroot/wt
&& got update
> /dev
/null
)
1325 if [ $ret -ne 0 ]; then
1326 echo "got update failed unexpectedly" >&2
1327 test_done
"$testroot" "$ret"
1331 (cd $testroot/wt
&& got merge newbranch \
1332 > $testroot/stdout
2> $testroot/stderr
)
1334 if [ $ret -eq 0 ]; then
1335 echo "got merge succeeded unexpectedly" >&2
1336 test_done
"$testroot" "1"
1340 echo "! alpha" > $testroot/stdout.expected
1341 echo "G gamma/delta" >> $testroot/stdout.expected
1342 echo -n "Files which had incoming changes but could not be found " \
1343 >> $testroot/stdout.expected
1344 echo "in the work tree: 1" >> $testroot/stdout.expected
1345 cmp -s $testroot/stdout.expected
$testroot/stdout
1347 if [ $ret -ne 0 ]; then
1348 diff -u $testroot/stdout.expected
$testroot/stdout
1349 test_done
"$testroot" "$ret"
1353 echo -n "got: changes destined for some files " \
1354 > $testroot/stderr.expected
1355 echo -n "were not yet merged and should be merged manually if " \
1356 >> $testroot/stderr.expected
1357 echo "required before the merge operation is continued" \
1358 >> $testroot/stderr.expected
1359 cmp -s $testroot/stderr.expected
$testroot/stderr
1361 if [ $ret -ne 0 ]; then
1362 diff -u $testroot/stderr.expected
$testroot/stderr
1363 test_done
"$testroot" "$ret"
1367 (cd $testroot/wt
&& got status
> $testroot/stdout
)
1369 cat > $testroot/stdout.expected
<<EOF
1371 Work tree is merging refs/heads/newbranch into refs/heads/master
1373 cmp -s $testroot/stdout.expected
$testroot/stdout
1375 if [ $ret -ne 0 ]; then
1376 diff -u $testroot/stdout.expected
$testroot/stdout
1377 test_done
"$testroot" "$ret"
1381 test_done
"$testroot" "$ret"
1384 test_merge_no_op
() {
1385 local testroot
=`test_init merge_no_op`
1386 local commit0
=`git_show_head $testroot/repo`
1387 local commit0_author_time
=`git_show_author_time $testroot/repo`
1389 git
-C $testroot/repo checkout
-q -b newbranch
1390 echo "modified alpha on branch" > $testroot/repo
/alpha
1391 git_commit
$testroot/repo
-m "committing to alpha on newbranch"
1392 local branch_commit
=`git_show_branch_head $testroot/repo newbranch`
1394 got checkout
-b master
$testroot/repo
$testroot/wt
> /dev
/null
1396 if [ $ret -ne 0 ]; then
1397 echo "got checkout failed unexpectedly" >&2
1398 test_done
"$testroot" "$ret"
1402 # create a conflicting commit
1403 git
-C $testroot/repo checkout
-q master
1404 echo "modified alpha on master" > $testroot/repo
/alpha
1405 git_commit
$testroot/repo
-m "committing to alpha on master"
1406 local master_commit
=`git_show_head $testroot/repo`
1408 # need an up-to-date work tree for 'got merge'
1409 (cd $testroot/wt
&& got update
> /dev
/null
)
1411 if [ $ret -ne 0 ]; then
1412 echo "got update failed unexpectedly" >&2
1413 test_done
"$testroot" "$ret"
1417 (cd $testroot/wt
&& got merge newbranch \
1418 > $testroot/stdout
2> $testroot/stderr
)
1420 if [ $ret -eq 0 ]; then
1421 echo "got merge succeeded unexpectedly" >&2
1422 test_done
"$testroot" "1"
1426 echo "C alpha" >> $testroot/stdout.expected
1427 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1428 cmp -s $testroot/stdout.expected
$testroot/stdout
1430 if [ $ret -ne 0 ]; then
1431 diff -u $testroot/stdout.expected
$testroot/stdout
1432 test_done
"$testroot" "$ret"
1436 echo "got: conflicts must be resolved before merging can continue" \
1437 > $testroot/stderr.expected
1438 cmp -s $testroot/stderr.expected
$testroot/stderr
1440 if [ $ret -ne 0 ]; then
1441 diff -u $testroot/stderr.expected
$testroot/stderr
1442 test_done
"$testroot" "$ret"
1446 (cd $testroot/wt
&& got status
> $testroot/stdout
)
1448 cat > $testroot/stdout.expected
<<EOF
1450 Work tree is merging refs/heads/newbranch into refs/heads/master
1452 cmp -s $testroot/stdout.expected
$testroot/stdout
1454 if [ $ret -ne 0 ]; then
1455 diff -u $testroot/stdout.expected
$testroot/stdout
1456 test_done
"$testroot" "$ret"
1460 # resolve the conflict by reverting all changes; now it is no-op merge
1461 (cd $testroot/wt
&& got revert alpha
> /dev
/null
)
1463 if [ $ret -ne 0 ]; then
1464 echo "got revert failed unexpectedly" >&2
1465 test_done
"$testroot" "$ret"
1469 (cd $testroot/wt
&& got merge
-c > $testroot/stdout \
1470 2> $testroot/stderr
)
1472 if [ $ret -ne 0 ]; then
1473 echo "got merge failed unexpectedly" >&2
1474 test_done
"$testroot" "$ret"
1478 echo -n '' > $testroot/stderr.expected
1479 cmp -s $testroot/stderr.expected
$testroot/stderr
1481 if [ $ret -ne 0 ]; then
1482 diff -u $testroot/stderr.expected
$testroot/stderr
1483 test_done
"$testroot" "$ret"
1487 local merge_commit
=`git_show_head $testroot/repo`
1488 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1489 > $testroot/stdout.expected
1490 echo $merge_commit >> $testroot/stdout.expected
1492 cmp -s $testroot/stdout.expected
$testroot/stdout
1494 if [ $ret -ne 0 ]; then
1495 diff -u $testroot/stdout.expected
$testroot/stdout
1496 test_done
"$testroot" "$ret"
1500 (cd $testroot/wt
&& got status
> $testroot/stdout
)
1502 echo -n "" > $testroot/stdout.expected
1503 cmp -s $testroot/stdout.expected
$testroot/stdout
1505 if [ $ret -ne 0 ]; then
1506 diff -u $testroot/stdout.expected
$testroot/stdout
1507 test_done
"$testroot" "$ret"
1511 # We should have created a merge commit with two parents.
1512 got log
-r $testroot/repo
-l1 -c $merge_commit |
grep ^parent \
1514 echo "parent 1: $master_commit" > $testroot/stdout.expected
1515 echo "parent 2: $branch_commit" >> $testroot/stdout.expected
1516 cmp -s $testroot/stdout.expected
$testroot/stdout
1518 if [ $ret -ne 0 ]; then
1519 diff -u $testroot/stdout.expected
$testroot/stdout
1521 test_done
"$testroot" "$ret"
1524 test_merge_imported_branch
() {
1525 local testroot
=`test_init merge_import`
1526 local commit0
=`git_show_head $testroot/repo`
1527 local commit0_author_time
=`git_show_author_time $testroot/repo`
1529 # import a new sub-tree to the 'files' branch such that
1530 # none of the files added here collide with existing ones
1531 mkdir
-p $testroot/tree
/there
1532 mkdir
-p $testroot/tree
/be
/lots
1533 mkdir
-p $testroot/tree
/files
1534 echo "there should" > $testroot/tree
/there
/should
1535 echo "be lots of" > $testroot/tree
/be
/lots
/of
1536 echo "files here" > $testroot/tree
/files
/here
1537 got import
-r $testroot/repo
-b files
-m 'import files' \
1538 $testroot/tree
> /dev
/null
1540 got checkout
-b master
$testroot/repo
$testroot/wt
> /dev
/null
1542 if [ $ret -ne 0 ]; then
1543 echo "got checkout failed unexpectedly" >&2
1544 test_done
"$testroot" "$ret"
1548 (cd $testroot/wt
&& got merge files
> $testroot/stdout
)
1550 if [ $ret -ne 0 ]; then
1551 echo "got merge failed unexpectedly" >&2
1552 test_done
"$testroot" "$ret"
1556 local merge_commit0
=`git_show_head $testroot/repo`
1557 cat > $testroot/stdout.expected
<<EOF
1561 Merged refs/heads/files into refs/heads/master: $merge_commit0
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 # try to merge again while no new changes are available
1572 (cd $testroot/wt
&& got merge files
> $testroot/stdout
)
1574 if [ $ret -ne 0 ]; then
1575 echo "got merge failed unexpectedly" >&2
1576 test_done
"$testroot" "$ret"
1579 echo "Already up-to-date" > $testroot/stdout.expected
1580 cmp -s $testroot/stdout.expected
$testroot/stdout
1582 if [ $ret -ne 0 ]; then
1583 diff -u $testroot/stdout.expected
$testroot/stdout
1584 test_done
"$testroot" "$ret"
1588 # update the 'files' branch
1589 git
-C $testroot/repo
reset -q --hard master
1590 git
-C $testroot/repo checkout
-q files
1591 echo "indeed" > $testroot/repo
/indeed
1592 git
-C $testroot/repo add indeed
1593 git_commit
$testroot/repo
-m "adding another file indeed"
1594 echo "be lots and lots of" > $testroot/repo
/be
/lots
/of
1595 git_commit
$testroot/repo
-m "lots of changes"
1597 (cd $testroot/wt
&& got update
> /dev
/null
)
1599 if [ $ret -ne 0 ]; then
1600 echo "got update failed unexpectedly" >&2
1601 test_done
"$testroot" "$ret"
1605 # we should now be able to merge more changes from files branch
1606 (cd $testroot/wt
&& got merge files
> $testroot/stdout
)
1608 if [ $ret -ne 0 ]; then
1609 echo "got merge failed unexpectedly" >&2
1610 test_done
"$testroot" "$ret"
1614 local merge_commit1
=`git_show_branch_head $testroot/repo master`
1615 cat > $testroot/stdout.expected
<<EOF
1618 Merged refs/heads/files into refs/heads/master: $merge_commit1
1621 cmp -s $testroot/stdout.expected
$testroot/stdout
1623 if [ $ret -ne 0 ]; then
1624 diff -u $testroot/stdout.expected
$testroot/stdout
1626 test_done
"$testroot" "$ret"
1629 test_merge_interrupt
() {
1630 local testroot
=`test_init merge_interrupt`
1631 local commit0
=`git_show_head $testroot/repo`
1632 local commit0_author_time
=`git_show_author_time $testroot/repo`
1634 git
-C $testroot/repo checkout
-q -b newbranch
1635 echo "modified alpha on branch" > $testroot/repo
/alpha
1636 git_commit
$testroot/repo
-m "committing to alpha on newbranch"
1637 local branch_commit0
=`git_show_branch_head $testroot/repo newbranch`
1639 got checkout
-b master
$testroot/repo
$testroot/wt
> /dev
/null
1641 if [ $ret -ne 0 ]; then
1642 echo "got checkout failed unexpectedly" >&2
1643 test_done
"$testroot" "$ret"
1647 # create a non-conflicting commit
1648 git
-C $testroot/repo checkout
-q master
1649 echo "modified beta on master" > $testroot/repo
/beta
1650 git_commit
$testroot/repo
-m "committing to beta on master"
1651 local master_commit
=`git_show_head $testroot/repo`
1653 # need an up-to-date work tree for 'got merge'
1654 (cd $testroot/wt
&& got update
> /dev
/null
)
1656 if [ $ret -ne 0 ]; then
1657 echo "got update failed unexpectedly" >&2
1658 test_done
"$testroot" "$ret"
1662 (cd $testroot/wt
&& got merge
-n newbranch \
1663 > $testroot/stdout
2> $testroot/stderr
)
1665 if [ $ret -ne 0 ]; then
1666 echo "got merge failed unexpectedly" >&2
1667 test_done
"$testroot" "1"
1671 echo "G alpha" > $testroot/stdout.expected
1672 echo "Merge of refs/heads/newbranch interrupted on request" \
1673 >> $testroot/stdout.expected
1674 cmp -s $testroot/stdout.expected
$testroot/stdout
1676 if [ $ret -ne 0 ]; then
1677 diff -u $testroot/stdout.expected
$testroot/stdout
1678 test_done
"$testroot" "$ret"
1682 (cd $testroot/wt
&& got status
> $testroot/stdout
)
1684 cat > $testroot/stdout.expected
<<EOF
1686 Work tree is merging refs/heads/newbranch into refs/heads/master
1688 cmp -s $testroot/stdout.expected
$testroot/stdout
1690 if [ $ret -ne 0 ]; then
1691 diff -u $testroot/stdout.expected
$testroot/stdout
1692 test_done
"$testroot" "$ret"
1696 echo "modified alpha on branch" > $testroot/content.expected
1697 cat $testroot/wt
/alpha
> $testroot/content
1698 cmp -s $testroot/content.expected
$testroot/content
1700 if [ $ret -ne 0 ]; then
1701 diff -u $testroot/content.expected
$testroot/content
1702 test_done
"$testroot" "$ret"
1706 # adjust merge result
1707 echo "adjusted merge result" > $testroot/wt
/alpha
1709 # continue the merge
1710 (cd $testroot/wt
&& got merge
-c > $testroot/stdout
)
1712 if [ $ret -ne 0 ]; then
1713 echo "got merge failed unexpectedly" >&2
1714 test_done
"$testroot" "$ret"
1718 local merge_commit
=`git_show_head $testroot/repo`
1720 echo "M alpha" > $testroot/stdout.expected
1721 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1722 >> $testroot/stdout.expected
1723 echo $merge_commit >> $testroot/stdout.expected
1725 cmp -s $testroot/stdout.expected
$testroot/stdout
1727 if [ $ret -ne 0 ]; then
1728 diff -u $testroot/stdout.expected
$testroot/stdout
1729 test_done
"$testroot" "$ret"
1733 (cd $testroot/wt
&& got status
> $testroot/stdout
)
1735 echo -n > $testroot/stdout.expected
1736 cmp -s $testroot/stdout.expected
$testroot/stdout
1738 if [ $ret -ne 0 ]; then
1739 diff -u $testroot/stdout.expected
$testroot/stdout
1740 test_done
"$testroot" "$ret"
1744 (cd $testroot/wt
&& got log
-l3 |
grep ^commit
> $testroot/stdout
)
1745 echo "commit $merge_commit (master)" > $testroot/stdout.expected
1746 echo "commit $master_commit" >> $testroot/stdout.expected
1747 echo "commit $commit0" >> $testroot/stdout.expected
1748 cmp -s $testroot/stdout.expected
$testroot/stdout
1750 if [ $ret -ne 0 ]; then
1751 diff -u $testroot/stdout.expected
$testroot/stdout
1752 test_done
"$testroot" "$ret"
1756 (cd $testroot/wt
&& got update
> $testroot/stdout
)
1758 echo 'Already up-to-date' > $testroot/stdout.expected
1759 cmp -s $testroot/stdout.expected
$testroot/stdout
1761 if [ $ret -ne 0 ]; then
1762 diff -u $testroot/stdout.expected
$testroot/stdout
1763 test_done
"$testroot" "$ret"
1767 # We should have created a merge commit with two parents.
1768 (cd $testroot/wt
&& got log
-l1 |
grep ^parent
> $testroot/stdout
)
1769 echo "parent 1: $master_commit" > $testroot/stdout.expected
1770 echo "parent 2: $branch_commit0" >> $testroot/stdout.expected
1771 cmp -s $testroot/stdout.expected
$testroot/stdout
1773 if [ $ret -ne 0 ]; then
1774 diff -u $testroot/stdout.expected
$testroot/stdout
1776 test_done
"$testroot" "$ret"
1779 test_merge_umask
() {
1780 local testroot
=`test_init merge_umask`
1782 git
-C $testroot/repo checkout
-q -b newbranch
1783 echo "modified alpha on branch" >$testroot/repo
/alpha
1784 git_commit
"$testroot/repo" -m "committing alpha on newbranch"
1785 echo "modified delta on branch" >$testroot/repo
/gamma
/delta
1786 git_commit
"$testroot/repo" -m "committing delta on newbranch"
1788 # diverge from newbranch
1789 git
-C "$testroot/repo" checkout
-q master
1790 echo "modified beta on master" >$testroot/repo
/beta
1791 git_commit
"$testroot/repo" -m "committing zeto no master"
1793 got checkout
"$testroot/repo" "$testroot/wt" >/dev
/null
1795 # using a subshell to avoid clobbering global umask
1796 (umask 077 && cd "$testroot/wt" && got merge newbranch
) >/dev
/null
1798 for f
in alpha gamma
/delta
; do
1799 ls -l "$testroot/wt/$f" |
grep -q ^
-rw-------
1800 if [ $?
-ne 0 ]; then
1801 echo "$f is not 0600 after merge" >&2
1802 ls -l "$testroot/wt/$f" >&2
1803 test_done
"$testroot" 1
1807 test_done
"$testroot" 0
1810 test_merge_gitconfig_author
() {
1811 local testroot
=`test_init merge_gitconfig_author`
1813 git
-C $testroot/repo config user.name
'Flan Luck'
1814 git
-C $testroot/repo config user.email
'flan_luck@openbsd.org'
1816 git
-C $testroot/repo checkout
-q -b newbranch
1817 echo "modified alpha on branch" >$testroot/repo
/alpha
1818 git_commit
"$testroot/repo" -m "committing alpha on newbranch"
1819 echo "modified delta on branch" >$testroot/repo
/gamma
/delta
1820 git_commit
"$testroot/repo" -m "committing delta on newbranch"
1822 # diverge from newbranch
1823 git
-C "$testroot/repo" checkout
-q master
1824 echo "modified beta on master" >$testroot/repo
/beta
1825 git_commit
"$testroot/repo" -m "committing zeto no master"
1827 got checkout
"$testroot/repo" "$testroot/wt" >/dev
/null
1829 # unset in a subshell to avoid affecting our environment
1830 (unset GOT_IGNORE_GITCONFIG
&& cd $testroot/wt
&& \
1831 got merge newbranch
> /dev
/null
)
1833 (cd $testroot/repo
&& got log
-l1 |
grep ^from
: > $testroot/stdout
)
1835 if [ $ret -ne 0 ]; then
1836 test_done
"$testroot" "$ret"
1840 echo "from: Flan Luck <flan_luck@openbsd.org>" \
1841 > $testroot/stdout.expected
1842 cmp -s $testroot/stdout.expected
$testroot/stdout
1844 if [ $ret -ne 0 ]; then
1845 diff -u $testroot/stdout.expected
$testroot/stdout
1847 test_done
"$testroot" "$ret"
1850 test_merge_fetched_branch
() {
1851 local testroot
=`test_init merge_fetched_branch`
1852 local testurl
=ssh://127.0.0.1/$testroot
1853 local commit_id
=`git_show_head $testroot/repo`
1855 got clone
-q $testurl/repo
$testroot/repo-clone
1857 if [ $ret -ne 0 ]; then
1858 echo "got clone command failed unexpectedly" >&2
1859 test_done
"$testroot" "$ret"
1863 echo "modified alpha" > $testroot/repo
/alpha
1864 git_commit
$testroot/repo
-m "modified alpha"
1865 local commit_id2
=`git_show_head $testroot/repo`
1867 got fetch
-q -r $testroot/repo-clone
> $testroot/stdout
1869 if [ $ret -ne 0 ]; then
1870 echo "got fetch command failed unexpectedly" >&2
1871 test_done
"$testroot" "$ret"
1875 echo -n > $testroot/stdout.expected
1877 cmp -s $testroot/stdout
$testroot/stdout.expected
1879 if [ $ret -ne 0 ]; then
1880 diff -u $testroot/stdout.expected
$testroot/stdout
1881 test_done
"$testroot" "$ret"
1885 got ref
-l -r $testroot/repo-clone
> $testroot/stdout
1887 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1888 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1889 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1890 >> $testroot/stdout.expected
1891 echo "refs/remotes/origin/master: $commit_id2" \
1892 >> $testroot/stdout.expected
1894 cmp -s $testroot/stdout
$testroot/stdout.expected
1896 if [ $ret -ne 0 ]; then
1897 diff -u $testroot/stdout.expected
$testroot/stdout
1898 test_done
"$testroot" "$ret"
1902 got checkout
$testroot/repo-clone
$testroot/wt
> /dev
/null
1904 echo "modified beta" > $testroot/wt
/beta
1905 (cd $testroot/wt
&& got commit
-m "modified beta" > /dev
/null
)
1906 local commit_id3
=`git_show_head $testroot/repo-clone`
1908 (cd $testroot/wt
&& got update
> /dev
/null
)
1909 (cd $testroot/wt
&& got merge origin
/master
> $testroot/stdout
)
1910 local merge_commit_id
=`git_show_head $testroot/repo-clone`
1912 cat > $testroot/stdout.expected
<<EOF
1914 Merged refs/remotes/origin/master into refs/heads/master: $merge_commit_id
1917 cmp -s $testroot/stdout
$testroot/stdout.expected
1919 if [ $ret -ne 0 ]; then
1920 diff -u $testroot/stdout.expected
$testroot/stdout
1922 test_done
"$testroot" "$ret"
1925 test_merge_fetched_branch_remote
() {
1926 local testroot
=`test_init merge_fetched_branch_remote`
1927 local testurl
=ssh://127.0.0.1/$testroot
1928 local commit_id
=`git_show_head $testroot/repo`
1930 got clone
-q $testurl/repo
$testroot/repo-clone
1932 if [ $ret -ne 0 ]; then
1933 echo "got clone command failed unexpectedly" >&2
1934 test_done
"$testroot" "$ret"
1938 echo "modified alpha" > $testroot/repo
/alpha
1939 git_commit
$testroot/repo
-m "modified alpha"
1940 local commit_id2
=`git_show_head $testroot/repo`
1942 got fetch
-q -r $testroot/repo-clone
> $testroot/stdout
1944 if [ $ret -ne 0 ]; then
1945 echo "got fetch command failed unexpectedly" >&2
1946 test_done
"$testroot" "$ret"
1950 echo -n > $testroot/stdout.expected
1952 cmp -s $testroot/stdout
$testroot/stdout.expected
1954 if [ $ret -ne 0 ]; then
1955 diff -u $testroot/stdout.expected
$testroot/stdout
1956 test_done
"$testroot" "$ret"
1960 got ref
-l -r $testroot/repo-clone
> $testroot/stdout
1962 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1963 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1964 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1965 >> $testroot/stdout.expected
1966 echo "refs/remotes/origin/master: $commit_id2" \
1967 >> $testroot/stdout.expected
1969 cmp -s $testroot/stdout
$testroot/stdout.expected
1971 if [ $ret -ne 0 ]; then
1972 diff -u $testroot/stdout.expected
$testroot/stdout
1973 test_done
"$testroot" "$ret"
1977 got checkout
$testroot/repo-clone
$testroot/wt
> /dev
/null
1979 echo "modified beta" > $testroot/wt
/beta
1980 (cd $testroot/wt
&& got commit
-m "modified beta" > /dev
/null
)
1981 local commit_id3
=`git_show_head $testroot/repo-clone`
1983 (cd $testroot/wt
&& got update
-b origin
/master
> /dev
/null
)
1984 (cd $testroot/wt
&& got merge master
> \
1985 $testroot/stdout
2> $testroot/stderr
)
1986 local merge_commit_id
=`git_show_head $testroot/repo-clone`
1988 echo -n > $testroot/stdout.expected
1990 cmp -s $testroot/stdout
$testroot/stdout.expected
1992 if [ $ret -ne 0 ]; then
1993 diff -u $testroot/stdout.expected
$testroot/stdout
1994 test_done
"$testroot" "$ret"
1998 echo -n "got: work tree's current branch refs/remotes/origin/master " \
1999 > $testroot/stderr.expected
2000 echo -n 'is outside the "refs/heads/" reference namespace; ' \
2001 >> $testroot/stderr.expected
2002 echo -n "update -b required: will not commit to a branch " \
2003 >> $testroot/stderr.expected
2004 echo 'outside the "refs/heads/" reference namespace' \
2005 >> $testroot/stderr.expected
2007 cmp -s $testroot/stderr
$testroot/stderr.expected
2009 if [ $ret -ne 0 ]; then
2010 diff -u $testroot/stderr.expected
$testroot/stderr
2012 test_done
"$testroot" "$ret"
2016 run_test test_merge_basic
2017 run_test test_merge_forward
2018 run_test test_merge_forward_commit
2019 run_test test_merge_forward_interrupt
2020 run_test test_merge_backward
2021 run_test test_merge_continue
2022 run_test test_merge_continue_new_commit
2023 run_test test_merge_abort
2024 run_test test_merge_in_progress
2025 run_test test_merge_path_prefix
2026 run_test test_merge_missing_file
2027 run_test test_merge_no_op
2028 run_test test_merge_imported_branch
2029 run_test test_merge_interrupt
2030 run_test test_merge_umask
2031 run_test test_merge_gitconfig_author
2032 run_test test_merge_fetched_branch no-sha256
# need network
2033 run_test test_merge_fetched_branch_remote no-sha256
# need network