refactor got log -d and tog diffstat to compute diff once
[got-portable.git] / regress / cmdline / merge.sh
blob43fc62a9959f02a646f8a0777654f8bce35c3878
1 #!/bin/sh
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.
17 . ./common.sh
19 test_merge_basic() {
20 local testroot=`test_init merge_basic`
21 local commit0=`git_show_head $testroot/repo`
22 local commit0_author_time=`git_show_author_time $testroot/repo`
24 (cd $testroot/repo && git checkout -q -b newbranch)
25 echo "modified delta on branch" > $testroot/repo/gamma/delta
26 git_commit $testroot/repo -m "committing to delta on newbranch"
27 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
29 echo "modified alpha on branch" > $testroot/repo/alpha
30 git_commit $testroot/repo -m "committing to alpha on newbranch"
31 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
32 (cd $testroot/repo && git rm -q beta)
33 git_commit $testroot/repo -m "removing beta on newbranch"
34 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
35 echo "new file on branch" > $testroot/repo/epsilon/new
36 (cd $testroot/repo && git add epsilon/new)
37 git_commit $testroot/repo -m "adding new file on newbranch"
38 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
39 (cd $testroot/repo && ln -s alpha symlink && git add symlink)
40 git_commit $testroot/repo -m "adding symlink on newbranch"
41 local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
42 (cd $testroot/repo && ln -sf .got/bar dotgotbar.link)
43 (cd $testroot/repo && git add dotgotbar.link)
44 git_commit $testroot/repo -m "adding a bad symlink on newbranch"
45 local branch_commit5=`git_show_branch_head $testroot/repo newbranch`
47 got checkout -b master $testroot/repo $testroot/wt > /dev/null
48 ret=$?
49 if [ $ret -ne 0 ]; then
50 echo "got checkout failed unexpectedly" >&2
51 test_done "$testroot" "$ret"
52 return 1
55 # need a divergant commit on the main branch for 'got merge'
56 (cd $testroot/wt && got merge newbranch \
57 > $testroot/stdout 2> $testroot/stderr)
58 ret=$?
59 if [ $ret -eq 0 ]; then
60 echo "got merge succeeded unexpectedly" >&2
61 test_done "$testroot" "1"
62 return 1
64 echo -n "got: cannot create a merge commit because " \
65 > $testroot/stderr.expected
66 echo -n "refs/heads/newbranch is based on refs/heads/master; " \
67 >> $testroot/stderr.expected
68 echo -n "refs/heads/newbranch can be integrated with " \
69 >> $testroot/stderr.expected
70 echo "'got integrate' instead" >> $testroot/stderr.expected
71 cmp -s $testroot/stderr.expected $testroot/stderr
72 ret=$?
73 if [ $ret -ne 0 ]; then
74 diff -u $testroot/stderr.expected $testroot/stderr
75 test_done "$testroot" "$ret"
76 return 1
79 # create the required dirvergant commit
80 (cd $testroot/repo && git checkout -q master)
81 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
82 git_commit $testroot/repo -m "committing to zeta on master"
83 local master_commit=`git_show_head $testroot/repo`
85 # need an up-to-date work tree for 'got merge'
86 (cd $testroot/wt && got merge newbranch \
87 > $testroot/stdout 2> $testroot/stderr)
88 ret=$?
89 if [ $ret -eq 0 ]; then
90 echo "got merge succeeded unexpectedly" >&2
91 test_done "$testroot" "$ret"
92 return 1
94 echo -n "got: work tree must be updated before it can be used " \
95 > $testroot/stderr.expected
96 echo "to merge a branch" >> $testroot/stderr.expected
97 cmp -s $testroot/stderr.expected $testroot/stderr
98 ret=$?
99 if [ $ret -ne 0 ]; then
100 diff -u $testroot/stderr.expected $testroot/stderr
101 test_done "$testroot" "$ret"
102 return 1
105 (cd $testroot/wt && got update > /dev/null)
106 ret=$?
107 if [ $ret -ne 0 ]; then
108 echo "got update failed unexpectedly" >&2
109 test_done "$testroot" "$ret"
110 return 1
113 # must not use a mixed-commit work tree with 'got merge'
114 (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
115 ret=$?
116 if [ $ret -ne 0 ]; then
117 echo "got update failed unexpectedly" >&2
118 test_done "$testroot" "$ret"
119 return 1
121 (cd $testroot/wt && got merge newbranch \
122 > $testroot/stdout 2> $testroot/stderr)
123 ret=$?
124 if [ $ret -eq 0 ]; then
125 echo "got merge succeeded unexpectedly" >&2
126 test_done "$testroot" "$ret"
127 return 1
129 echo -n "got: work tree contains files from multiple base commits; " \
130 > $testroot/stderr.expected
131 echo "the entire work tree must be updated first" \
132 >> $testroot/stderr.expected
133 cmp -s $testroot/stderr.expected $testroot/stderr
134 ret=$?
135 if [ $ret -ne 0 ]; then
136 diff -u $testroot/stderr.expected $testroot/stderr
137 test_done "$testroot" "$ret"
138 return 1
141 (cd $testroot/wt && got update > /dev/null)
142 ret=$?
143 if [ $ret -ne 0 ]; then
144 echo "got update failed unexpectedly" >&2
145 test_done "$testroot" "$ret"
146 return 1
149 # must not have staged files with 'got merge'
150 echo "modified file alpha" > $testroot/wt/alpha
151 (cd $testroot/wt && got stage alpha > /dev/null)
152 ret=$?
153 if [ $ret -ne 0 ]; then
154 echo "got stage failed unexpectedly" >&2
155 test_done "$testroot" "$ret"
156 return 1
158 (cd $testroot/wt && got merge newbranch \
159 > $testroot/stdout 2> $testroot/stderr)
160 ret=$?
161 if [ $ret -eq 0 ]; then
162 echo "got merge succeeded unexpectedly" >&2
163 test_done "$testroot" "$ret"
164 return 1
166 echo "got: alpha: file is staged" > $testroot/stderr.expected
167 cmp -s $testroot/stderr.expected $testroot/stderr
168 ret=$?
169 if [ $ret -ne 0 ]; then
170 diff -u $testroot/stderr.expected $testroot/stderr
171 test_done "$testroot" "$ret"
172 return 1
174 (cd $testroot/wt && got unstage alpha > /dev/null)
175 ret=$?
176 if [ $ret -ne 0 ]; then
177 echo "got unstage failed unexpectedly" >&2
178 test_done "$testroot" "$ret"
179 return 1
182 # must not have local changes with 'got merge'
183 (cd $testroot/wt && got merge newbranch \
184 > $testroot/stdout 2> $testroot/stderr)
185 ret=$?
186 if [ $ret -eq 0 ]; then
187 echo "got merge succeeded unexpectedly" >&2
188 test_done "$testroot" "$ret"
189 return 1
191 echo -n "got: work tree contains local changes; " \
192 > $testroot/stderr.expected
193 echo "these changes must be committed or reverted first" \
194 >> $testroot/stderr.expected
195 cmp -s $testroot/stderr.expected $testroot/stderr
196 ret=$?
197 if [ $ret -ne 0 ]; then
198 diff -u $testroot/stderr.expected $testroot/stderr
199 test_done "$testroot" "$ret"
200 return 1
203 (cd $testroot/wt && got revert alpha > /dev/null)
204 ret=$?
205 if [ $ret -ne 0 ]; then
206 echo "got revert failed unexpectedly" >&2
207 test_done "$testroot" "$ret"
208 return 1
211 (cd $testroot/wt && got merge newbranch > $testroot/stdout)
212 ret=$?
213 if [ $ret -ne 0 ]; then
214 echo "got merge failed unexpectedly" >&2
215 test_done "$testroot" "$ret"
216 return 1
219 local merge_commit=`git_show_head $testroot/repo`
221 echo "G alpha" >> $testroot/stdout.expected
222 echo "D beta" >> $testroot/stdout.expected
223 echo "A dotgotbar.link" >> $testroot/stdout.expected
224 echo "A epsilon/new" >> $testroot/stdout.expected
225 echo "G gamma/delta" >> $testroot/stdout.expected
226 echo "A symlink" >> $testroot/stdout.expected
227 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
228 >> $testroot/stdout.expected
229 echo $merge_commit >> $testroot/stdout.expected
231 cmp -s $testroot/stdout.expected $testroot/stdout
232 ret=$?
233 if [ $ret -ne 0 ]; then
234 diff -u $testroot/stdout.expected $testroot/stdout
235 test_done "$testroot" "$ret"
236 return 1
239 echo "modified delta on branch" > $testroot/content.expected
240 cat $testroot/wt/gamma/delta > $testroot/content
241 cmp -s $testroot/content.expected $testroot/content
242 ret=$?
243 if [ $ret -ne 0 ]; then
244 diff -u $testroot/content.expected $testroot/content
245 test_done "$testroot" "$ret"
246 return 1
249 echo "modified alpha on branch" > $testroot/content.expected
250 cat $testroot/wt/alpha > $testroot/content
251 cmp -s $testroot/content.expected $testroot/content
252 ret=$?
253 if [ $ret -ne 0 ]; then
254 diff -u $testroot/content.expected $testroot/content
255 test_done "$testroot" "$ret"
256 return 1
259 if [ -e $testroot/wt/beta ]; then
260 echo "removed file beta still exists on disk" >&2
261 test_done "$testroot" "1"
262 return 1
265 echo "new file on branch" > $testroot/content.expected
266 cat $testroot/wt/epsilon/new > $testroot/content
267 cmp -s $testroot/content.expected $testroot/content
268 ret=$?
269 if [ $ret -ne 0 ]; then
270 diff -u $testroot/content.expected $testroot/content
271 test_done "$testroot" "$ret"
272 return 1
275 if [ ! -h $testroot/wt/dotgotbar.link ]; then
276 echo "dotgotbar.link is not a symlink"
277 test_done "$testroot" "1"
278 return 1
281 readlink $testroot/wt/symlink > $testroot/stdout
282 echo "alpha" > $testroot/stdout.expected
283 cmp -s $testroot/stdout.expected $testroot/stdout
284 ret=$?
285 if [ $ret -ne 0 ]; then
286 diff -u $testroot/stdout.expected $testroot/stdout
287 test_done "$testroot" "$ret"
288 return 1
291 (cd $testroot/wt && got status > $testroot/stdout)
293 echo -n > $testroot/stdout.expected
294 cmp -s $testroot/stdout.expected $testroot/stdout
295 ret=$?
296 if [ $ret -ne 0 ]; then
297 diff -u $testroot/stdout.expected $testroot/stdout
298 test_done "$testroot" "$ret"
299 return 1
302 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
303 echo "commit $merge_commit (master)" > $testroot/stdout.expected
304 echo "commit $master_commit" >> $testroot/stdout.expected
305 echo "commit $commit0" >> $testroot/stdout.expected
306 cmp -s $testroot/stdout.expected $testroot/stdout
307 ret=$?
308 if [ $ret -ne 0 ]; then
309 diff -u $testroot/stdout.expected $testroot/stdout
310 test_done "$testroot" "$ret"
311 return 1
314 (cd $testroot/wt && got update > $testroot/stdout)
316 echo 'U dotgotbar.link' > $testroot/stdout.expected
317 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
318 git_show_head $testroot/repo >> $testroot/stdout.expected
319 echo >> $testroot/stdout.expected
320 cmp -s $testroot/stdout.expected $testroot/stdout
321 ret=$?
322 if [ $ret -ne 0 ]; then
323 diff -u $testroot/stdout.expected $testroot/stdout
324 test_done "$testroot" "$ret"
325 return 1
328 # update has changed the bad symlink into a regular file
329 if [ -h $testroot/wt/dotgotbar.link ]; then
330 echo "dotgotbar.link is a symlink"
331 test_done "$testroot" "1"
332 return 1
335 # We should have created a merge commit with two parents.
336 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
337 echo "parent 1: $master_commit" > $testroot/stdout.expected
338 echo "parent 2: $branch_commit5" >> $testroot/stdout.expected
339 cmp -s $testroot/stdout.expected $testroot/stdout
340 ret=$?
341 if [ $ret -ne 0 ]; then
342 diff -u $testroot/stdout.expected $testroot/stdout
343 test_done "$testroot" "$ret"
344 return 1
347 got tree -r $testroot/repo -c $merge_commit -R > $testroot/stdout
348 ret=$?
349 if [ $ret -ne 0 ]; then
350 echo "got tree failed unexpectedly" >&2
351 test_done "$testroot" "$ret"
352 return 1
355 # bad symlink dotgotbar.link appears as a symlink in the merge commit:
356 cat > $testroot/stdout.expected <<EOF
357 alpha
358 dotgotbar.link@ -> .got/bar
359 epsilon/
360 epsilon/new
361 epsilon/zeta
362 gamma/
363 gamma/delta
364 symlink@ -> alpha
366 cmp -s $testroot/stdout.expected $testroot/stdout
367 ret=$?
368 if [ $ret -ne 0 ]; then
369 diff -u $testroot/stdout.expected $testroot/stdout
371 test_done "$testroot" "$ret"
374 test_merge_continue() {
375 local testroot=`test_init merge_continue`
376 local commit0=`git_show_head $testroot/repo`
377 local commit0_author_time=`git_show_author_time $testroot/repo`
379 (cd $testroot/repo && git checkout -q -b newbranch)
380 echo "modified delta on branch" > $testroot/repo/gamma/delta
381 git_commit $testroot/repo -m "committing to delta on newbranch"
382 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
384 echo "modified alpha on branch" > $testroot/repo/alpha
385 git_commit $testroot/repo -m "committing to alpha on newbranch"
386 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
387 (cd $testroot/repo && git rm -q beta)
388 git_commit $testroot/repo -m "removing beta on newbranch"
389 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
390 echo "new file on branch" > $testroot/repo/epsilon/new
391 (cd $testroot/repo && git add epsilon/new)
392 git_commit $testroot/repo -m "adding new file on newbranch"
393 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
395 got checkout -b master $testroot/repo $testroot/wt > /dev/null
396 ret=$?
397 if [ $ret -ne 0 ]; then
398 echo "got checkout failed unexpectedly" >&2
399 test_done "$testroot" "$ret"
400 return 1
403 # create a conflicting commit
404 (cd $testroot/repo && git checkout -q master)
405 echo "modified alpha on master" > $testroot/repo/alpha
406 git_commit $testroot/repo -m "committing to alpha on master"
407 local master_commit=`git_show_head $testroot/repo`
409 # need an up-to-date work tree for 'got merge'
410 (cd $testroot/wt && got update > /dev/null)
411 ret=$?
412 if [ $ret -ne 0 ]; then
413 echo "got update failed unexpectedly" >&2
414 test_done "$testroot" "$ret"
415 return 1
418 (cd $testroot/wt && got merge newbranch \
419 > $testroot/stdout 2> $testroot/stderr)
420 ret=$?
421 if [ $ret -eq 0 ]; then
422 echo "got merge succeeded unexpectedly" >&2
423 test_done "$testroot" "1"
424 return 1
427 echo "C alpha" >> $testroot/stdout.expected
428 echo "D beta" >> $testroot/stdout.expected
429 echo "A epsilon/new" >> $testroot/stdout.expected
430 echo "G gamma/delta" >> $testroot/stdout.expected
431 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
432 cmp -s $testroot/stdout.expected $testroot/stdout
433 ret=$?
434 if [ $ret -ne 0 ]; then
435 diff -u $testroot/stdout.expected $testroot/stdout
436 test_done "$testroot" "$ret"
437 return 1
440 echo "got: conflicts must be resolved before merging can continue" \
441 > $testroot/stderr.expected
442 cmp -s $testroot/stderr.expected $testroot/stderr
443 ret=$?
444 if [ $ret -ne 0 ]; then
445 diff -u $testroot/stderr.expected $testroot/stderr
446 test_done "$testroot" "$ret"
447 return 1
450 (cd $testroot/wt && got status > $testroot/stdout)
452 echo "C alpha" > $testroot/stdout.expected
453 echo "D beta" >> $testroot/stdout.expected
454 echo "A epsilon/new" >> $testroot/stdout.expected
455 echo "M gamma/delta" >> $testroot/stdout.expected
456 cmp -s $testroot/stdout.expected $testroot/stdout
457 ret=$?
458 if [ $ret -ne 0 ]; then
459 diff -u $testroot/stdout.expected $testroot/stdout
460 test_done "$testroot" "$ret"
461 return 1
464 echo '<<<<<<<' > $testroot/content.expected
465 echo "modified alpha on master" >> $testroot/content.expected
466 echo "||||||| 3-way merge base: commit $commit0" \
467 >> $testroot/content.expected
468 echo "alpha" >> $testroot/content.expected
469 echo "=======" >> $testroot/content.expected
470 echo "modified alpha on branch" >> $testroot/content.expected
471 echo ">>>>>>> merged change: commit $branch_commit3" \
472 >> $testroot/content.expected
473 cat $testroot/wt/alpha > $testroot/content
474 cmp -s $testroot/content.expected $testroot/content
475 ret=$?
476 if [ $ret -ne 0 ]; then
477 diff -u $testroot/content.expected $testroot/content
478 test_done "$testroot" "$ret"
479 return 1
482 # resolve the conflict
483 echo "modified alpha by both branches" > $testroot/wt/alpha
485 (cd $testroot/wt && got merge -c > $testroot/stdout)
486 ret=$?
487 if [ $ret -ne 0 ]; then
488 echo "got merge failed unexpectedly" >&2
489 test_done "$testroot" "$ret"
490 return 1
493 local merge_commit=`git_show_head $testroot/repo`
495 echo "M alpha" > $testroot/stdout.expected
496 echo "D beta" >> $testroot/stdout.expected
497 echo "A epsilon/new" >> $testroot/stdout.expected
498 echo "M gamma/delta" >> $testroot/stdout.expected
499 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
500 >> $testroot/stdout.expected
501 echo $merge_commit >> $testroot/stdout.expected
503 cmp -s $testroot/stdout.expected $testroot/stdout
504 ret=$?
505 if [ $ret -ne 0 ]; then
506 diff -u $testroot/stdout.expected $testroot/stdout
507 test_done "$testroot" "$ret"
508 return 1
511 echo "modified delta on branch" > $testroot/content.expected
512 cat $testroot/wt/gamma/delta > $testroot/content
513 cmp -s $testroot/content.expected $testroot/content
514 ret=$?
515 if [ $ret -ne 0 ]; then
516 diff -u $testroot/content.expected $testroot/content
517 test_done "$testroot" "$ret"
518 return 1
521 echo "modified alpha by both branches" > $testroot/content.expected
522 cat $testroot/wt/alpha > $testroot/content
523 cmp -s $testroot/content.expected $testroot/content
524 ret=$?
525 if [ $ret -ne 0 ]; then
526 diff -u $testroot/content.expected $testroot/content
527 test_done "$testroot" "$ret"
528 return 1
531 if [ -e $testroot/wt/beta ]; then
532 echo "removed file beta still exists on disk" >&2
533 test_done "$testroot" "1"
534 return 1
537 echo "new file on branch" > $testroot/content.expected
538 cat $testroot/wt/epsilon/new > $testroot/content
539 cmp -s $testroot/content.expected $testroot/content
540 ret=$?
541 if [ $ret -ne 0 ]; then
542 diff -u $testroot/content.expected $testroot/content
543 test_done "$testroot" "$ret"
544 return 1
547 (cd $testroot/wt && got status > $testroot/stdout)
549 echo -n > $testroot/stdout.expected
550 cmp -s $testroot/stdout.expected $testroot/stdout
551 ret=$?
552 if [ $ret -ne 0 ]; then
553 diff -u $testroot/stdout.expected $testroot/stdout
554 test_done "$testroot" "$ret"
555 return 1
558 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
559 echo "commit $merge_commit (master)" > $testroot/stdout.expected
560 echo "commit $master_commit" >> $testroot/stdout.expected
561 echo "commit $commit0" >> $testroot/stdout.expected
562 cmp -s $testroot/stdout.expected $testroot/stdout
563 ret=$?
564 if [ $ret -ne 0 ]; then
565 diff -u $testroot/stdout.expected $testroot/stdout
566 test_done "$testroot" "$ret"
567 return 1
570 (cd $testroot/wt && got update > $testroot/stdout)
572 echo 'Already up-to-date' > $testroot/stdout.expected
573 cmp -s $testroot/stdout.expected $testroot/stdout
574 ret=$?
575 if [ $ret -ne 0 ]; then
576 diff -u $testroot/stdout.expected $testroot/stdout
577 test_done "$testroot" "$ret"
578 return 1
581 # We should have created a merge commit with two parents.
582 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
583 echo "parent 1: $master_commit" > $testroot/stdout.expected
584 echo "parent 2: $branch_commit3" >> $testroot/stdout.expected
585 cmp -s $testroot/stdout.expected $testroot/stdout
586 ret=$?
587 if [ $ret -ne 0 ]; then
588 diff -u $testroot/stdout.expected $testroot/stdout
590 test_done "$testroot" "$ret"
593 test_merge_abort() {
594 local testroot=`test_init merge_abort`
595 local commit0=`git_show_head $testroot/repo`
596 local commit0_author_time=`git_show_author_time $testroot/repo`
598 (cd $testroot/repo && git checkout -q -b newbranch)
599 echo "modified delta on branch" > $testroot/repo/gamma/delta
600 git_commit $testroot/repo -m "committing to delta on newbranch"
601 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
603 echo "modified alpha on branch" > $testroot/repo/alpha
604 git_commit $testroot/repo -m "committing to alpha on newbranch"
605 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
606 (cd $testroot/repo && git rm -q beta)
607 git_commit $testroot/repo -m "removing beta on newbranch"
608 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
609 echo "new file on branch" > $testroot/repo/epsilon/new
610 (cd $testroot/repo && git add epsilon/new)
611 git_commit $testroot/repo -m "adding new file on newbranch"
612 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
613 (cd $testroot/repo && ln -s alpha symlink && git add symlink)
614 git_commit $testroot/repo -m "adding symlink on newbranch"
615 local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
617 got checkout -b master $testroot/repo $testroot/wt > /dev/null
618 ret=$?
619 if [ $ret -ne 0 ]; then
620 echo "got checkout failed unexpectedly" >&2
621 test_done "$testroot" "$ret"
622 return 1
625 # unrelated unversioned file in work tree
626 touch $testroot/wt/unversioned-file
628 # create a conflicting commit
629 (cd $testroot/repo && git checkout -q master)
630 echo "modified alpha on master" > $testroot/repo/alpha
631 git_commit $testroot/repo -m "committing to alpha on master"
632 local master_commit=`git_show_head $testroot/repo`
634 # need an up-to-date work tree for 'got merge'
635 (cd $testroot/wt && got update > /dev/null)
636 ret=$?
637 if [ $ret -ne 0 ]; then
638 echo "got update failed unexpectedly" >&2
639 test_done "$testroot" "$ret"
640 return 1
643 (cd $testroot/wt && got merge newbranch \
644 > $testroot/stdout 2> $testroot/stderr)
645 ret=$?
646 if [ $ret -eq 0 ]; then
647 echo "got merge succeeded unexpectedly" >&2
648 test_done "$testroot" "1"
649 return 1
652 echo "C alpha" >> $testroot/stdout.expected
653 echo "D beta" >> $testroot/stdout.expected
654 echo "A epsilon/new" >> $testroot/stdout.expected
655 echo "G gamma/delta" >> $testroot/stdout.expected
656 echo "A symlink" >> $testroot/stdout.expected
657 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
658 cmp -s $testroot/stdout.expected $testroot/stdout
659 ret=$?
660 if [ $ret -ne 0 ]; then
661 diff -u $testroot/stdout.expected $testroot/stdout
662 test_done "$testroot" "$ret"
663 return 1
666 echo "got: conflicts must be resolved before merging can continue" \
667 > $testroot/stderr.expected
668 cmp -s $testroot/stderr.expected $testroot/stderr
669 ret=$?
670 if [ $ret -ne 0 ]; then
671 diff -u $testroot/stderr.expected $testroot/stderr
672 test_done "$testroot" "$ret"
673 return 1
676 (cd $testroot/wt && got status > $testroot/stdout)
678 echo "C alpha" > $testroot/stdout.expected
679 echo "D beta" >> $testroot/stdout.expected
680 echo "A epsilon/new" >> $testroot/stdout.expected
681 echo "M gamma/delta" >> $testroot/stdout.expected
682 echo "A symlink" >> $testroot/stdout.expected
683 echo "? unversioned-file" >> $testroot/stdout.expected
684 cmp -s $testroot/stdout.expected $testroot/stdout
685 ret=$?
686 if [ $ret -ne 0 ]; then
687 diff -u $testroot/stdout.expected $testroot/stdout
688 test_done "$testroot" "$ret"
689 return 1
692 (cd $testroot/wt && got merge -a > $testroot/stdout)
693 ret=$?
694 if [ $ret -ne 0 ]; then
695 echo "got merge failed unexpectedly" >&2
696 test_done "$testroot" "$ret"
697 return 1
700 echo "R alpha" > $testroot/stdout.expected
701 echo "R beta" >> $testroot/stdout.expected
702 echo "R epsilon/new" >> $testroot/stdout.expected
703 echo "R gamma/delta" >> $testroot/stdout.expected
704 echo "R symlink" >> $testroot/stdout.expected
705 echo "Merge of refs/heads/newbranch aborted" \
706 >> $testroot/stdout.expected
708 cmp -s $testroot/stdout.expected $testroot/stdout
709 ret=$?
710 if [ $ret -ne 0 ]; then
711 diff -u $testroot/stdout.expected $testroot/stdout
712 test_done "$testroot" "$ret"
713 return 1
716 echo "delta" > $testroot/content.expected
717 cat $testroot/wt/gamma/delta > $testroot/content
718 cmp -s $testroot/content.expected $testroot/content
719 ret=$?
720 if [ $ret -ne 0 ]; then
721 diff -u $testroot/content.expected $testroot/content
722 test_done "$testroot" "$ret"
723 return 1
726 echo "modified alpha on master" > $testroot/content.expected
727 cat $testroot/wt/alpha > $testroot/content
728 cmp -s $testroot/content.expected $testroot/content
729 ret=$?
730 if [ $ret -ne 0 ]; then
731 diff -u $testroot/content.expected $testroot/content
732 test_done "$testroot" "$ret"
733 return 1
736 echo "beta" > $testroot/content.expected
737 cat $testroot/wt/beta > $testroot/content
738 cmp -s $testroot/content.expected $testroot/content
739 ret=$?
740 if [ $ret -ne 0 ]; then
741 diff -u $testroot/content.expected $testroot/content
742 test_done "$testroot" "$ret"
743 return 1
746 if [ -e $testroot/wt/epsilon/new ]; then
747 echo "reverted file epsilon/new still exists on disk" >&2
748 test_done "$testroot" "1"
749 return 1
752 if [ -e $testroot/wt/symlink ]; then
753 echo "reverted symlink still exists on disk" >&2
754 test_done "$testroot" "1"
755 return 1
758 (cd $testroot/wt && got status > $testroot/stdout)
760 echo "? unversioned-file" > $testroot/stdout.expected
761 cmp -s $testroot/stdout.expected $testroot/stdout
762 ret=$?
763 if [ $ret -ne 0 ]; then
764 diff -u $testroot/stdout.expected $testroot/stdout
765 test_done "$testroot" "$ret"
766 return 1
769 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
770 echo "commit $master_commit (master)" > $testroot/stdout.expected
771 echo "commit $commit0" >> $testroot/stdout.expected
772 cmp -s $testroot/stdout.expected $testroot/stdout
773 ret=$?
774 if [ $ret -ne 0 ]; then
775 diff -u $testroot/stdout.expected $testroot/stdout
776 test_done "$testroot" "$ret"
777 return 1
780 (cd $testroot/wt && got update > $testroot/stdout)
782 echo 'Already up-to-date' > $testroot/stdout.expected
783 cmp -s $testroot/stdout.expected $testroot/stdout
784 ret=$?
785 if [ $ret -ne 0 ]; then
786 diff -u $testroot/stdout.expected $testroot/stdout
788 test_done "$testroot" "$ret"
791 test_merge_in_progress() {
792 local testroot=`test_init merge_in_progress`
793 local commit0=`git_show_head $testroot/repo`
794 local commit0_author_time=`git_show_author_time $testroot/repo`
796 (cd $testroot/repo && git checkout -q -b newbranch)
797 echo "modified alpha on branch" > $testroot/repo/alpha
798 git_commit $testroot/repo -m "committing to alpha on newbranch"
799 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
801 got checkout -b master $testroot/repo $testroot/wt > /dev/null
802 ret=$?
803 if [ $ret -ne 0 ]; then
804 echo "got checkout failed unexpectedly" >&2
805 test_done "$testroot" "$ret"
806 return 1
809 # create a conflicting commit
810 (cd $testroot/repo && git checkout -q master)
811 echo "modified alpha on master" > $testroot/repo/alpha
812 git_commit $testroot/repo -m "committing to alpha on master"
813 local master_commit=`git_show_head $testroot/repo`
815 # need an up-to-date work tree for 'got merge'
816 (cd $testroot/wt && got update > /dev/null)
817 ret=$?
818 if [ $ret -ne 0 ]; then
819 echo "got update failed unexpectedly" >&2
820 test_done "$testroot" "$ret"
821 return 1
824 (cd $testroot/wt && got merge newbranch \
825 > $testroot/stdout 2> $testroot/stderr)
826 ret=$?
827 if [ $ret -eq 0 ]; then
828 echo "got merge succeeded unexpectedly" >&2
829 test_done "$testroot" "1"
830 return 1
833 echo "C alpha" >> $testroot/stdout.expected
834 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
835 cmp -s $testroot/stdout.expected $testroot/stdout
836 ret=$?
837 if [ $ret -ne 0 ]; then
838 diff -u $testroot/stdout.expected $testroot/stdout
839 test_done "$testroot" "$ret"
840 return 1
843 echo "got: conflicts must be resolved before merging can continue" \
844 > $testroot/stderr.expected
845 cmp -s $testroot/stderr.expected $testroot/stderr
846 ret=$?
847 if [ $ret -ne 0 ]; then
848 diff -u $testroot/stderr.expected $testroot/stderr
849 test_done "$testroot" "$ret"
850 return 1
853 (cd $testroot/wt && got status > $testroot/stdout)
855 echo "C alpha" > $testroot/stdout.expected
856 cmp -s $testroot/stdout.expected $testroot/stdout
857 ret=$?
858 if [ $ret -ne 0 ]; then
859 diff -u $testroot/stdout.expected $testroot/stdout
860 test_done "$testroot" "$ret"
861 return 1
864 for cmd in update commit histedit "rebase newbranch" \
865 "integrate newbranch" "stage alpha"; do
866 (cd $testroot/wt && got $cmd > $testroot/stdout \
867 2> $testroot/stderr)
869 echo -n > $testroot/stdout.expected
870 cmp -s $testroot/stdout.expected $testroot/stdout
871 ret=$?
872 if [ $ret -ne 0 ]; then
873 diff -u $testroot/stdout.expected $testroot/stdout
874 test_done "$testroot" "$ret"
875 return 1
878 echo -n "got: a merge operation is in progress in this " \
879 > $testroot/stderr.expected
880 echo "work tree and must be continued or aborted first" \
881 >> $testroot/stderr.expected
882 cmp -s $testroot/stderr.expected $testroot/stderr
883 ret=$?
884 if [ $ret -ne 0 ]; then
885 diff -u $testroot/stderr.expected $testroot/stderr
886 test_done "$testroot" "$ret"
887 return 1
889 done
891 test_done "$testroot" "$ret"
894 test_merge_path_prefix() {
895 local testroot=`test_init merge_path_prefix`
896 local commit0=`git_show_head $testroot/repo`
897 local commit0_author_time=`git_show_author_time $testroot/repo`
899 (cd $testroot/repo && git checkout -q -b newbranch)
900 echo "modified alpha on branch" > $testroot/repo/alpha
901 git_commit $testroot/repo -m "committing to alpha on newbranch"
902 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
904 got checkout -p epsilon -b master $testroot/repo $testroot/wt \
905 > /dev/null
906 ret=$?
907 if [ $ret -ne 0 ]; then
908 echo "got checkout failed unexpectedly" >&2
909 test_done "$testroot" "$ret"
910 return 1
913 # create a conflicting commit
914 (cd $testroot/repo && git checkout -q master)
915 echo "modified alpha on master" > $testroot/repo/alpha
916 git_commit $testroot/repo -m "committing to alpha on master"
917 local master_commit=`git_show_head $testroot/repo`
919 # need an up-to-date work tree for 'got merge'
920 (cd $testroot/wt && got update > /dev/null)
921 ret=$?
922 if [ $ret -ne 0 ]; then
923 echo "got update failed unexpectedly" >&2
924 test_done "$testroot" "$ret"
925 return 1
928 (cd $testroot/wt && got merge newbranch \
929 > $testroot/stdout 2> $testroot/stderr)
930 ret=$?
931 if [ $ret -eq 0 ]; then
932 echo "got merge succeeded unexpectedly" >&2
933 test_done "$testroot" "1"
934 return 1
937 echo -n "got: cannot merge branch which contains changes outside " \
938 > $testroot/stderr.expected
939 echo "of this work tree's path prefix" >> $testroot/stderr.expected
940 cmp -s $testroot/stderr.expected $testroot/stderr
941 ret=$?
942 if [ $ret -ne 0 ]; then
943 diff -u $testroot/stderr.expected $testroot/stderr
945 test_done "$testroot" "$ret"
948 test_merge_missing_file() {
949 local testroot=`test_init merge_missing_file`
950 local commit0=`git_show_head $testroot/repo`
951 local commit0_author_time=`git_show_author_time $testroot/repo`
953 (cd $testroot/repo && git checkout -q -b newbranch)
954 echo "modified alpha on branch" > $testroot/repo/alpha
955 echo "modified delta on branch" > $testroot/repo/gamma/delta
956 git_commit $testroot/repo -m "committing to alpha and delta"
957 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
959 got checkout -b master $testroot/repo $testroot/wt > /dev/null
960 ret=$?
961 if [ $ret -ne 0 ]; then
962 echo "got checkout failed unexpectedly" >&2
963 test_done "$testroot" "$ret"
964 return 1
967 # create a conflicting commit which renames alpha
968 (cd $testroot/repo && git checkout -q master)
969 (cd $testroot/repo && git mv alpha epsilon/alpha-moved)
970 git_commit $testroot/repo -m "moving alpha on master"
971 local master_commit=`git_show_head $testroot/repo`
973 # need an up-to-date work tree for 'got merge'
974 (cd $testroot/wt && got update > /dev/null)
975 ret=$?
976 if [ $ret -ne 0 ]; then
977 echo "got update failed unexpectedly" >&2
978 test_done "$testroot" "$ret"
979 return 1
982 (cd $testroot/wt && got merge newbranch \
983 > $testroot/stdout 2> $testroot/stderr)
984 ret=$?
985 if [ $ret -eq 0 ]; then
986 echo "got merge succeeded unexpectedly" >&2
987 test_done "$testroot" "1"
988 return 1
991 echo "! alpha" > $testroot/stdout.expected
992 echo "G gamma/delta" >> $testroot/stdout.expected
993 echo -n "Files which had incoming changes but could not be found " \
994 >> $testroot/stdout.expected
995 echo "in the work tree: 1" >> $testroot/stdout.expected
996 cmp -s $testroot/stdout.expected $testroot/stdout
997 ret=$?
998 if [ $ret -ne 0 ]; then
999 diff -u $testroot/stdout.expected $testroot/stdout
1000 test_done "$testroot" "$ret"
1001 return 1
1004 echo -n "got: changes destined for some files " \
1005 > $testroot/stderr.expected
1006 echo -n "were not yet merged and should be merged manually if " \
1007 >> $testroot/stderr.expected
1008 echo "required before the merge operation is continued" \
1009 >> $testroot/stderr.expected
1010 cmp -s $testroot/stderr.expected $testroot/stderr
1011 ret=$?
1012 if [ $ret -ne 0 ]; then
1013 diff -u $testroot/stderr.expected $testroot/stderr
1014 test_done "$testroot" "$ret"
1015 return 1
1018 (cd $testroot/wt && got status > $testroot/stdout)
1020 echo "M gamma/delta" > $testroot/stdout.expected
1021 cmp -s $testroot/stdout.expected $testroot/stdout
1022 ret=$?
1023 if [ $ret -ne 0 ]; then
1024 diff -u $testroot/stdout.expected $testroot/stdout
1025 test_done "$testroot" "$ret"
1026 return 1
1029 test_done "$testroot" "$ret"
1032 test_merge_no_op() {
1033 local testroot=`test_init merge_no_op`
1034 local commit0=`git_show_head $testroot/repo`
1035 local commit0_author_time=`git_show_author_time $testroot/repo`
1037 (cd $testroot/repo && git checkout -q -b newbranch)
1038 echo "modified alpha on branch" > $testroot/repo/alpha
1039 git_commit $testroot/repo -m "committing to alpha on newbranch"
1040 local branch_commitk=`git_show_branch_head $testroot/repo newbranch`
1042 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1043 ret=$?
1044 if [ $ret -ne 0 ]; then
1045 echo "got checkout failed unexpectedly" >&2
1046 test_done "$testroot" "$ret"
1047 return 1
1050 # create a conflicting commit
1051 (cd $testroot/repo && git checkout -q master)
1052 echo "modified alpha on master" > $testroot/repo/alpha
1053 git_commit $testroot/repo -m "committing to alpha on master"
1054 local master_commit=`git_show_head $testroot/repo`
1056 # need an up-to-date work tree for 'got merge'
1057 (cd $testroot/wt && got update > /dev/null)
1058 ret=$?
1059 if [ $ret -ne 0 ]; then
1060 echo "got update failed unexpectedly" >&2
1061 test_done "$testroot" "$ret"
1062 return 1
1065 (cd $testroot/wt && got merge newbranch \
1066 > $testroot/stdout 2> $testroot/stderr)
1067 ret=$?
1068 if [ $ret -eq 0 ]; then
1069 echo "got merge succeeded unexpectedly" >&2
1070 test_done "$testroot" "1"
1071 return 1
1074 echo "C alpha" >> $testroot/stdout.expected
1075 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1076 cmp -s $testroot/stdout.expected $testroot/stdout
1077 ret=$?
1078 if [ $ret -ne 0 ]; then
1079 diff -u $testroot/stdout.expected $testroot/stdout
1080 test_done "$testroot" "$ret"
1081 return 1
1084 echo "got: conflicts must be resolved before merging can continue" \
1085 > $testroot/stderr.expected
1086 cmp -s $testroot/stderr.expected $testroot/stderr
1087 ret=$?
1088 if [ $ret -ne 0 ]; then
1089 diff -u $testroot/stderr.expected $testroot/stderr
1090 test_done "$testroot" "$ret"
1091 return 1
1094 (cd $testroot/wt && got status > $testroot/stdout)
1096 echo "C alpha" > $testroot/stdout.expected
1097 cmp -s $testroot/stdout.expected $testroot/stdout
1098 ret=$?
1099 if [ $ret -ne 0 ]; then
1100 diff -u $testroot/stdout.expected $testroot/stdout
1101 test_done "$testroot" "$ret"
1102 return 1
1105 # resolve the conflict by reverting all changes; now it is no-op merge
1106 (cd $testroot/wt && got revert alpha > /dev/null)
1107 ret=$?
1108 if [ $ret -ne 0 ]; then
1109 echo "got revert failed unexpectedly" >&2
1110 test_done "$testroot" "$ret"
1111 return 1
1114 (cd $testroot/wt && got merge -c > $testroot/stdout \
1115 2> $testroot/stderr)
1116 ret=$?
1117 if [ $ret -eq 0 ]; then
1118 echo "got merge succeeded unexpectedly" >&2
1119 test_done "$testroot" "$ret"
1120 return 1
1123 echo -n "got: merge of refs/heads/newbranch cannot proceed: " \
1124 > $testroot/stderr.expected
1125 echo "no changes to commit" >> $testroot/stderr.expected
1126 cmp -s $testroot/stderr.expected $testroot/stderr
1127 ret=$?
1128 if [ $ret -ne 0 ]; then
1129 diff -u $testroot/stderr.expected $testroot/stderr
1130 test_done "$testroot" "$ret"
1131 return 1
1134 (cd $testroot/wt && got status > $testroot/stdout)
1136 echo -n "" > $testroot/stdout.expected
1137 cmp -s $testroot/stdout.expected $testroot/stdout
1138 ret=$?
1139 if [ $ret -ne 0 ]; then
1140 diff -u $testroot/stdout.expected $testroot/stdout
1142 test_done "$testroot" "$ret"
1145 test_merge_imported_branch() {
1146 local testroot=`test_init merge_import`
1147 local commit0=`git_show_head $testroot/repo`
1148 local commit0_author_time=`git_show_author_time $testroot/repo`
1150 # import a new sub-tree to the 'files' branch such that
1151 # none of the files added here collide with existing ones
1152 mkdir -p $testroot/tree/there
1153 mkdir -p $testroot/tree/be/lots
1154 mkdir -p $testroot/tree/files
1155 echo "there should" > $testroot/tree/there/should
1156 echo "be lots of" > $testroot/tree/be/lots/of
1157 echo "files here" > $testroot/tree/files/here
1158 got import -r $testroot/repo -b files -m 'import files' \
1159 $testroot/tree > /dev/null
1161 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1162 ret=$?
1163 if [ $ret -ne 0 ]; then
1164 echo "got checkout failed unexpectedly" >&2
1165 test_done "$testroot" "$ret"
1166 return 1
1169 (cd $testroot/wt && got merge files > $testroot/stdout)
1170 ret=$?
1171 if [ $ret -ne 0 ]; then
1172 echo "got merge failed unexpectedly" >&2
1173 test_done "$testroot" "$ret"
1174 return 1
1177 local merge_commit0=`git_show_head $testroot/repo`
1178 cat > $testroot/stdout.expected <<EOF
1179 A be/lots/of
1180 A files/here
1181 A there/should
1182 Merged refs/heads/files into refs/heads/master: $merge_commit0
1184 cmp -s $testroot/stdout.expected $testroot/stdout
1185 ret=$?
1186 if [ $ret -ne 0 ]; then
1187 diff -u $testroot/stdout.expected $testroot/stdout
1188 test_done "$testroot" "$ret"
1189 return 1
1192 # try to merge again while no new changes are available
1193 (cd $testroot/wt && got merge files > $testroot/stdout)
1194 ret=$?
1195 if [ $ret -ne 0 ]; then
1196 echo "got merge failed unexpectedly" >&2
1197 test_done "$testroot" "$ret"
1198 return 1
1200 echo "Already up-to-date" > $testroot/stdout.expected
1201 cmp -s $testroot/stdout.expected $testroot/stdout
1202 ret=$?
1203 if [ $ret -ne 0 ]; then
1204 diff -u $testroot/stdout.expected $testroot/stdout
1205 test_done "$testroot" "$ret"
1206 return 1
1209 # update the 'files' branch
1210 (cd $testroot/repo && git reset -q --hard master)
1211 (cd $testroot/repo && git checkout -q files)
1212 echo "indeed" > $testroot/repo/indeed
1213 (cd $testroot/repo && git add indeed)
1214 git_commit $testroot/repo -m "adding another file indeed"
1215 echo "be lots and lots of" > $testroot/repo/be/lots/of
1216 git_commit $testroot/repo -m "lots of changes"
1218 (cd $testroot/wt && got update > /dev/null)
1219 ret=$?
1220 if [ $ret -ne 0 ]; then
1221 echo "got update failed unexpectedly" >&2
1222 test_done "$testroot" "$ret"
1223 return 1
1226 # we should now be able to merge more changes from files branch
1227 (cd $testroot/wt && got merge files > $testroot/stdout)
1228 ret=$?
1229 if [ $ret -ne 0 ]; then
1230 echo "got merge failed unexpectedly" >&2
1231 test_done "$testroot" "$ret"
1232 return 1
1235 local merge_commit1=`git_show_branch_head $testroot/repo master`
1236 cat > $testroot/stdout.expected <<EOF
1237 G be/lots/of
1238 A indeed
1239 Merged refs/heads/files into refs/heads/master: $merge_commit1
1242 cmp -s $testroot/stdout.expected $testroot/stdout
1243 ret=$?
1244 if [ $ret -ne 0 ]; then
1245 diff -u $testroot/stdout.expected $testroot/stdout
1247 test_done "$testroot" "$ret"
1250 test_merge_interrupt() {
1251 local testroot=`test_init merge_interrupt`
1252 local commit0=`git_show_head $testroot/repo`
1253 local commit0_author_time=`git_show_author_time $testroot/repo`
1255 (cd $testroot/repo && git checkout -q -b newbranch)
1256 echo "modified alpha on branch" > $testroot/repo/alpha
1257 git_commit $testroot/repo -m "committing to alpha on newbranch"
1258 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1260 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1261 ret=$?
1262 if [ $ret -ne 0 ]; then
1263 echo "got checkout failed unexpectedly" >&2
1264 test_done "$testroot" "$ret"
1265 return 1
1268 # create a non-conflicting commit
1269 (cd $testroot/repo && git checkout -q master)
1270 echo "modified beta on master" > $testroot/repo/beta
1271 git_commit $testroot/repo -m "committing to beta on master"
1272 local master_commit=`git_show_head $testroot/repo`
1274 # need an up-to-date work tree for 'got merge'
1275 (cd $testroot/wt && got update > /dev/null)
1276 ret=$?
1277 if [ $ret -ne 0 ]; then
1278 echo "got update failed unexpectedly" >&2
1279 test_done "$testroot" "$ret"
1280 return 1
1283 (cd $testroot/wt && got merge -n newbranch \
1284 > $testroot/stdout 2> $testroot/stderr)
1285 ret=$?
1286 if [ $ret -ne 0 ]; then
1287 echo "got merge failed unexpectedly" >&2
1288 test_done "$testroot" "1"
1289 return 1
1292 echo "G alpha" > $testroot/stdout.expected
1293 echo "Merge of refs/heads/newbranch interrupted on request" \
1294 >> $testroot/stdout.expected
1295 cmp -s $testroot/stdout.expected $testroot/stdout
1296 ret=$?
1297 if [ $ret -ne 0 ]; then
1298 diff -u $testroot/stdout.expected $testroot/stdout
1299 test_done "$testroot" "$ret"
1300 return 1
1303 (cd $testroot/wt && got status > $testroot/stdout)
1305 echo "M alpha" > $testroot/stdout.expected
1306 cmp -s $testroot/stdout.expected $testroot/stdout
1307 ret=$?
1308 if [ $ret -ne 0 ]; then
1309 diff -u $testroot/stdout.expected $testroot/stdout
1310 test_done "$testroot" "$ret"
1311 return 1
1314 echo "modified alpha on branch" > $testroot/content.expected
1315 cat $testroot/wt/alpha > $testroot/content
1316 cmp -s $testroot/content.expected $testroot/content
1317 ret=$?
1318 if [ $ret -ne 0 ]; then
1319 diff -u $testroot/content.expected $testroot/content
1320 test_done "$testroot" "$ret"
1321 return 1
1324 # adjust merge result
1325 echo "adjusted merge result" > $testroot/wt/alpha
1327 # continue the merge
1328 (cd $testroot/wt && got merge -c > $testroot/stdout)
1329 ret=$?
1330 if [ $ret -ne 0 ]; then
1331 echo "got merge failed unexpectedly" >&2
1332 test_done "$testroot" "$ret"
1333 return 1
1336 local merge_commit=`git_show_head $testroot/repo`
1338 echo "M alpha" > $testroot/stdout.expected
1339 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1340 >> $testroot/stdout.expected
1341 echo $merge_commit >> $testroot/stdout.expected
1343 cmp -s $testroot/stdout.expected $testroot/stdout
1344 ret=$?
1345 if [ $ret -ne 0 ]; then
1346 diff -u $testroot/stdout.expected $testroot/stdout
1347 test_done "$testroot" "$ret"
1348 return 1
1351 (cd $testroot/wt && got status > $testroot/stdout)
1353 echo -n > $testroot/stdout.expected
1354 cmp -s $testroot/stdout.expected $testroot/stdout
1355 ret=$?
1356 if [ $ret -ne 0 ]; then
1357 diff -u $testroot/stdout.expected $testroot/stdout
1358 test_done "$testroot" "$ret"
1359 return 1
1362 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1363 echo "commit $merge_commit (master)" > $testroot/stdout.expected
1364 echo "commit $master_commit" >> $testroot/stdout.expected
1365 echo "commit $commit0" >> $testroot/stdout.expected
1366 cmp -s $testroot/stdout.expected $testroot/stdout
1367 ret=$?
1368 if [ $ret -ne 0 ]; then
1369 diff -u $testroot/stdout.expected $testroot/stdout
1370 test_done "$testroot" "$ret"
1371 return 1
1374 (cd $testroot/wt && got update > $testroot/stdout)
1376 echo 'Already up-to-date' > $testroot/stdout.expected
1377 cmp -s $testroot/stdout.expected $testroot/stdout
1378 ret=$?
1379 if [ $ret -ne 0 ]; then
1380 diff -u $testroot/stdout.expected $testroot/stdout
1381 test_done "$testroot" "$ret"
1382 return 1
1385 # We should have created a merge commit with two parents.
1386 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
1387 echo "parent 1: $master_commit" > $testroot/stdout.expected
1388 echo "parent 2: $branch_commit0" >> $testroot/stdout.expected
1389 cmp -s $testroot/stdout.expected $testroot/stdout
1390 ret=$?
1391 if [ $ret -ne 0 ]; then
1392 diff -u $testroot/stdout.expected $testroot/stdout
1394 test_done "$testroot" "$ret"
1397 test_merge_umask() {
1398 local testroot=`test_init merge_umask`
1400 (cd $testroot/repo && git checkout -q -b newbranch)
1401 echo "modified alpha on branch" >$testroot/repo/alpha
1402 git_commit "$testroot/repo" -m "committing alpha on newbranch"
1403 echo "modified delta on branch" >$testroot/repo/gamma/delta
1404 git_commit "$testroot/repo" -m "committing delta on newbranch"
1406 # diverge from newbranch
1407 (cd "$testroot/repo" && git checkout -q master)
1408 echo "modified beta on master" >$testroot/repo/beta
1409 git_commit "$testroot/repo" -m "committing zeto no master"
1411 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1413 # using a subshell to avoid clobbering global umask
1414 (umask 077 && cd "$testroot/wt" && got merge newbranch) >/dev/null
1416 for f in alpha gamma/delta; do
1417 ls -l "$testroot/wt/$f" | grep -q ^-rw-------
1418 if [ $? -ne 0 ]; then
1419 echo "$f is not 0600 after merge" >&2
1420 ls -l "$testroot/wt/$f" >&2
1421 test_done "$testroot" 1
1423 done
1425 test_done "$testroot" 0
1428 test_parseargs "$@"
1429 run_test test_merge_basic
1430 run_test test_merge_continue
1431 run_test test_merge_abort
1432 run_test test_merge_in_progress
1433 run_test test_merge_path_prefix
1434 run_test test_merge_missing_file
1435 run_test test_merge_no_op
1436 run_test test_merge_imported_branch
1437 run_test test_merge_interrupt
1438 run_test test_merge_umask