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`
43 got checkout
-b master
$testroot/repo
$testroot/wt
> /dev
/null
45 if [ "$ret" != "0" ]; then
46 echo "got checkout failed unexpectedly" >&2
47 test_done
"$testroot" "$ret"
51 # need a divergant commit on the main branch for 'got merge'
52 (cd $testroot/wt
&& got merge newbranch \
53 > $testroot/stdout
2> $testroot/stderr
)
55 if [ "$ret" == "0" ]; then
56 echo "got merge succeeded unexpectedly" >&2
57 test_done
"$testroot" "1"
60 echo -n "got: cannot create a merge commit because " \
61 > $testroot/stderr.expected
62 echo -n "refs/heads/newbranch is based on refs/heads/master; " \
63 >> $testroot/stderr.expected
64 echo -n "refs/heads/newbranch can be integrated with " \
65 >> $testroot/stderr.expected
66 echo "'got integrate' instead" >> $testroot/stderr.expected
67 cmp -s $testroot/stderr.expected
$testroot/stderr
69 if [ "$ret" != "0" ]; then
70 diff -u $testroot/stderr.expected
$testroot/stderr
71 test_done
"$testroot" "$ret"
75 # create the required dirvergant commit
76 (cd $testroot/repo
&& git checkout
-q master
)
77 echo "modified zeta on master" > $testroot/repo
/epsilon
/zeta
78 git_commit
$testroot/repo
-m "committing to zeta on master"
79 local master_commit
=`git_show_head $testroot/repo`
81 # need an up-to-date work tree for 'got merge'
82 (cd $testroot/wt
&& got merge newbranch \
83 > $testroot/stdout
2> $testroot/stderr
)
85 if [ "$ret" == "0" ]; then
86 echo "got merge succeeded unexpectedly" >&2
87 test_done
"$testroot" "$ret"
90 echo -n "got: work tree must be updated before it can be used " \
91 > $testroot/stderr.expected
92 echo "to merge a branch" >> $testroot/stderr.expected
93 cmp -s $testroot/stderr.expected
$testroot/stderr
95 if [ "$ret" != "0" ]; then
96 diff -u $testroot/stderr.expected
$testroot/stderr
97 test_done
"$testroot" "$ret"
101 (cd $testroot/wt
&& got update
> /dev
/null
)
103 if [ "$ret" != "0" ]; then
104 echo "got update failed unexpectedly" >&2
105 test_done
"$testroot" "$ret"
109 # must not use a mixed-commit work tree with 'got merge'
110 (cd $testroot/wt
&& got update
-c $commit0 alpha
> /dev
/null
)
112 if [ "$ret" != "0" ]; then
113 echo "got update failed unexpectedly" >&2
114 test_done
"$testroot" "$ret"
117 (cd $testroot/wt
&& got merge newbranch \
118 > $testroot/stdout
2> $testroot/stderr
)
120 if [ "$ret" == "0" ]; then
121 echo "got merge succeeded unexpectedly" >&2
122 test_done
"$testroot" "$ret"
125 echo -n "got: work tree contains files from multiple base commits; " \
126 > $testroot/stderr.expected
127 echo "the entire work tree must be updated first" \
128 >> $testroot/stderr.expected
129 cmp -s $testroot/stderr.expected
$testroot/stderr
131 if [ "$ret" != "0" ]; then
132 diff -u $testroot/stderr.expected
$testroot/stderr
133 test_done
"$testroot" "$ret"
137 (cd $testroot/wt
&& got update
> /dev
/null
)
139 if [ "$ret" != "0" ]; then
140 echo "got update failed unexpectedly" >&2
141 test_done
"$testroot" "$ret"
145 # must not have staged files with 'got merge'
146 echo "modified file alpha" > $testroot/wt
/alpha
147 (cd $testroot/wt
&& got stage alpha
> /dev
/null
)
149 if [ "$ret" != "0" ]; then
150 echo "got stage failed unexpectedly" >&2
151 test_done
"$testroot" "$ret"
154 (cd $testroot/wt
&& got merge newbranch \
155 > $testroot/stdout
2> $testroot/stderr
)
157 if [ "$ret" == "0" ]; then
158 echo "got merge succeeded unexpectedly" >&2
159 test_done
"$testroot" "$ret"
162 echo "got: alpha: file is staged" > $testroot/stderr.expected
163 cmp -s $testroot/stderr.expected
$testroot/stderr
165 if [ "$ret" != "0" ]; then
166 diff -u $testroot/stderr.expected
$testroot/stderr
167 test_done
"$testroot" "$ret"
170 (cd $testroot/wt
&& got unstage alpha
> /dev
/null
)
172 if [ "$ret" != "0" ]; then
173 echo "got unstage failed unexpectedly" >&2
174 test_done
"$testroot" "$ret"
178 # must not have local changes with 'got merge'
179 (cd $testroot/wt
&& got merge newbranch \
180 > $testroot/stdout
2> $testroot/stderr
)
182 if [ "$ret" == "0" ]; then
183 echo "got merge succeeded unexpectedly" >&2
184 test_done
"$testroot" "$ret"
187 echo -n "got: work tree contains local changes; " \
188 > $testroot/stderr.expected
189 echo "these changes must be committed or reverted first" \
190 >> $testroot/stderr.expected
191 cmp -s $testroot/stderr.expected
$testroot/stderr
193 if [ "$ret" != "0" ]; then
194 diff -u $testroot/stderr.expected
$testroot/stderr
195 test_done
"$testroot" "$ret"
199 (cd $testroot/wt
&& got revert alpha
> /dev
/null
)
201 if [ "$ret" != "0" ]; then
202 echo "got revert failed unexpectedly" >&2
203 test_done
"$testroot" "$ret"
207 (cd $testroot/wt
&& got merge newbranch
> $testroot/stdout
)
209 if [ "$ret" != "0" ]; then
210 echo "got merge failed unexpectedly" >&2
211 test_done
"$testroot" "$ret"
215 local merge_commit
=`git_show_head $testroot/repo`
217 echo "G alpha" >> $testroot/stdout.expected
218 echo "D beta" >> $testroot/stdout.expected
219 echo "A epsilon/new" >> $testroot/stdout.expected
220 echo "G gamma/delta" >> $testroot/stdout.expected
221 echo "A symlink" >> $testroot/stdout.expected
222 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
223 >> $testroot/stdout.expected
224 echo $merge_commit >> $testroot/stdout.expected
226 cmp -s $testroot/stdout.expected
$testroot/stdout
228 if [ "$ret" != "0" ]; then
229 diff -u $testroot/stdout.expected
$testroot/stdout
230 test_done
"$testroot" "$ret"
234 echo "modified delta on branch" > $testroot/content.expected
235 cat $testroot/wt
/gamma
/delta
> $testroot/content
236 cmp -s $testroot/content.expected
$testroot/content
238 if [ "$ret" != "0" ]; then
239 diff -u $testroot/content.expected
$testroot/content
240 test_done
"$testroot" "$ret"
244 echo "modified alpha on branch" > $testroot/content.expected
245 cat $testroot/wt
/alpha
> $testroot/content
246 cmp -s $testroot/content.expected
$testroot/content
248 if [ "$ret" != "0" ]; then
249 diff -u $testroot/content.expected
$testroot/content
250 test_done
"$testroot" "$ret"
254 if [ -e $testroot/wt
/beta
]; then
255 echo "removed file beta still exists on disk" >&2
256 test_done
"$testroot" "1"
260 echo "new file on branch" > $testroot/content.expected
261 cat $testroot/wt
/epsilon
/new
> $testroot/content
262 cmp -s $testroot/content.expected
$testroot/content
264 if [ "$ret" != "0" ]; then
265 diff -u $testroot/content.expected
$testroot/content
266 test_done
"$testroot" "$ret"
270 readlink
$testroot/wt
/symlink
> $testroot/stdout
271 echo "alpha" > $testroot/stdout.expected
272 cmp -s $testroot/stdout.expected
$testroot/stdout
274 if [ "$ret" != "0" ]; then
275 diff -u $testroot/stdout.expected
$testroot/stdout
276 test_done
"$testroot" "$ret"
280 (cd $testroot/wt
&& got status
> $testroot/stdout
)
282 echo -n > $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 log
-l3 |
grep ^commit
> $testroot/stdout
)
292 echo "commit $merge_commit (master)" > $testroot/stdout.expected
293 echo "commit $master_commit" >> $testroot/stdout.expected
294 echo "commit $commit0" >> $testroot/stdout.expected
295 cmp -s $testroot/stdout.expected
$testroot/stdout
297 if [ "$ret" != "0" ]; then
298 diff -u $testroot/stdout.expected
$testroot/stdout
299 test_done
"$testroot" "$ret"
303 (cd $testroot/wt
&& got update
> $testroot/stdout
)
305 echo 'Already up-to-date' > $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 # We should have created a merge commit with two parents.
315 (cd $testroot/wt
&& got log
-l1 |
grep ^parent
> $testroot/stdout
)
316 echo "parent 1: $master_commit" > $testroot/stdout.expected
317 echo "parent 2: $branch_commit4" >> $testroot/stdout.expected
318 cmp -s $testroot/stdout.expected
$testroot/stdout
320 if [ "$ret" != "0" ]; then
321 diff -u $testroot/stdout.expected
$testroot/stdout
323 test_done
"$testroot" "$ret"
326 test_merge_continue
() {
327 local testroot
=`test_init merge_continue`
328 local commit0
=`git_show_head $testroot/repo`
329 local commit0_author_time
=`git_show_author_time $testroot/repo`
331 (cd $testroot/repo
&& git checkout
-q -b newbranch
)
332 echo "modified delta on branch" > $testroot/repo
/gamma
/delta
333 git_commit
$testroot/repo
-m "committing to delta on newbranch"
334 local branch_commit0
=`git_show_branch_head $testroot/repo newbranch`
336 echo "modified alpha on branch" > $testroot/repo
/alpha
337 git_commit
$testroot/repo
-m "committing to alpha on newbranch"
338 local branch_commit1
=`git_show_branch_head $testroot/repo newbranch`
339 (cd $testroot/repo
&& git
rm -q beta
)
340 git_commit
$testroot/repo
-m "removing beta on newbranch"
341 local branch_commit2
=`git_show_branch_head $testroot/repo newbranch`
342 echo "new file on branch" > $testroot/repo
/epsilon
/new
343 (cd $testroot/repo
&& git add epsilon
/new
)
344 git_commit
$testroot/repo
-m "adding new file on newbranch"
345 local branch_commit3
=`git_show_branch_head $testroot/repo newbranch`
347 got checkout
-b master
$testroot/repo
$testroot/wt
> /dev
/null
349 if [ "$ret" != "0" ]; then
350 echo "got checkout failed unexpectedly" >&2
351 test_done
"$testroot" "$ret"
355 # create a conflicting commit
356 (cd $testroot/repo
&& git checkout
-q master
)
357 echo "modified alpha on master" > $testroot/repo
/alpha
358 git_commit
$testroot/repo
-m "committing to alpha on master"
359 local master_commit
=`git_show_head $testroot/repo`
361 # need an up-to-date work tree for 'got merge'
362 (cd $testroot/wt
&& got update
> /dev
/null
)
364 if [ "$ret" != "0" ]; then
365 echo "got update failed unexpectedly" >&2
366 test_done
"$testroot" "$ret"
370 (cd $testroot/wt
&& got merge newbranch \
371 > $testroot/stdout
2> $testroot/stderr
)
373 if [ "$ret" == "0" ]; then
374 echo "got merge succeeded unexpectedly" >&2
375 test_done
"$testroot" "1"
379 echo "C alpha" >> $testroot/stdout.expected
380 echo "D beta" >> $testroot/stdout.expected
381 echo "A epsilon/new" >> $testroot/stdout.expected
382 echo "G gamma/delta" >> $testroot/stdout.expected
383 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
384 cmp -s $testroot/stdout.expected
$testroot/stdout
386 if [ "$ret" != "0" ]; then
387 diff -u $testroot/stdout.expected
$testroot/stdout
388 test_done
"$testroot" "$ret"
392 echo "got: conflicts must be resolved before merging can continue" \
393 > $testroot/stderr.expected
394 cmp -s $testroot/stderr.expected
$testroot/stderr
396 if [ "$ret" != "0" ]; then
397 diff -u $testroot/stderr.expected
$testroot/stderr
398 test_done
"$testroot" "$ret"
402 (cd $testroot/wt
&& got status
> $testroot/stdout
)
404 echo "C alpha" > $testroot/stdout.expected
405 echo "D beta" >> $testroot/stdout.expected
406 echo "A epsilon/new" >> $testroot/stdout.expected
407 echo "M gamma/delta" >> $testroot/stdout.expected
408 cmp -s $testroot/stdout.expected
$testroot/stdout
410 if [ "$ret" != "0" ]; then
411 diff -u $testroot/stdout.expected
$testroot/stdout
412 test_done
"$testroot" "$ret"
416 echo '<<<<<<<' > $testroot/content.expected
417 echo "modified alpha on master" >> $testroot/content.expected
418 echo "||||||| 3-way merge base: commit $commit0" \
419 >> $testroot/content.expected
420 echo "alpha" >> $testroot/content.expected
421 echo "=======" >> $testroot/content.expected
422 echo "modified alpha on branch" >> $testroot/content.expected
423 echo ">>>>>>> merged change: commit $branch_commit3" \
424 >> $testroot/content.expected
425 cat $testroot/wt
/alpha
> $testroot/content
426 cmp -s $testroot/content.expected
$testroot/content
428 if [ "$ret" != "0" ]; then
429 diff -u $testroot/content.expected
$testroot/content
430 test_done
"$testroot" "$ret"
434 # resolve the conflict
435 echo "modified alpha by both branches" > $testroot/wt
/alpha
437 (cd $testroot/wt
&& got merge
-c > $testroot/stdout
)
439 if [ "$ret" != "0" ]; then
440 echo "got merge failed unexpectedly" >&2
441 test_done
"$testroot" "$ret"
445 local merge_commit
=`git_show_head $testroot/repo`
447 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
448 > $testroot/stdout.expected
449 echo $merge_commit >> $testroot/stdout.expected
451 cmp -s $testroot/stdout.expected
$testroot/stdout
453 if [ "$ret" != "0" ]; then
454 diff -u $testroot/stdout.expected
$testroot/stdout
455 test_done
"$testroot" "$ret"
459 echo "modified delta on branch" > $testroot/content.expected
460 cat $testroot/wt
/gamma
/delta
> $testroot/content
461 cmp -s $testroot/content.expected
$testroot/content
463 if [ "$ret" != "0" ]; then
464 diff -u $testroot/content.expected
$testroot/content
465 test_done
"$testroot" "$ret"
469 echo "modified alpha by both branches" > $testroot/content.expected
470 cat $testroot/wt
/alpha
> $testroot/content
471 cmp -s $testroot/content.expected
$testroot/content
473 if [ "$ret" != "0" ]; then
474 diff -u $testroot/content.expected
$testroot/content
475 test_done
"$testroot" "$ret"
479 if [ -e $testroot/wt
/beta
]; then
480 echo "removed file beta still exists on disk" >&2
481 test_done
"$testroot" "1"
485 echo "new file on branch" > $testroot/content.expected
486 cat $testroot/wt
/epsilon
/new
> $testroot/content
487 cmp -s $testroot/content.expected
$testroot/content
489 if [ "$ret" != "0" ]; then
490 diff -u $testroot/content.expected
$testroot/content
491 test_done
"$testroot" "$ret"
495 (cd $testroot/wt
&& got status
> $testroot/stdout
)
497 echo -n > $testroot/stdout.expected
498 cmp -s $testroot/stdout.expected
$testroot/stdout
500 if [ "$ret" != "0" ]; then
501 diff -u $testroot/stdout.expected
$testroot/stdout
502 test_done
"$testroot" "$ret"
506 (cd $testroot/wt
&& got log
-l3 |
grep ^commit
> $testroot/stdout
)
507 echo "commit $merge_commit (master)" > $testroot/stdout.expected
508 echo "commit $master_commit" >> $testroot/stdout.expected
509 echo "commit $commit0" >> $testroot/stdout.expected
510 cmp -s $testroot/stdout.expected
$testroot/stdout
512 if [ "$ret" != "0" ]; then
513 diff -u $testroot/stdout.expected
$testroot/stdout
514 test_done
"$testroot" "$ret"
518 (cd $testroot/wt
&& got update
> $testroot/stdout
)
520 echo 'Already up-to-date' > $testroot/stdout.expected
521 cmp -s $testroot/stdout.expected
$testroot/stdout
523 if [ "$ret" != "0" ]; then
524 diff -u $testroot/stdout.expected
$testroot/stdout
525 test_done
"$testroot" "$ret"
529 # We should have created a merge commit with two parents.
530 (cd $testroot/wt
&& got log
-l1 |
grep ^parent
> $testroot/stdout
)
531 echo "parent 1: $master_commit" > $testroot/stdout.expected
532 echo "parent 2: $branch_commit3" >> $testroot/stdout.expected
533 cmp -s $testroot/stdout.expected
$testroot/stdout
535 if [ "$ret" != "0" ]; then
536 diff -u $testroot/stdout.expected
$testroot/stdout
538 test_done
"$testroot" "$ret"
542 local testroot
=`test_init merge_abort`
543 local commit0
=`git_show_head $testroot/repo`
544 local commit0_author_time
=`git_show_author_time $testroot/repo`
546 (cd $testroot/repo
&& git checkout
-q -b newbranch
)
547 echo "modified delta on branch" > $testroot/repo
/gamma
/delta
548 git_commit
$testroot/repo
-m "committing to delta on newbranch"
549 local branch_commit0
=`git_show_branch_head $testroot/repo newbranch`
551 echo "modified alpha on branch" > $testroot/repo
/alpha
552 git_commit
$testroot/repo
-m "committing to alpha on newbranch"
553 local branch_commit1
=`git_show_branch_head $testroot/repo newbranch`
554 (cd $testroot/repo
&& git
rm -q beta
)
555 git_commit
$testroot/repo
-m "removing beta on newbranch"
556 local branch_commit2
=`git_show_branch_head $testroot/repo newbranch`
557 echo "new file on branch" > $testroot/repo
/epsilon
/new
558 (cd $testroot/repo
&& git add epsilon
/new
)
559 git_commit
$testroot/repo
-m "adding new file on newbranch"
560 local branch_commit3
=`git_show_branch_head $testroot/repo newbranch`
561 (cd $testroot/repo
&& ln -s alpha symlink
&& git add symlink
)
562 git_commit
$testroot/repo
-m "adding symlink on newbranch"
563 local branch_commit4
=`git_show_branch_head $testroot/repo newbranch`
565 got checkout
-b master
$testroot/repo
$testroot/wt
> /dev
/null
567 if [ "$ret" != "0" ]; then
568 echo "got checkout failed unexpectedly" >&2
569 test_done
"$testroot" "$ret"
573 # create a conflicting commit
574 (cd $testroot/repo
&& git checkout
-q master
)
575 echo "modified alpha on master" > $testroot/repo
/alpha
576 git_commit
$testroot/repo
-m "committing to alpha on master"
577 local master_commit
=`git_show_head $testroot/repo`
579 # need an up-to-date work tree for 'got merge'
580 (cd $testroot/wt
&& got update
> /dev
/null
)
582 if [ "$ret" != "0" ]; then
583 echo "got update failed unexpectedly" >&2
584 test_done
"$testroot" "$ret"
588 (cd $testroot/wt
&& got merge newbranch \
589 > $testroot/stdout
2> $testroot/stderr
)
591 if [ "$ret" == "0" ]; then
592 echo "got merge succeeded unexpectedly" >&2
593 test_done
"$testroot" "1"
597 echo "C alpha" >> $testroot/stdout.expected
598 echo "D beta" >> $testroot/stdout.expected
599 echo "A epsilon/new" >> $testroot/stdout.expected
600 echo "G gamma/delta" >> $testroot/stdout.expected
601 echo "A symlink" >> $testroot/stdout.expected
602 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
603 cmp -s $testroot/stdout.expected
$testroot/stdout
605 if [ "$ret" != "0" ]; then
606 diff -u $testroot/stdout.expected
$testroot/stdout
607 test_done
"$testroot" "$ret"
611 echo "got: conflicts must be resolved before merging can continue" \
612 > $testroot/stderr.expected
613 cmp -s $testroot/stderr.expected
$testroot/stderr
615 if [ "$ret" != "0" ]; then
616 diff -u $testroot/stderr.expected
$testroot/stderr
617 test_done
"$testroot" "$ret"
621 (cd $testroot/wt
&& got status
> $testroot/stdout
)
623 echo "C alpha" > $testroot/stdout.expected
624 echo "D beta" >> $testroot/stdout.expected
625 echo "A epsilon/new" >> $testroot/stdout.expected
626 echo "M gamma/delta" >> $testroot/stdout.expected
627 echo "A symlink" >> $testroot/stdout.expected
628 cmp -s $testroot/stdout.expected
$testroot/stdout
630 if [ "$ret" != "0" ]; then
631 diff -u $testroot/stdout.expected
$testroot/stdout
632 test_done
"$testroot" "$ret"
636 (cd $testroot/wt
&& got merge
-a > $testroot/stdout
)
638 if [ "$ret" != "0" ]; then
639 echo "got merge failed unexpectedly" >&2
640 test_done
"$testroot" "$ret"
644 echo "R alpha" > $testroot/stdout.expected
645 echo "R beta" >> $testroot/stdout.expected
646 echo "R epsilon/new" >> $testroot/stdout.expected
647 echo "R gamma/delta" >> $testroot/stdout.expected
648 echo "R symlink" >> $testroot/stdout.expected
649 echo "Merge of refs/heads/newbranch aborted" \
650 >> $testroot/stdout.expected
652 cmp -s $testroot/stdout.expected
$testroot/stdout
654 if [ "$ret" != "0" ]; then
655 diff -u $testroot/stdout.expected
$testroot/stdout
656 test_done
"$testroot" "$ret"
660 echo "delta" > $testroot/content.expected
661 cat $testroot/wt
/gamma
/delta
> $testroot/content
662 cmp -s $testroot/content.expected
$testroot/content
664 if [ "$ret" != "0" ]; then
665 diff -u $testroot/content.expected
$testroot/content
666 test_done
"$testroot" "$ret"
670 echo "modified alpha on master" > $testroot/content.expected
671 cat $testroot/wt
/alpha
> $testroot/content
672 cmp -s $testroot/content.expected
$testroot/content
674 if [ "$ret" != "0" ]; then
675 diff -u $testroot/content.expected
$testroot/content
676 test_done
"$testroot" "$ret"
680 echo "beta" > $testroot/content.expected
681 cat $testroot/wt
/beta
> $testroot/content
682 cmp -s $testroot/content.expected
$testroot/content
684 if [ "$ret" != "0" ]; then
685 diff -u $testroot/content.expected
$testroot/content
686 test_done
"$testroot" "$ret"
690 if [ -e $testroot/wt
/epsilon
/new
]; then
691 echo "reverted file epsilon/new still exists on disk" >&2
692 test_done
"$testroot" "1"
696 if [ -e $testroot/wt
/symlink
]; then
697 echo "reverted symlink still exists on disk" >&2
698 test_done
"$testroot" "1"
702 (cd $testroot/wt
&& got status
> $testroot/stdout
)
704 echo -n "" > $testroot/stdout.expected
705 cmp -s $testroot/stdout.expected
$testroot/stdout
707 if [ "$ret" != "0" ]; then
708 diff -u $testroot/stdout.expected
$testroot/stdout
709 test_done
"$testroot" "$ret"
713 (cd $testroot/wt
&& got log
-l3 |
grep ^commit
> $testroot/stdout
)
714 echo "commit $master_commit (master)" > $testroot/stdout.expected
715 echo "commit $commit0" >> $testroot/stdout.expected
716 cmp -s $testroot/stdout.expected
$testroot/stdout
718 if [ "$ret" != "0" ]; then
719 diff -u $testroot/stdout.expected
$testroot/stdout
720 test_done
"$testroot" "$ret"
724 (cd $testroot/wt
&& got update
> $testroot/stdout
)
726 echo 'Already up-to-date' > $testroot/stdout.expected
727 cmp -s $testroot/stdout.expected
$testroot/stdout
729 if [ "$ret" != "0" ]; then
730 diff -u $testroot/stdout.expected
$testroot/stdout
732 test_done
"$testroot" "$ret"
735 test_merge_in_progress
() {
736 local testroot
=`test_init merge_in_progress`
737 local commit0
=`git_show_head $testroot/repo`
738 local commit0_author_time
=`git_show_author_time $testroot/repo`
740 (cd $testroot/repo
&& git checkout
-q -b newbranch
)
741 echo "modified alpha on branch" > $testroot/repo
/alpha
742 git_commit
$testroot/repo
-m "committing to alpha on newbranch"
743 local branch_commit0
=`git_show_branch_head $testroot/repo newbranch`
745 got checkout
-b master
$testroot/repo
$testroot/wt
> /dev
/null
747 if [ "$ret" != "0" ]; then
748 echo "got checkout failed unexpectedly" >&2
749 test_done
"$testroot" "$ret"
753 # create a conflicting commit
754 (cd $testroot/repo
&& git checkout
-q master
)
755 echo "modified alpha on master" > $testroot/repo
/alpha
756 git_commit
$testroot/repo
-m "committing to alpha on master"
757 local master_commit
=`git_show_head $testroot/repo`
759 # need an up-to-date work tree for 'got merge'
760 (cd $testroot/wt
&& got update
> /dev
/null
)
762 if [ "$ret" != "0" ]; then
763 echo "got update failed unexpectedly" >&2
764 test_done
"$testroot" "$ret"
768 (cd $testroot/wt
&& got merge newbranch \
769 > $testroot/stdout
2> $testroot/stderr
)
771 if [ "$ret" == "0" ]; then
772 echo "got merge succeeded unexpectedly" >&2
773 test_done
"$testroot" "1"
777 echo "C alpha" >> $testroot/stdout.expected
778 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
779 cmp -s $testroot/stdout.expected
$testroot/stdout
781 if [ "$ret" != "0" ]; then
782 diff -u $testroot/stdout.expected
$testroot/stdout
783 test_done
"$testroot" "$ret"
787 echo "got: conflicts must be resolved before merging can continue" \
788 > $testroot/stderr.expected
789 cmp -s $testroot/stderr.expected
$testroot/stderr
791 if [ "$ret" != "0" ]; then
792 diff -u $testroot/stderr.expected
$testroot/stderr
793 test_done
"$testroot" "$ret"
797 (cd $testroot/wt
&& got status
> $testroot/stdout
)
799 echo "C alpha" > $testroot/stdout.expected
800 cmp -s $testroot/stdout.expected
$testroot/stdout
802 if [ "$ret" != "0" ]; then
803 diff -u $testroot/stdout.expected
$testroot/stdout
804 test_done
"$testroot" "$ret"
808 for cmd
in update commit histedit
"rebase newbranch" \
809 "integrate newbranch" "stage alpha"; do
810 (cd $testroot/wt
&& got
$cmd > $testroot/stdout \
813 echo -n > $testroot/stdout.expected
814 cmp -s $testroot/stdout.expected
$testroot/stdout
816 if [ "$ret" != "0" ]; then
817 diff -u $testroot/stdout.expected
$testroot/stdout
818 test_done
"$testroot" "$ret"
822 echo -n "got: a merge operation is in progress in this " \
823 > $testroot/stderr.expected
824 echo "work tree and must be continued or aborted first" \
825 >> $testroot/stderr.expected
826 cmp -s $testroot/stderr.expected
$testroot/stderr
828 if [ "$ret" != "0" ]; then
829 diff -u $testroot/stderr.expected
$testroot/stderr
830 test_done
"$testroot" "$ret"
835 test_done
"$testroot" "$ret"
838 test_merge_path_prefix
() {
839 local testroot
=`test_init merge_path_prefix`
840 local commit0
=`git_show_head $testroot/repo`
841 local commit0_author_time
=`git_show_author_time $testroot/repo`
843 (cd $testroot/repo
&& git checkout
-q -b newbranch
)
844 echo "modified alpha on branch" > $testroot/repo
/alpha
845 git_commit
$testroot/repo
-m "committing to alpha on newbranch"
846 local branch_commit0
=`git_show_branch_head $testroot/repo newbranch`
848 got checkout
-p epsilon
-b master
$testroot/repo
$testroot/wt \
851 if [ "$ret" != "0" ]; then
852 echo "got checkout failed unexpectedly" >&2
853 test_done
"$testroot" "$ret"
857 # create a conflicting commit
858 (cd $testroot/repo
&& git checkout
-q master
)
859 echo "modified alpha on master" > $testroot/repo
/alpha
860 git_commit
$testroot/repo
-m "committing to alpha on master"
861 local master_commit
=`git_show_head $testroot/repo`
863 # need an up-to-date work tree for 'got merge'
864 (cd $testroot/wt
&& got update
> /dev
/null
)
866 if [ "$ret" != "0" ]; then
867 echo "got update failed unexpectedly" >&2
868 test_done
"$testroot" "$ret"
872 (cd $testroot/wt
&& got merge newbranch \
873 > $testroot/stdout
2> $testroot/stderr
)
875 if [ "$ret" == "0" ]; then
876 echo "got merge succeeded unexpectedly" >&2
877 test_done
"$testroot" "1"
881 echo -n "got: cannot merge branch which contains changes outside " \
882 > $testroot/stderr.expected
883 echo "of this work tree's path prefix" >> $testroot/stderr.expected
884 cmp -s $testroot/stderr.expected
$testroot/stderr
886 if [ "$ret" != "0" ]; then
887 diff -u $testroot/stderr.expected
$testroot/stderr
889 test_done
"$testroot" "$ret"
892 test_merge_missing_file
() {
893 local testroot
=`test_init merge_missing_file`
894 local commit0
=`git_show_head $testroot/repo`
895 local commit0_author_time
=`git_show_author_time $testroot/repo`
897 (cd $testroot/repo
&& git checkout
-q -b newbranch
)
898 echo "modified alpha on branch" > $testroot/repo
/alpha
899 echo "modified delta on branch" > $testroot/repo
/gamma
/delta
900 git_commit
$testroot/repo
-m "committing to alpha and delta"
901 local branch_commit0
=`git_show_branch_head $testroot/repo newbranch`
903 got checkout
-b master
$testroot/repo
$testroot/wt
> /dev
/null
905 if [ "$ret" != "0" ]; then
906 echo "got checkout failed unexpectedly" >&2
907 test_done
"$testroot" "$ret"
911 # create a conflicting commit which renames alpha
912 (cd $testroot/repo
&& git checkout
-q master
)
913 (cd $testroot/repo
&& git
mv alpha epsilon
/alpha-moved
)
914 git_commit
$testroot/repo
-m "moving alpha on master"
915 local master_commit
=`git_show_head $testroot/repo`
917 # need an up-to-date work tree for 'got merge'
918 (cd $testroot/wt
&& got update
> /dev
/null
)
920 if [ "$ret" != "0" ]; then
921 echo "got update failed unexpectedly" >&2
922 test_done
"$testroot" "$ret"
926 (cd $testroot/wt
&& got merge newbranch \
927 > $testroot/stdout
2> $testroot/stderr
)
929 if [ "$ret" == "0" ]; then
930 echo "got merge succeeded unexpectedly" >&2
931 test_done
"$testroot" "1"
935 echo "! alpha" > $testroot/stdout.expected
936 echo "G gamma/delta" >> $testroot/stdout.expected
937 cmp -s $testroot/stdout.expected
$testroot/stdout
939 if [ "$ret" != "0" ]; then
940 diff -u $testroot/stdout.expected
$testroot/stdout
941 test_done
"$testroot" "$ret"
945 echo -n "got: changes destined for missing or obstructed files " \
946 > $testroot/stderr.expected
947 echo -n "were not yet merged and should be merged manually if " \
948 >> $testroot/stderr.expected
949 echo "required before the merge operation is continued" \
950 >> $testroot/stderr.expected
951 cmp -s $testroot/stderr.expected
$testroot/stderr
953 if [ "$ret" != "0" ]; then
954 diff -u $testroot/stderr.expected
$testroot/stderr
955 test_done
"$testroot" "$ret"
959 (cd $testroot/wt
&& got status
> $testroot/stdout
)
961 echo "M gamma/delta" > $testroot/stdout.expected
962 cmp -s $testroot/stdout.expected
$testroot/stdout
964 if [ "$ret" != "0" ]; then
965 diff -u $testroot/stdout.expected
$testroot/stdout
966 test_done
"$testroot" "$ret"
970 test_done
"$testroot" "$ret"
974 local testroot
=`test_init merge_no_op`
975 local commit0
=`git_show_head $testroot/repo`
976 local commit0_author_time
=`git_show_author_time $testroot/repo`
978 (cd $testroot/repo
&& git checkout
-q -b newbranch
)
979 echo "modified alpha on branch" > $testroot/repo
/alpha
980 git_commit
$testroot/repo
-m "committing to alpha on newbranch"
981 local branch_commitk
=`git_show_branch_head $testroot/repo newbranch`
983 got checkout
-b master
$testroot/repo
$testroot/wt
> /dev
/null
985 if [ "$ret" != "0" ]; then
986 echo "got checkout failed unexpectedly" >&2
987 test_done
"$testroot" "$ret"
991 # create a conflicting commit
992 (cd $testroot/repo
&& git checkout
-q master
)
993 echo "modified alpha on master" > $testroot/repo
/alpha
994 git_commit
$testroot/repo
-m "committing to alpha on master"
995 local master_commit
=`git_show_head $testroot/repo`
997 # need an up-to-date work tree for 'got merge'
998 (cd $testroot/wt
&& got update
> /dev
/null
)
1000 if [ "$ret" != "0" ]; then
1001 echo "got update failed unexpectedly" >&2
1002 test_done
"$testroot" "$ret"
1006 (cd $testroot/wt
&& got merge newbranch \
1007 > $testroot/stdout
2> $testroot/stderr
)
1009 if [ "$ret" == "0" ]; then
1010 echo "got merge succeeded unexpectedly" >&2
1011 test_done
"$testroot" "1"
1015 echo "C alpha" >> $testroot/stdout.expected
1016 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1017 cmp -s $testroot/stdout.expected
$testroot/stdout
1019 if [ "$ret" != "0" ]; then
1020 diff -u $testroot/stdout.expected
$testroot/stdout
1021 test_done
"$testroot" "$ret"
1025 echo "got: conflicts must be resolved before merging can continue" \
1026 > $testroot/stderr.expected
1027 cmp -s $testroot/stderr.expected
$testroot/stderr
1029 if [ "$ret" != "0" ]; then
1030 diff -u $testroot/stderr.expected
$testroot/stderr
1031 test_done
"$testroot" "$ret"
1035 (cd $testroot/wt
&& got status
> $testroot/stdout
)
1037 echo "C alpha" > $testroot/stdout.expected
1038 cmp -s $testroot/stdout.expected
$testroot/stdout
1040 if [ "$ret" != "0" ]; then
1041 diff -u $testroot/stdout.expected
$testroot/stdout
1042 test_done
"$testroot" "$ret"
1046 # resolve the conflict by reverting all changes; now it is no-op merge
1047 (cd $testroot/wt
&& got revert alpha
> /dev
/null
)
1049 if [ "$ret" != "0" ]; then
1050 echo "got revert failed unexpectedly" >&2
1051 test_done
"$testroot" "$ret"
1055 (cd $testroot/wt
&& got merge
-c > $testroot/stdout \
1056 2> $testroot/stderr
)
1058 if [ "$ret" == "0" ]; then
1059 echo "got merge succeeded unexpectedly" >&2
1060 test_done
"$testroot" "$ret"
1064 echo -n "got: merge of refs/heads/newbranch cannot proceed: " \
1065 > $testroot/stderr.expected
1066 echo "no changes to commit" >> $testroot/stderr.expected
1067 cmp -s $testroot/stderr.expected
$testroot/stderr
1069 if [ "$ret" != "0" ]; then
1070 diff -u $testroot/stderr.expected
$testroot/stderr
1071 test_done
"$testroot" "$ret"
1075 (cd $testroot/wt
&& got status
> $testroot/stdout
)
1077 echo -n "" > $testroot/stdout.expected
1078 cmp -s $testroot/stdout.expected
$testroot/stdout
1080 if [ "$ret" != "0" ]; then
1081 diff -u $testroot/stdout.expected
$testroot/stdout
1083 test_done
"$testroot" "$ret"
1087 run_test test_merge_basic
1088 run_test test_merge_continue
1089 run_test test_merge_abort
1090 run_test test_merge_in_progress
1091 run_test test_merge_path_prefix
1092 run_test test_merge_missing_file
1093 run_test test_merge_no_op