Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
4 #
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.
8 #
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 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
49 ret=$?
50 if [ $ret -ne 0 ]; then
51 echo "got checkout failed unexpectedly" >&2
52 test_done "$testroot" "$ret"
53 return 1
54 fi
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)
65 ret=$?
66 if [ $ret -eq 0 ]; then
67 echo "got merge succeeded unexpectedly" >&2
68 test_done "$testroot" "1"
69 return 1
70 fi
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
75 ret=$?
76 if [ $ret -ne 0 ]; then
77 diff -u $testroot/stderr.expected $testroot/stderr
78 test_done "$testroot" "$ret"
79 return 1
80 fi
82 (cd $testroot/wt && got update > /dev/null)
83 ret=$?
84 if [ $ret -ne 0 ]; then
85 echo "got update failed unexpectedly" >&2
86 test_done "$testroot" "$ret"
87 return 1
88 fi
90 # must not use a mixed-commit work tree with 'got merge'
91 (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
92 ret=$?
93 if [ $ret -ne 0 ]; then
94 echo "got update failed unexpectedly" >&2
95 test_done "$testroot" "$ret"
96 return 1
97 fi
98 (cd $testroot/wt && got merge newbranch \
99 > $testroot/stdout 2> $testroot/stderr)
100 ret=$?
101 if [ $ret -eq 0 ]; then
102 echo "got merge succeeded unexpectedly" >&2
103 test_done "$testroot" "1"
104 return 1
105 fi
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
111 ret=$?
112 if [ $ret -ne 0 ]; then
113 diff -u $testroot/stderr.expected $testroot/stderr
114 test_done "$testroot" "$ret"
115 return 1
116 fi
118 (cd $testroot/wt && got update > /dev/null)
119 ret=$?
120 if [ $ret -ne 0 ]; then
121 echo "got update failed unexpectedly" >&2
122 test_done "$testroot" "$ret"
123 return 1
124 fi
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)
129 ret=$?
130 if [ $ret -ne 0 ]; then
131 echo "got stage failed unexpectedly" >&2
132 test_done "$testroot" "$ret"
133 return 1
134 fi
135 (cd $testroot/wt && got merge newbranch \
136 > $testroot/stdout 2> $testroot/stderr)
137 ret=$?
138 if [ $ret -eq 0 ]; then
139 echo "got merge succeeded unexpectedly" >&2
140 test_done "$testroot" "1"
141 return 1
142 fi
143 echo "got: alpha: file is staged" > $testroot/stderr.expected
144 cmp -s $testroot/stderr.expected $testroot/stderr
145 ret=$?
146 if [ $ret -ne 0 ]; then
147 diff -u $testroot/stderr.expected $testroot/stderr
148 test_done "$testroot" "$ret"
149 return 1
150 fi
151 (cd $testroot/wt && got unstage alpha > /dev/null)
152 ret=$?
153 if [ $ret -ne 0 ]; then
154 echo "got unstage failed unexpectedly" >&2
155 test_done "$testroot" "$ret"
156 return 1
157 fi
159 # must not have local changes with 'got merge'
160 (cd $testroot/wt && got merge newbranch \
161 > $testroot/stdout 2> $testroot/stderr)
162 ret=$?
163 if [ $ret -eq 0 ]; then
164 echo "got merge succeeded unexpectedly" >&2
165 test_done "$testroot" "1"
166 return 1
167 fi
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
173 ret=$?
174 if [ $ret -ne 0 ]; then
175 diff -u $testroot/stderr.expected $testroot/stderr
176 test_done "$testroot" "$ret"
177 return 1
178 fi
180 (cd $testroot/wt && got revert alpha > /dev/null)
181 ret=$?
182 if [ $ret -ne 0 ]; then
183 echo "got revert failed unexpectedly" >&2
184 test_done "$testroot" "$ret"
185 return 1
186 fi
188 (cd $testroot/wt && got merge newbranch > $testroot/stdout)
189 ret=$?
190 if [ $ret -ne 0 ]; then
191 echo "got merge failed unexpectedly" >&2
192 test_done "$testroot" "$ret"
193 return 1
194 fi
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
209 ret=$?
210 if [ $ret -ne 0 ]; then
211 diff -u $testroot/stdout.expected $testroot/stdout
212 test_done "$testroot" "$ret"
213 return 1
214 fi
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
219 ret=$?
220 if [ $ret -ne 0 ]; then
221 diff -u $testroot/content.expected $testroot/content
222 test_done "$testroot" "$ret"
223 return 1
224 fi
226 echo "modified alpha on branch" > $testroot/content.expected
227 cat $testroot/wt/alpha > $testroot/content
228 cmp -s $testroot/content.expected $testroot/content
229 ret=$?
230 if [ $ret -ne 0 ]; then
231 diff -u $testroot/content.expected $testroot/content
232 test_done "$testroot" "$ret"
233 return 1
234 fi
236 if [ -e $testroot/wt/beta ]; then
237 echo "removed file beta still exists on disk" >&2
238 test_done "$testroot" "1"
239 return 1
240 fi
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
245 ret=$?
246 if [ $ret -ne 0 ]; then
247 diff -u $testroot/content.expected $testroot/content
248 test_done "$testroot" "$ret"
249 return 1
250 fi
252 if [ ! -h $testroot/wt/dotgotbar.link ]; then
253 echo "dotgotbar.link is not a symlink"
254 test_done "$testroot" "1"
255 return 1
256 fi
258 readlink $testroot/wt/symlink > $testroot/stdout
259 echo "alpha" > $testroot/stdout.expected
260 cmp -s $testroot/stdout.expected $testroot/stdout
261 ret=$?
262 if [ $ret -ne 0 ]; then
263 diff -u $testroot/stdout.expected $testroot/stdout
264 test_done "$testroot" "$ret"
265 return 1
266 fi
268 (cd $testroot/wt && got status > $testroot/stdout)
270 echo -n > $testroot/stdout.expected
271 cmp -s $testroot/stdout.expected $testroot/stdout
272 ret=$?
273 if [ $ret -ne 0 ]; then
274 diff -u $testroot/stdout.expected $testroot/stdout
275 test_done "$testroot" "$ret"
276 return 1
277 fi
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
284 ret=$?
285 if [ $ret -ne 0 ]; then
286 diff -u $testroot/stdout.expected $testroot/stdout
287 test_done "$testroot" "$ret"
288 return 1
289 fi
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
298 ret=$?
299 if [ $ret -ne 0 ]; then
300 diff -u $testroot/stdout.expected $testroot/stdout
301 test_done "$testroot" "$ret"
302 return 1
303 fi
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"
309 return 1
310 fi
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
317 ret=$?
318 if [ $ret -ne 0 ]; then
319 diff -u $testroot/stdout.expected $testroot/stdout
320 test_done "$testroot" "$ret"
321 return 1
322 fi
324 got tree -r $testroot/repo -c $merge_commit -R > $testroot/stdout
325 ret=$?
326 if [ $ret -ne 0 ]; then
327 echo "got tree failed unexpectedly" >&2
328 test_done "$testroot" "$ret"
329 return 1
330 fi
332 # bad symlink dotgotbar.link appears as a symlink in the merge commit:
333 cat > $testroot/stdout.expected <<EOF
334 alpha
335 dotgotbar.link@ -> .got/bar
336 epsilon/
337 epsilon/new
338 epsilon/zeta
339 gamma/
340 gamma/delta
341 symlink@ -> alpha
342 EOF
343 cmp -s $testroot/stdout.expected $testroot/stdout
344 ret=$?
345 if [ $ret -ne 0 ]; then
346 diff -u $testroot/stdout.expected $testroot/stdout
347 fi
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
367 ret=$?
368 if [ $ret -ne 0 ]; then
369 echo "got checkout failed unexpectedly" >&2
370 test_done "$testroot" "$ret"
371 return 1
372 fi
374 # must not use a mixed-commit work tree with 'got merge'
375 (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
376 ret=$?
377 if [ $ret -ne 0 ]; then
378 echo "got update failed unexpectedly" >&2
379 test_done "$testroot" "$ret"
380 return 1
381 fi
382 (cd $testroot/wt && got merge newbranch \
383 > $testroot/stdout 2> $testroot/stderr)
384 ret=$?
385 if [ $ret -eq 0 ]; then
386 echo "got merge succeeded unexpectedly" >&2
387 test_done "$testroot" "$ret"
388 return 1
389 fi
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
395 ret=$?
396 if [ $ret -ne 0 ]; then
397 diff -u $testroot/stderr.expected $testroot/stderr
398 test_done "$testroot" "$ret"
399 return 1
400 fi
402 (cd $testroot/wt && got update > /dev/null)
403 ret=$?
404 if [ $ret -ne 0 ]; then
405 echo "got update failed unexpectedly" >&2
406 test_done "$testroot" "$ret"
407 return 1
408 fi
410 # 'got merge -n' refuses to fast-forward
411 (cd $testroot/wt && got merge -n newbranch \
412 > $testroot/stdout 2> $testroot/stderr)
413 ret=$?
414 if [ $ret -eq 0 ]; then
415 echo "got merge succeeded unexpectedly" >&2
416 test_done "$testroot" "1"
417 return 1
418 fi
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
430 ret=$?
431 if [ $ret -ne 0 ]; then
432 diff -u $testroot/stderr.expected $testroot/stderr
433 test_done "$testroot" "$ret"
434 return 1
435 fi
437 (cd $testroot/wt && got merge newbranch \
438 > $testroot/stdout 2> $testroot/stderr)
439 ret=$?
440 if [ $ret -ne 0 ]; then
441 echo "got merge failed unexpectedly" >&2
442 test_done "$testroot" "$ret"
443 return 1
444 fi
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
452 ret=$?
453 if [ $ret -ne 0 ]; then
454 diff -u $testroot/stdout.expected $testroot/stdout
455 test_done "$testroot" "$ret"
456 return 1
457 fi
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
465 ret=$?
466 if [ $ret -ne 0 ]; then
467 diff -u $testroot/stdout.expected $testroot/stdout
468 test_done "$testroot" "$ret"
469 return 1
470 fi
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
484 ret=$?
485 if [ $ret -ne 0 ]; then
486 echo "got checkout failed unexpectedly" >&2
487 test_done "$testroot" "$ret"
488 return 1
489 fi
491 (cd $testroot/wt && got merge -M newbranch > $testroot/stdout)
492 ret=$?
493 if [ $ret -ne 0 ]; then
494 echo "got merge failed unexpectedly" >&2
495 test_done "$testroot" "$ret"
496 return 1
497 fi
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
507 ret=$?
508 if [ $ret -ne 0 ]; then
509 diff -u $testroot/stdout.expected $testroot/stdout
510 test_done "$testroot" "$ret"
511 return 1
512 fi
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
519 ret=$?
520 if [ $ret -ne 0 ]; then
521 diff -u $testroot/stdout.expected $testroot/stdout
522 test_done "$testroot" "$ret"
523 return 1
524 fi
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
540 ret=$?
541 if [ $ret -ne 0 ]; then
542 echo "got checkout failed unexpectedly" >&2
543 test_done "$testroot" "$ret"
544 return 1
545 fi
547 (cd $testroot/wt && got merge -M -n newbranch > $testroot/stdout)
548 ret=$?
549 if [ $ret -ne 0 ]; then
550 echo "got merge failed unexpectedly" >&2
551 test_done "$testroot" "$ret"
552 return 1
553 fi
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
559 ret=$?
560 if [ $ret -ne 0 ]; then
561 diff -u $testroot/stdout.expected $testroot/stdout
562 test_done "$testroot" "$ret"
563 return 1
564 fi
566 # Continue the merge.
567 (cd $testroot/wt && got merge -c > $testroot/stdout)
568 ret=$?
569 if [ $ret -ne 0 ]; then
570 echo "got merge failed unexpectedly" >&2
571 test_done "$testroot" "$ret"
572 return 1
573 fi
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
583 ret=$?
584 if [ $ret -ne 0 ]; then
585 diff -u $testroot/stdout.expected $testroot/stdout
586 test_done "$testroot" "$ret"
587 return 1
588 fi
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
595 ret=$?
596 if [ $ret -ne 0 ]; then
597 diff -u $testroot/stdout.expected $testroot/stdout
598 fi
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
612 ret=$?
613 if [ $ret -ne 0 ]; then
614 echo "got checkout failed unexpectedly" >&2
615 test_done "$testroot" "$ret"
616 return 1
617 fi
619 (cd $testroot/wt && got merge newbranch \
620 > $testroot/stdout 2> $testroot/stderr)
621 ret=$?
622 if [ $ret -ne 0 ]; then
623 echo "got merge failed unexpectedly" >&2
624 test_done "$testroot" "$ret"
625 return 1
626 fi
627 echo "Already up-to-date" > $testroot/stdout.expected
628 cmp -s $testroot/stdout.expected $testroot/stdout
629 ret=$?
630 if [ $ret -ne 0 ]; then
631 diff -u $testroot/stdout.expected $testroot/stdout
632 test_done "$testroot" "$ret"
633 return 1
634 fi
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
660 ret=$?
661 if [ $ret -ne 0 ]; then
662 echo "got checkout failed unexpectedly" >&2
663 test_done "$testroot" "$ret"
664 return 1
665 fi
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)
675 ret=$?
676 if [ $ret -ne 0 ]; then
677 echo "got update failed unexpectedly" >&2
678 test_done "$testroot" "$ret"
679 return 1
680 fi
682 (cd $testroot/wt && got merge newbranch \
683 > $testroot/stdout 2> $testroot/stderr)
684 ret=$?
685 if [ $ret -eq 0 ]; then
686 echo "got merge succeeded unexpectedly" >&2
687 test_done "$testroot" "1"
688 return 1
689 fi
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
697 ret=$?
698 if [ $ret -ne 0 ]; then
699 diff -u $testroot/stdout.expected $testroot/stdout
700 test_done "$testroot" "$ret"
701 return 1
702 fi
704 echo "got: conflicts must be resolved before merging can continue" \
705 > $testroot/stderr.expected
706 cmp -s $testroot/stderr.expected $testroot/stderr
707 ret=$?
708 if [ $ret -ne 0 ]; then
709 diff -u $testroot/stderr.expected $testroot/stderr
710 test_done "$testroot" "$ret"
711 return 1
712 fi
714 (cd $testroot/wt && got status > $testroot/stdout)
716 echo "C alpha" > $testroot/stdout.expected
717 echo "D beta" >> $testroot/stdout.expected
718 echo "A epsilon/new" >> $testroot/stdout.expected
719 echo "M gamma/delta" >> $testroot/stdout.expected
720 cmp -s $testroot/stdout.expected $testroot/stdout
721 ret=$?
722 if [ $ret -ne 0 ]; then
723 diff -u $testroot/stdout.expected $testroot/stdout
724 test_done "$testroot" "$ret"
725 return 1
726 fi
728 echo '<<<<<<<' > $testroot/content.expected
729 echo "modified alpha on master" >> $testroot/content.expected
730 echo "||||||| 3-way merge base: commit $commit0" \
731 >> $testroot/content.expected
732 echo "alpha" >> $testroot/content.expected
733 echo "=======" >> $testroot/content.expected
734 echo "modified alpha on branch" >> $testroot/content.expected
735 echo ">>>>>>> merged change: commit $branch_commit3" \
736 >> $testroot/content.expected
737 cat $testroot/wt/alpha > $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
744 fi
746 # resolve the conflict
747 echo "modified alpha by both branches" > $testroot/wt/alpha
749 (cd $testroot/wt && got merge -c > $testroot/stdout)
750 ret=$?
751 if [ $ret -ne 0 ]; then
752 echo "got merge failed unexpectedly" >&2
753 test_done "$testroot" "$ret"
754 return 1
755 fi
757 local merge_commit=`git_show_head $testroot/repo`
759 echo "M alpha" > $testroot/stdout.expected
760 echo "D beta" >> $testroot/stdout.expected
761 echo "A epsilon/new" >> $testroot/stdout.expected
762 echo "M gamma/delta" >> $testroot/stdout.expected
763 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
764 >> $testroot/stdout.expected
765 echo $merge_commit >> $testroot/stdout.expected
767 cmp -s $testroot/stdout.expected $testroot/stdout
768 ret=$?
769 if [ $ret -ne 0 ]; then
770 diff -u $testroot/stdout.expected $testroot/stdout
771 test_done "$testroot" "$ret"
772 return 1
773 fi
775 echo "modified delta on branch" > $testroot/content.expected
776 cat $testroot/wt/gamma/delta > $testroot/content
777 cmp -s $testroot/content.expected $testroot/content
778 ret=$?
779 if [ $ret -ne 0 ]; then
780 diff -u $testroot/content.expected $testroot/content
781 test_done "$testroot" "$ret"
782 return 1
783 fi
785 echo "modified alpha by both branches" > $testroot/content.expected
786 cat $testroot/wt/alpha > $testroot/content
787 cmp -s $testroot/content.expected $testroot/content
788 ret=$?
789 if [ $ret -ne 0 ]; then
790 diff -u $testroot/content.expected $testroot/content
791 test_done "$testroot" "$ret"
792 return 1
793 fi
795 if [ -e $testroot/wt/beta ]; then
796 echo "removed file beta still exists on disk" >&2
797 test_done "$testroot" "1"
798 return 1
799 fi
801 echo "new file on branch" > $testroot/content.expected
802 cat $testroot/wt/epsilon/new > $testroot/content
803 cmp -s $testroot/content.expected $testroot/content
804 ret=$?
805 if [ $ret -ne 0 ]; then
806 diff -u $testroot/content.expected $testroot/content
807 test_done "$testroot" "$ret"
808 return 1
809 fi
811 (cd $testroot/wt && got status > $testroot/stdout)
813 echo -n > $testroot/stdout.expected
814 cmp -s $testroot/stdout.expected $testroot/stdout
815 ret=$?
816 if [ $ret -ne 0 ]; then
817 diff -u $testroot/stdout.expected $testroot/stdout
818 test_done "$testroot" "$ret"
819 return 1
820 fi
822 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
823 echo "commit $merge_commit (master)" > $testroot/stdout.expected
824 echo "commit $master_commit" >> $testroot/stdout.expected
825 echo "commit $commit0" >> $testroot/stdout.expected
826 cmp -s $testroot/stdout.expected $testroot/stdout
827 ret=$?
828 if [ $ret -ne 0 ]; then
829 diff -u $testroot/stdout.expected $testroot/stdout
830 test_done "$testroot" "$ret"
831 return 1
832 fi
834 (cd $testroot/wt && got update > $testroot/stdout)
836 echo 'Already up-to-date' > $testroot/stdout.expected
837 cmp -s $testroot/stdout.expected $testroot/stdout
838 ret=$?
839 if [ $ret -ne 0 ]; then
840 diff -u $testroot/stdout.expected $testroot/stdout
841 test_done "$testroot" "$ret"
842 return 1
843 fi
845 # We should have created a merge commit with two parents.
846 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
847 echo "parent 1: $master_commit" > $testroot/stdout.expected
848 echo "parent 2: $branch_commit3" >> $testroot/stdout.expected
849 cmp -s $testroot/stdout.expected $testroot/stdout
850 ret=$?
851 if [ $ret -ne 0 ]; then
852 diff -u $testroot/stdout.expected $testroot/stdout
853 fi
854 test_done "$testroot" "$ret"
857 test_merge_continue_new_commit() {
858 # "got merge -c" should refuse to run if the current branch tip has
859 # changed since the merge was started, to avoid clobbering the changes.
860 local testroot=`test_init merge_continue_new_commit`
862 git -C $testroot/repo checkout -q -b newbranch
863 echo "modified delta on branch" > $testroot/repo/gamma/delta
864 git_commit $testroot/repo -m "committing to delta on newbranch"
866 git -C $testroot/repo checkout -q master
867 echo "modified alpha on master" > $testroot/repo/alpha
868 git_commit $testroot/repo -m "committing to alpha on master"
870 got checkout -b master $testroot/repo $testroot/wt > /dev/null
871 ret=$?
872 if [ $ret -ne 0 ]; then
873 echo "got checkout failed unexpectedly" >&2
874 test_done "$testroot" "$ret"
875 return 1
876 fi
878 (cd $testroot/wt && got merge -n newbranch >/dev/null)
879 ret=$?
880 if [ $ret -ne 0 ]; then
881 echo "got merge failed unexpectedly" >&2
882 test_done "$testroot" "$ret"
883 return 1
884 fi
886 echo "modified alpha again on master" > $testroot/repo/alpha
887 git_commit $testroot/repo -m "committing to alpha on master again"
889 (cd $testroot/wt && got merge -c > $testroot/stdout 2> $testroot/stderr)
890 ret=$?
891 if [ $ret -eq 0 ]; then
892 echo "got merge succeeded unexpectedly" >&2
893 test_done "$testroot" "1"
894 return 1
895 fi
897 echo -n > $testroot/stdout.expected
898 cmp -s $testroot/stdout.expected $testroot/stdout
899 ret=$?
900 if [ $ret -ne 0 ]; then
901 diff -u $testroot/stdout.expected $testroot/stdout
902 test_done "$testroot" "$ret"
903 return 1
904 fi
906 echo -n "got: merging cannot proceed because the work tree is no " \
907 > $testroot/stderr.expected
908 echo "longer up-to-date; merge must be aborted and retried" \
909 >> $testroot/stderr.expected
910 cmp -s $testroot/stderr.expected $testroot/stderr
911 ret=$?
912 if [ $ret -ne 0 ]; then
913 diff -u $testroot/stderr.expected $testroot/stderr
914 fi
915 test_done "$testroot" "$ret"
918 test_merge_abort() {
919 local testroot=`test_init merge_abort`
920 local commit0=`git_show_head $testroot/repo`
921 local commit0_author_time=`git_show_author_time $testroot/repo`
923 git -C $testroot/repo checkout -q -b newbranch
924 echo "modified delta on branch" > $testroot/repo/gamma/delta
925 git_commit $testroot/repo -m "committing to delta on newbranch"
926 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
928 echo "modified alpha on branch" > $testroot/repo/alpha
929 git_commit $testroot/repo -m "committing to alpha on newbranch"
930 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
931 git -C $testroot/repo rm -q beta
932 git_commit $testroot/repo -m "removing beta on newbranch"
933 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
934 echo "new file on branch" > $testroot/repo/epsilon/new
935 git -C $testroot/repo add epsilon/new
936 git_commit $testroot/repo -m "adding new file on newbranch"
937 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
938 (cd $testroot/repo && ln -s alpha symlink)
939 git -C $testroot/repo add symlink
940 git_commit $testroot/repo -m "adding symlink on newbranch"
941 local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
943 got checkout -b master $testroot/repo $testroot/wt > /dev/null
944 ret=$?
945 if [ $ret -ne 0 ]; then
946 echo "got checkout failed unexpectedly" >&2
947 test_done "$testroot" "$ret"
948 return 1
949 fi
951 # unrelated unversioned file in work tree
952 touch $testroot/wt/unversioned-file
954 # create a conflicting commit
955 git -C $testroot/repo checkout -q master
956 echo "modified alpha on master" > $testroot/repo/alpha
957 git_commit $testroot/repo -m "committing to alpha on master"
958 local master_commit=`git_show_head $testroot/repo`
960 # need an up-to-date work tree for 'got merge'
961 (cd $testroot/wt && got update > /dev/null)
962 ret=$?
963 if [ $ret -ne 0 ]; then
964 echo "got update failed unexpectedly" >&2
965 test_done "$testroot" "$ret"
966 return 1
967 fi
969 (cd $testroot/wt && got merge newbranch \
970 > $testroot/stdout 2> $testroot/stderr)
971 ret=$?
972 if [ $ret -eq 0 ]; then
973 echo "got merge succeeded unexpectedly" >&2
974 test_done "$testroot" "1"
975 return 1
976 fi
978 echo "C alpha" >> $testroot/stdout.expected
979 echo "D beta" >> $testroot/stdout.expected
980 echo "A epsilon/new" >> $testroot/stdout.expected
981 echo "G gamma/delta" >> $testroot/stdout.expected
982 echo "A symlink" >> $testroot/stdout.expected
983 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
984 cmp -s $testroot/stdout.expected $testroot/stdout
985 ret=$?
986 if [ $ret -ne 0 ]; then
987 diff -u $testroot/stdout.expected $testroot/stdout
988 test_done "$testroot" "$ret"
989 return 1
990 fi
992 echo "got: conflicts must be resolved before merging can continue" \
993 > $testroot/stderr.expected
994 cmp -s $testroot/stderr.expected $testroot/stderr
995 ret=$?
996 if [ $ret -ne 0 ]; then
997 diff -u $testroot/stderr.expected $testroot/stderr
998 test_done "$testroot" "$ret"
999 return 1
1002 # unrelated added file added during conflict resolution
1003 touch $testroot/wt/added-file
1004 (cd $testroot/wt && got add added-file > /dev/null)
1006 (cd $testroot/wt && got status > $testroot/stdout)
1008 echo "A added-file" > $testroot/stdout.expected
1009 echo "C alpha" >> $testroot/stdout.expected
1010 echo "D beta" >> $testroot/stdout.expected
1011 echo "A epsilon/new" >> $testroot/stdout.expected
1012 echo "M gamma/delta" >> $testroot/stdout.expected
1013 echo "A symlink" >> $testroot/stdout.expected
1014 echo "? unversioned-file" >> $testroot/stdout.expected
1015 cmp -s $testroot/stdout.expected $testroot/stdout
1016 ret=$?
1017 if [ $ret -ne 0 ]; then
1018 diff -u $testroot/stdout.expected $testroot/stdout
1019 test_done "$testroot" "$ret"
1020 return 1
1023 (cd $testroot/wt && got merge -a > $testroot/stdout)
1024 ret=$?
1025 if [ $ret -ne 0 ]; then
1026 echo "got merge failed unexpectedly" >&2
1027 test_done "$testroot" "$ret"
1028 return 1
1031 echo "R added-file" > $testroot/stdout.expected
1032 echo "R alpha" >> $testroot/stdout.expected
1033 echo "R beta" >> $testroot/stdout.expected
1034 echo "R epsilon/new" >> $testroot/stdout.expected
1035 echo "R gamma/delta" >> $testroot/stdout.expected
1036 echo "R symlink" >> $testroot/stdout.expected
1037 echo "G added-file" >> $testroot/stdout.expected
1038 echo "Merge of refs/heads/newbranch aborted" \
1039 >> $testroot/stdout.expected
1041 cmp -s $testroot/stdout.expected $testroot/stdout
1042 ret=$?
1043 if [ $ret -ne 0 ]; then
1044 diff -u $testroot/stdout.expected $testroot/stdout
1045 test_done "$testroot" "$ret"
1046 return 1
1049 echo "delta" > $testroot/content.expected
1050 cat $testroot/wt/gamma/delta > $testroot/content
1051 cmp -s $testroot/content.expected $testroot/content
1052 ret=$?
1053 if [ $ret -ne 0 ]; then
1054 diff -u $testroot/content.expected $testroot/content
1055 test_done "$testroot" "$ret"
1056 return 1
1059 echo "modified alpha on master" > $testroot/content.expected
1060 cat $testroot/wt/alpha > $testroot/content
1061 cmp -s $testroot/content.expected $testroot/content
1062 ret=$?
1063 if [ $ret -ne 0 ]; then
1064 diff -u $testroot/content.expected $testroot/content
1065 test_done "$testroot" "$ret"
1066 return 1
1069 echo "beta" > $testroot/content.expected
1070 cat $testroot/wt/beta > $testroot/content
1071 cmp -s $testroot/content.expected $testroot/content
1072 ret=$?
1073 if [ $ret -ne 0 ]; then
1074 diff -u $testroot/content.expected $testroot/content
1075 test_done "$testroot" "$ret"
1076 return 1
1079 if [ -e $testroot/wt/epsilon/new ]; then
1080 echo "reverted file epsilon/new still exists on disk" >&2
1081 test_done "$testroot" "1"
1082 return 1
1085 if [ -e $testroot/wt/symlink ]; then
1086 echo "reverted symlink still exists on disk" >&2
1087 test_done "$testroot" "1"
1088 return 1
1091 (cd $testroot/wt && got status > $testroot/stdout)
1093 echo "? added-file" > $testroot/stdout.expected
1094 echo "? unversioned-file" >> $testroot/stdout.expected
1095 cmp -s $testroot/stdout.expected $testroot/stdout
1096 ret=$?
1097 if [ $ret -ne 0 ]; then
1098 diff -u $testroot/stdout.expected $testroot/stdout
1099 test_done "$testroot" "$ret"
1100 return 1
1103 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1104 echo "commit $master_commit (master)" > $testroot/stdout.expected
1105 echo "commit $commit0" >> $testroot/stdout.expected
1106 cmp -s $testroot/stdout.expected $testroot/stdout
1107 ret=$?
1108 if [ $ret -ne 0 ]; then
1109 diff -u $testroot/stdout.expected $testroot/stdout
1110 test_done "$testroot" "$ret"
1111 return 1
1114 (cd $testroot/wt && got update > $testroot/stdout)
1116 echo 'Already up-to-date' > $testroot/stdout.expected
1117 cmp -s $testroot/stdout.expected $testroot/stdout
1118 ret=$?
1119 if [ $ret -ne 0 ]; then
1120 diff -u $testroot/stdout.expected $testroot/stdout
1122 test_done "$testroot" "$ret"
1125 test_merge_in_progress() {
1126 local testroot=`test_init merge_in_progress`
1127 local commit0=`git_show_head $testroot/repo`
1128 local commit0_author_time=`git_show_author_time $testroot/repo`
1130 git -C $testroot/repo checkout -q -b newbranch
1131 echo "modified alpha on branch" > $testroot/repo/alpha
1132 git_commit $testroot/repo -m "committing to alpha on newbranch"
1133 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1135 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1136 ret=$?
1137 if [ $ret -ne 0 ]; then
1138 echo "got checkout failed unexpectedly" >&2
1139 test_done "$testroot" "$ret"
1140 return 1
1143 # create a conflicting commit
1144 git -C $testroot/repo checkout -q master
1145 echo "modified alpha on master" > $testroot/repo/alpha
1146 git_commit $testroot/repo -m "committing to alpha on master"
1147 local master_commit=`git_show_head $testroot/repo`
1149 # need an up-to-date work tree for 'got merge'
1150 (cd $testroot/wt && got update > /dev/null)
1151 ret=$?
1152 if [ $ret -ne 0 ]; then
1153 echo "got update failed unexpectedly" >&2
1154 test_done "$testroot" "$ret"
1155 return 1
1158 (cd $testroot/wt && got merge newbranch \
1159 > $testroot/stdout 2> $testroot/stderr)
1160 ret=$?
1161 if [ $ret -eq 0 ]; then
1162 echo "got merge succeeded unexpectedly" >&2
1163 test_done "$testroot" "1"
1164 return 1
1167 echo "C alpha" >> $testroot/stdout.expected
1168 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1169 cmp -s $testroot/stdout.expected $testroot/stdout
1170 ret=$?
1171 if [ $ret -ne 0 ]; then
1172 diff -u $testroot/stdout.expected $testroot/stdout
1173 test_done "$testroot" "$ret"
1174 return 1
1177 echo "got: conflicts must be resolved before merging can continue" \
1178 > $testroot/stderr.expected
1179 cmp -s $testroot/stderr.expected $testroot/stderr
1180 ret=$?
1181 if [ $ret -ne 0 ]; then
1182 diff -u $testroot/stderr.expected $testroot/stderr
1183 test_done "$testroot" "$ret"
1184 return 1
1187 (cd $testroot/wt && got status > $testroot/stdout)
1189 echo "C alpha" > $testroot/stdout.expected
1190 cmp -s $testroot/stdout.expected $testroot/stdout
1191 ret=$?
1192 if [ $ret -ne 0 ]; then
1193 diff -u $testroot/stdout.expected $testroot/stdout
1194 test_done "$testroot" "$ret"
1195 return 1
1198 for cmd in update commit histedit "rebase newbranch" \
1199 "integrate newbranch" "merge newbranch" "stage alpha"; do
1200 (cd $testroot/wt && got $cmd > $testroot/stdout \
1201 2> $testroot/stderr)
1202 ret=$?
1203 if [ $ret -eq 0 ]; then
1204 echo "got $cmd succeeded unexpectedly" >&2
1205 test_done "$testroot" "1"
1206 return 1
1209 echo -n > $testroot/stdout.expected
1210 cmp -s $testroot/stdout.expected $testroot/stdout
1211 ret=$?
1212 if [ $ret -ne 0 ]; then
1213 diff -u $testroot/stdout.expected $testroot/stdout
1214 test_done "$testroot" "$ret"
1215 return 1
1218 echo -n "got: a merge operation is in progress in this " \
1219 > $testroot/stderr.expected
1220 echo "work tree and must be continued or aborted first" \
1221 >> $testroot/stderr.expected
1222 cmp -s $testroot/stderr.expected $testroot/stderr
1223 ret=$?
1224 if [ $ret -ne 0 ]; then
1225 diff -u $testroot/stderr.expected $testroot/stderr
1226 test_done "$testroot" "$ret"
1227 return 1
1229 done
1231 test_done "$testroot" "$ret"
1234 test_merge_path_prefix() {
1235 local testroot=`test_init merge_path_prefix`
1236 local commit0=`git_show_head $testroot/repo`
1237 local commit0_author_time=`git_show_author_time $testroot/repo`
1239 git -C $testroot/repo checkout -q -b newbranch
1240 echo "modified alpha on branch" > $testroot/repo/alpha
1241 git_commit $testroot/repo -m "committing to alpha on newbranch"
1242 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1244 got checkout -p epsilon -b master $testroot/repo $testroot/wt \
1245 > /dev/null
1246 ret=$?
1247 if [ $ret -ne 0 ]; then
1248 echo "got checkout failed unexpectedly" >&2
1249 test_done "$testroot" "$ret"
1250 return 1
1253 # create a conflicting commit
1254 git -C $testroot/repo checkout -q master
1255 echo "modified alpha on master" > $testroot/repo/alpha
1256 git_commit $testroot/repo -m "committing to alpha on master"
1257 local master_commit=`git_show_head $testroot/repo`
1259 # need an up-to-date work tree for 'got merge'
1260 (cd $testroot/wt && got update > /dev/null)
1261 ret=$?
1262 if [ $ret -ne 0 ]; then
1263 echo "got update failed unexpectedly" >&2
1264 test_done "$testroot" "$ret"
1265 return 1
1268 (cd $testroot/wt && got merge newbranch \
1269 > $testroot/stdout 2> $testroot/stderr)
1270 ret=$?
1271 if [ $ret -eq 0 ]; then
1272 echo "got merge succeeded unexpectedly" >&2
1273 test_done "$testroot" "1"
1274 return 1
1277 echo -n "got: cannot merge branch which contains changes outside " \
1278 > $testroot/stderr.expected
1279 echo "of this work tree's path prefix" >> $testroot/stderr.expected
1280 cmp -s $testroot/stderr.expected $testroot/stderr
1281 ret=$?
1282 if [ $ret -ne 0 ]; then
1283 diff -u $testroot/stderr.expected $testroot/stderr
1285 test_done "$testroot" "$ret"
1288 test_merge_missing_file() {
1289 local testroot=`test_init merge_missing_file`
1290 local commit0=`git_show_head $testroot/repo`
1291 local commit0_author_time=`git_show_author_time $testroot/repo`
1293 git -C $testroot/repo checkout -q -b newbranch
1294 echo "modified alpha on branch" > $testroot/repo/alpha
1295 echo "modified delta on branch" > $testroot/repo/gamma/delta
1296 git_commit $testroot/repo -m "committing to alpha and delta"
1297 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1299 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1300 ret=$?
1301 if [ $ret -ne 0 ]; then
1302 echo "got checkout failed unexpectedly" >&2
1303 test_done "$testroot" "$ret"
1304 return 1
1307 # create a conflicting commit which renames alpha
1308 git -C $testroot/repo checkout -q master
1309 git -C $testroot/repo mv alpha epsilon/alpha-moved
1310 git_commit $testroot/repo -m "moving alpha on master"
1311 local master_commit=`git_show_head $testroot/repo`
1313 # need an up-to-date work tree for 'got merge'
1314 (cd $testroot/wt && got update > /dev/null)
1315 ret=$?
1316 if [ $ret -ne 0 ]; then
1317 echo "got update failed unexpectedly" >&2
1318 test_done "$testroot" "$ret"
1319 return 1
1322 (cd $testroot/wt && got merge newbranch \
1323 > $testroot/stdout 2> $testroot/stderr)
1324 ret=$?
1325 if [ $ret -eq 0 ]; then
1326 echo "got merge succeeded unexpectedly" >&2
1327 test_done "$testroot" "1"
1328 return 1
1331 echo "! alpha" > $testroot/stdout.expected
1332 echo "G gamma/delta" >> $testroot/stdout.expected
1333 echo -n "Files which had incoming changes but could not be found " \
1334 >> $testroot/stdout.expected
1335 echo "in the work tree: 1" >> $testroot/stdout.expected
1336 cmp -s $testroot/stdout.expected $testroot/stdout
1337 ret=$?
1338 if [ $ret -ne 0 ]; then
1339 diff -u $testroot/stdout.expected $testroot/stdout
1340 test_done "$testroot" "$ret"
1341 return 1
1344 echo -n "got: changes destined for some files " \
1345 > $testroot/stderr.expected
1346 echo -n "were not yet merged and should be merged manually if " \
1347 >> $testroot/stderr.expected
1348 echo "required before the merge operation is continued" \
1349 >> $testroot/stderr.expected
1350 cmp -s $testroot/stderr.expected $testroot/stderr
1351 ret=$?
1352 if [ $ret -ne 0 ]; then
1353 diff -u $testroot/stderr.expected $testroot/stderr
1354 test_done "$testroot" "$ret"
1355 return 1
1358 (cd $testroot/wt && got status > $testroot/stdout)
1360 echo "M gamma/delta" > $testroot/stdout.expected
1361 cmp -s $testroot/stdout.expected $testroot/stdout
1362 ret=$?
1363 if [ $ret -ne 0 ]; then
1364 diff -u $testroot/stdout.expected $testroot/stdout
1365 test_done "$testroot" "$ret"
1366 return 1
1369 test_done "$testroot" "$ret"
1372 test_merge_no_op() {
1373 local testroot=`test_init merge_no_op`
1374 local commit0=`git_show_head $testroot/repo`
1375 local commit0_author_time=`git_show_author_time $testroot/repo`
1377 git -C $testroot/repo checkout -q -b newbranch
1378 echo "modified alpha on branch" > $testroot/repo/alpha
1379 git_commit $testroot/repo -m "committing to alpha on newbranch"
1380 local branch_commit=`git_show_branch_head $testroot/repo newbranch`
1382 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1383 ret=$?
1384 if [ $ret -ne 0 ]; then
1385 echo "got checkout failed unexpectedly" >&2
1386 test_done "$testroot" "$ret"
1387 return 1
1390 # create a conflicting commit
1391 git -C $testroot/repo checkout -q master
1392 echo "modified alpha on master" > $testroot/repo/alpha
1393 git_commit $testroot/repo -m "committing to alpha on master"
1394 local master_commit=`git_show_head $testroot/repo`
1396 # need an up-to-date work tree for 'got merge'
1397 (cd $testroot/wt && got update > /dev/null)
1398 ret=$?
1399 if [ $ret -ne 0 ]; then
1400 echo "got update failed unexpectedly" >&2
1401 test_done "$testroot" "$ret"
1402 return 1
1405 (cd $testroot/wt && got merge newbranch \
1406 > $testroot/stdout 2> $testroot/stderr)
1407 ret=$?
1408 if [ $ret -eq 0 ]; then
1409 echo "got merge succeeded unexpectedly" >&2
1410 test_done "$testroot" "1"
1411 return 1
1414 echo "C alpha" >> $testroot/stdout.expected
1415 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1416 cmp -s $testroot/stdout.expected $testroot/stdout
1417 ret=$?
1418 if [ $ret -ne 0 ]; then
1419 diff -u $testroot/stdout.expected $testroot/stdout
1420 test_done "$testroot" "$ret"
1421 return 1
1424 echo "got: conflicts must be resolved before merging can continue" \
1425 > $testroot/stderr.expected
1426 cmp -s $testroot/stderr.expected $testroot/stderr
1427 ret=$?
1428 if [ $ret -ne 0 ]; then
1429 diff -u $testroot/stderr.expected $testroot/stderr
1430 test_done "$testroot" "$ret"
1431 return 1
1434 (cd $testroot/wt && got status > $testroot/stdout)
1436 echo "C alpha" > $testroot/stdout.expected
1437 cmp -s $testroot/stdout.expected $testroot/stdout
1438 ret=$?
1439 if [ $ret -ne 0 ]; then
1440 diff -u $testroot/stdout.expected $testroot/stdout
1441 test_done "$testroot" "$ret"
1442 return 1
1445 # resolve the conflict by reverting all changes; now it is no-op merge
1446 (cd $testroot/wt && got revert alpha > /dev/null)
1447 ret=$?
1448 if [ $ret -ne 0 ]; then
1449 echo "got revert failed unexpectedly" >&2
1450 test_done "$testroot" "$ret"
1451 return 1
1454 (cd $testroot/wt && got merge -c > $testroot/stdout \
1455 2> $testroot/stderr)
1456 ret=$?
1457 if [ $ret -ne 0 ]; then
1458 echo "got merge failed unexpectedly" >&2
1459 test_done "$testroot" "$ret"
1460 return 1
1463 echo -n '' > $testroot/stderr.expected
1464 cmp -s $testroot/stderr.expected $testroot/stderr
1465 ret=$?
1466 if [ $ret -ne 0 ]; then
1467 diff -u $testroot/stderr.expected $testroot/stderr
1468 test_done "$testroot" "$ret"
1469 return 1
1472 local merge_commit=`git_show_head $testroot/repo`
1473 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1474 > $testroot/stdout.expected
1475 echo $merge_commit >> $testroot/stdout.expected
1477 cmp -s $testroot/stdout.expected $testroot/stdout
1478 ret=$?
1479 if [ $ret -ne 0 ]; then
1480 diff -u $testroot/stdout.expected $testroot/stdout
1481 test_done "$testroot" "$ret"
1482 return 1
1485 (cd $testroot/wt && got status > $testroot/stdout)
1487 echo -n "" > $testroot/stdout.expected
1488 cmp -s $testroot/stdout.expected $testroot/stdout
1489 ret=$?
1490 if [ $ret -ne 0 ]; then
1491 diff -u $testroot/stdout.expected $testroot/stdout
1492 test_done "$testroot" "$ret"
1493 return 1
1496 # We should have created a merge commit with two parents.
1497 got log -r $testroot/repo -l1 -c $merge_commit | grep ^parent \
1498 > $testroot/stdout
1499 echo "parent 1: $master_commit" > $testroot/stdout.expected
1500 echo "parent 2: $branch_commit" >> $testroot/stdout.expected
1501 cmp -s $testroot/stdout.expected $testroot/stdout
1502 ret=$?
1503 if [ $ret -ne 0 ]; then
1504 diff -u $testroot/stdout.expected $testroot/stdout
1506 test_done "$testroot" "$ret"
1509 test_merge_imported_branch() {
1510 local testroot=`test_init merge_import`
1511 local commit0=`git_show_head $testroot/repo`
1512 local commit0_author_time=`git_show_author_time $testroot/repo`
1514 # import a new sub-tree to the 'files' branch such that
1515 # none of the files added here collide with existing ones
1516 mkdir -p $testroot/tree/there
1517 mkdir -p $testroot/tree/be/lots
1518 mkdir -p $testroot/tree/files
1519 echo "there should" > $testroot/tree/there/should
1520 echo "be lots of" > $testroot/tree/be/lots/of
1521 echo "files here" > $testroot/tree/files/here
1522 got import -r $testroot/repo -b files -m 'import files' \
1523 $testroot/tree > /dev/null
1525 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1526 ret=$?
1527 if [ $ret -ne 0 ]; then
1528 echo "got checkout failed unexpectedly" >&2
1529 test_done "$testroot" "$ret"
1530 return 1
1533 (cd $testroot/wt && got merge files > $testroot/stdout)
1534 ret=$?
1535 if [ $ret -ne 0 ]; then
1536 echo "got merge failed unexpectedly" >&2
1537 test_done "$testroot" "$ret"
1538 return 1
1541 local merge_commit0=`git_show_head $testroot/repo`
1542 cat > $testroot/stdout.expected <<EOF
1543 A be/lots/of
1544 A files/here
1545 A there/should
1546 Merged refs/heads/files into refs/heads/master: $merge_commit0
1547 EOF
1548 cmp -s $testroot/stdout.expected $testroot/stdout
1549 ret=$?
1550 if [ $ret -ne 0 ]; then
1551 diff -u $testroot/stdout.expected $testroot/stdout
1552 test_done "$testroot" "$ret"
1553 return 1
1556 # try to merge again while no new changes are available
1557 (cd $testroot/wt && got merge files > $testroot/stdout)
1558 ret=$?
1559 if [ $ret -ne 0 ]; then
1560 echo "got merge failed unexpectedly" >&2
1561 test_done "$testroot" "$ret"
1562 return 1
1564 echo "Already up-to-date" > $testroot/stdout.expected
1565 cmp -s $testroot/stdout.expected $testroot/stdout
1566 ret=$?
1567 if [ $ret -ne 0 ]; then
1568 diff -u $testroot/stdout.expected $testroot/stdout
1569 test_done "$testroot" "$ret"
1570 return 1
1573 # update the 'files' branch
1574 git -C $testroot/repo reset -q --hard master
1575 git -C $testroot/repo checkout -q files
1576 echo "indeed" > $testroot/repo/indeed
1577 git -C $testroot/repo add indeed
1578 git_commit $testroot/repo -m "adding another file indeed"
1579 echo "be lots and lots of" > $testroot/repo/be/lots/of
1580 git_commit $testroot/repo -m "lots of changes"
1582 (cd $testroot/wt && got update > /dev/null)
1583 ret=$?
1584 if [ $ret -ne 0 ]; then
1585 echo "got update failed unexpectedly" >&2
1586 test_done "$testroot" "$ret"
1587 return 1
1590 # we should now be able to merge more changes from files branch
1591 (cd $testroot/wt && got merge files > $testroot/stdout)
1592 ret=$?
1593 if [ $ret -ne 0 ]; then
1594 echo "got merge failed unexpectedly" >&2
1595 test_done "$testroot" "$ret"
1596 return 1
1599 local merge_commit1=`git_show_branch_head $testroot/repo master`
1600 cat > $testroot/stdout.expected <<EOF
1601 G be/lots/of
1602 A indeed
1603 Merged refs/heads/files into refs/heads/master: $merge_commit1
1604 EOF
1606 cmp -s $testroot/stdout.expected $testroot/stdout
1607 ret=$?
1608 if [ $ret -ne 0 ]; then
1609 diff -u $testroot/stdout.expected $testroot/stdout
1611 test_done "$testroot" "$ret"
1614 test_merge_interrupt() {
1615 local testroot=`test_init merge_interrupt`
1616 local commit0=`git_show_head $testroot/repo`
1617 local commit0_author_time=`git_show_author_time $testroot/repo`
1619 git -C $testroot/repo checkout -q -b newbranch
1620 echo "modified alpha on branch" > $testroot/repo/alpha
1621 git_commit $testroot/repo -m "committing to alpha on newbranch"
1622 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1624 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1625 ret=$?
1626 if [ $ret -ne 0 ]; then
1627 echo "got checkout failed unexpectedly" >&2
1628 test_done "$testroot" "$ret"
1629 return 1
1632 # create a non-conflicting commit
1633 git -C $testroot/repo checkout -q master
1634 echo "modified beta on master" > $testroot/repo/beta
1635 git_commit $testroot/repo -m "committing to beta on master"
1636 local master_commit=`git_show_head $testroot/repo`
1638 # need an up-to-date work tree for 'got merge'
1639 (cd $testroot/wt && got update > /dev/null)
1640 ret=$?
1641 if [ $ret -ne 0 ]; then
1642 echo "got update failed unexpectedly" >&2
1643 test_done "$testroot" "$ret"
1644 return 1
1647 (cd $testroot/wt && got merge -n newbranch \
1648 > $testroot/stdout 2> $testroot/stderr)
1649 ret=$?
1650 if [ $ret -ne 0 ]; then
1651 echo "got merge failed unexpectedly" >&2
1652 test_done "$testroot" "1"
1653 return 1
1656 echo "G alpha" > $testroot/stdout.expected
1657 echo "Merge of refs/heads/newbranch interrupted on request" \
1658 >> $testroot/stdout.expected
1659 cmp -s $testroot/stdout.expected $testroot/stdout
1660 ret=$?
1661 if [ $ret -ne 0 ]; then
1662 diff -u $testroot/stdout.expected $testroot/stdout
1663 test_done "$testroot" "$ret"
1664 return 1
1667 (cd $testroot/wt && got status > $testroot/stdout)
1669 echo "M alpha" > $testroot/stdout.expected
1670 cmp -s $testroot/stdout.expected $testroot/stdout
1671 ret=$?
1672 if [ $ret -ne 0 ]; then
1673 diff -u $testroot/stdout.expected $testroot/stdout
1674 test_done "$testroot" "$ret"
1675 return 1
1678 echo "modified alpha on branch" > $testroot/content.expected
1679 cat $testroot/wt/alpha > $testroot/content
1680 cmp -s $testroot/content.expected $testroot/content
1681 ret=$?
1682 if [ $ret -ne 0 ]; then
1683 diff -u $testroot/content.expected $testroot/content
1684 test_done "$testroot" "$ret"
1685 return 1
1688 # adjust merge result
1689 echo "adjusted merge result" > $testroot/wt/alpha
1691 # continue the merge
1692 (cd $testroot/wt && got merge -c > $testroot/stdout)
1693 ret=$?
1694 if [ $ret -ne 0 ]; then
1695 echo "got merge failed unexpectedly" >&2
1696 test_done "$testroot" "$ret"
1697 return 1
1700 local merge_commit=`git_show_head $testroot/repo`
1702 echo "M alpha" > $testroot/stdout.expected
1703 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1704 >> $testroot/stdout.expected
1705 echo $merge_commit >> $testroot/stdout.expected
1707 cmp -s $testroot/stdout.expected $testroot/stdout
1708 ret=$?
1709 if [ $ret -ne 0 ]; then
1710 diff -u $testroot/stdout.expected $testroot/stdout
1711 test_done "$testroot" "$ret"
1712 return 1
1715 (cd $testroot/wt && got status > $testroot/stdout)
1717 echo -n > $testroot/stdout.expected
1718 cmp -s $testroot/stdout.expected $testroot/stdout
1719 ret=$?
1720 if [ $ret -ne 0 ]; then
1721 diff -u $testroot/stdout.expected $testroot/stdout
1722 test_done "$testroot" "$ret"
1723 return 1
1726 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1727 echo "commit $merge_commit (master)" > $testroot/stdout.expected
1728 echo "commit $master_commit" >> $testroot/stdout.expected
1729 echo "commit $commit0" >> $testroot/stdout.expected
1730 cmp -s $testroot/stdout.expected $testroot/stdout
1731 ret=$?
1732 if [ $ret -ne 0 ]; then
1733 diff -u $testroot/stdout.expected $testroot/stdout
1734 test_done "$testroot" "$ret"
1735 return 1
1738 (cd $testroot/wt && got update > $testroot/stdout)
1740 echo 'Already up-to-date' > $testroot/stdout.expected
1741 cmp -s $testroot/stdout.expected $testroot/stdout
1742 ret=$?
1743 if [ $ret -ne 0 ]; then
1744 diff -u $testroot/stdout.expected $testroot/stdout
1745 test_done "$testroot" "$ret"
1746 return 1
1749 # We should have created a merge commit with two parents.
1750 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
1751 echo "parent 1: $master_commit" > $testroot/stdout.expected
1752 echo "parent 2: $branch_commit0" >> $testroot/stdout.expected
1753 cmp -s $testroot/stdout.expected $testroot/stdout
1754 ret=$?
1755 if [ $ret -ne 0 ]; then
1756 diff -u $testroot/stdout.expected $testroot/stdout
1758 test_done "$testroot" "$ret"
1761 test_merge_umask() {
1762 local testroot=`test_init merge_umask`
1764 git -C $testroot/repo checkout -q -b newbranch
1765 echo "modified alpha on branch" >$testroot/repo/alpha
1766 git_commit "$testroot/repo" -m "committing alpha on newbranch"
1767 echo "modified delta on branch" >$testroot/repo/gamma/delta
1768 git_commit "$testroot/repo" -m "committing delta on newbranch"
1770 # diverge from newbranch
1771 git -C "$testroot/repo" checkout -q master
1772 echo "modified beta on master" >$testroot/repo/beta
1773 git_commit "$testroot/repo" -m "committing zeto no master"
1775 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1777 # using a subshell to avoid clobbering global umask
1778 (umask 077 && cd "$testroot/wt" && got merge newbranch) >/dev/null
1780 for f in alpha gamma/delta; do
1781 ls -l "$testroot/wt/$f" | grep -q ^-rw-------
1782 if [ $? -ne 0 ]; then
1783 echo "$f is not 0600 after merge" >&2
1784 ls -l "$testroot/wt/$f" >&2
1785 test_done "$testroot" 1
1787 done
1789 test_done "$testroot" 0
1792 test_merge_gitconfig_author() {
1793 local testroot=`test_init merge_gitconfig_author`
1795 git -C $testroot/repo config user.name 'Flan Luck'
1796 git -C $testroot/repo config user.email 'flan_luck@openbsd.org'
1798 git -C $testroot/repo checkout -q -b newbranch
1799 echo "modified alpha on branch" >$testroot/repo/alpha
1800 git_commit "$testroot/repo" -m "committing alpha on newbranch"
1801 echo "modified delta on branch" >$testroot/repo/gamma/delta
1802 git_commit "$testroot/repo" -m "committing delta on newbranch"
1804 # diverge from newbranch
1805 git -C "$testroot/repo" checkout -q master
1806 echo "modified beta on master" >$testroot/repo/beta
1807 git_commit "$testroot/repo" -m "committing zeto no master"
1809 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1811 # unset in a subshell to avoid affecting our environment
1812 (unset GOT_IGNORE_GITCONFIG && cd $testroot/wt && \
1813 got merge newbranch > /dev/null)
1815 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
1816 ret=$?
1817 if [ $ret -ne 0 ]; then
1818 test_done "$testroot" "$ret"
1819 return 1
1822 echo "from: Flan Luck <flan_luck@openbsd.org>" \
1823 > $testroot/stdout.expected
1824 cmp -s $testroot/stdout.expected $testroot/stdout
1825 ret=$?
1826 if [ $ret -ne 0 ]; then
1827 diff -u $testroot/stdout.expected $testroot/stdout
1829 test_done "$testroot" "$ret"
1832 test_merge_fetched_branch() {
1833 local testroot=`test_init merge_fetched_branch`
1834 local testurl=ssh://127.0.0.1/$testroot
1835 local commit_id=`git_show_head $testroot/repo`
1837 got clone -q $testurl/repo $testroot/repo-clone
1838 ret=$?
1839 if [ $ret -ne 0 ]; then
1840 echo "got clone command failed unexpectedly" >&2
1841 test_done "$testroot" "$ret"
1842 return 1
1845 echo "modified alpha" > $testroot/repo/alpha
1846 git_commit $testroot/repo -m "modified alpha"
1847 local commit_id2=`git_show_head $testroot/repo`
1849 got fetch -q -r $testroot/repo-clone > $testroot/stdout
1850 ret=$?
1851 if [ $ret -ne 0 ]; then
1852 echo "got fetch command failed unexpectedly" >&2
1853 test_done "$testroot" "$ret"
1854 return 1
1857 echo -n > $testroot/stdout.expected
1859 cmp -s $testroot/stdout $testroot/stdout.expected
1860 ret=$?
1861 if [ $ret -ne 0 ]; then
1862 diff -u $testroot/stdout.expected $testroot/stdout
1863 test_done "$testroot" "$ret"
1864 return 1
1867 got ref -l -r $testroot/repo-clone > $testroot/stdout
1869 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1870 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1871 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1872 >> $testroot/stdout.expected
1873 echo "refs/remotes/origin/master: $commit_id2" \
1874 >> $testroot/stdout.expected
1876 cmp -s $testroot/stdout $testroot/stdout.expected
1877 ret=$?
1878 if [ $ret -ne 0 ]; then
1879 diff -u $testroot/stdout.expected $testroot/stdout
1880 test_done "$testroot" "$ret"
1881 return 1
1884 got checkout $testroot/repo-clone $testroot/wt > /dev/null
1886 echo "modified beta" > $testroot/wt/beta
1887 (cd $testroot/wt && got commit -m "modified beta" > /dev/null)
1888 local commit_id3=`git_show_head $testroot/repo-clone`
1890 (cd $testroot/wt && got update > /dev/null)
1891 (cd $testroot/wt && got merge origin/master > $testroot/stdout)
1892 local merge_commit_id=`git_show_head $testroot/repo-clone`
1894 cat > $testroot/stdout.expected <<EOF
1895 G alpha
1896 Merged refs/remotes/origin/master into refs/heads/master: $merge_commit_id
1897 EOF
1899 cmp -s $testroot/stdout $testroot/stdout.expected
1900 ret=$?
1901 if [ $ret -ne 0 ]; then
1902 diff -u $testroot/stdout.expected $testroot/stdout
1904 test_done "$testroot" "$ret"
1907 test_merge_fetched_branch_remote() {
1908 local testroot=`test_init merge_fetched_branch_remote`
1909 local testurl=ssh://127.0.0.1/$testroot
1910 local commit_id=`git_show_head $testroot/repo`
1912 got clone -q $testurl/repo $testroot/repo-clone
1913 ret=$?
1914 if [ $ret -ne 0 ]; then
1915 echo "got clone command failed unexpectedly" >&2
1916 test_done "$testroot" "$ret"
1917 return 1
1920 echo "modified alpha" > $testroot/repo/alpha
1921 git_commit $testroot/repo -m "modified alpha"
1922 local commit_id2=`git_show_head $testroot/repo`
1924 got fetch -q -r $testroot/repo-clone > $testroot/stdout
1925 ret=$?
1926 if [ $ret -ne 0 ]; then
1927 echo "got fetch command failed unexpectedly" >&2
1928 test_done "$testroot" "$ret"
1929 return 1
1932 echo -n > $testroot/stdout.expected
1934 cmp -s $testroot/stdout $testroot/stdout.expected
1935 ret=$?
1936 if [ $ret -ne 0 ]; then
1937 diff -u $testroot/stdout.expected $testroot/stdout
1938 test_done "$testroot" "$ret"
1939 return 1
1942 got ref -l -r $testroot/repo-clone > $testroot/stdout
1944 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1945 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1946 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1947 >> $testroot/stdout.expected
1948 echo "refs/remotes/origin/master: $commit_id2" \
1949 >> $testroot/stdout.expected
1951 cmp -s $testroot/stdout $testroot/stdout.expected
1952 ret=$?
1953 if [ $ret -ne 0 ]; then
1954 diff -u $testroot/stdout.expected $testroot/stdout
1955 test_done "$testroot" "$ret"
1956 return 1
1959 got checkout $testroot/repo-clone $testroot/wt > /dev/null
1961 echo "modified beta" > $testroot/wt/beta
1962 (cd $testroot/wt && got commit -m "modified beta" > /dev/null)
1963 local commit_id3=`git_show_head $testroot/repo-clone`
1965 (cd $testroot/wt && got update -b origin/master > /dev/null)
1966 (cd $testroot/wt && got merge master > \
1967 $testroot/stdout 2> $testroot/stderr)
1968 local merge_commit_id=`git_show_head $testroot/repo-clone`
1970 echo -n > $testroot/stdout.expected
1972 cmp -s $testroot/stdout $testroot/stdout.expected
1973 ret=$?
1974 if [ $ret -ne 0 ]; then
1975 diff -u $testroot/stdout.expected $testroot/stdout
1976 test_done "$testroot" "$ret"
1977 return 1
1980 echo -n "got: work tree's current branch refs/remotes/origin/master " \
1981 > $testroot/stderr.expected
1982 echo -n 'is outside the "refs/heads/" reference namespace; ' \
1983 >> $testroot/stderr.expected
1984 echo -n "update -b required: will not commit to a branch " \
1985 >> $testroot/stderr.expected
1986 echo 'outside the "refs/heads/" reference namespace' \
1987 >> $testroot/stderr.expected
1989 cmp -s $testroot/stderr $testroot/stderr.expected
1990 ret=$?
1991 if [ $ret -ne 0 ]; then
1992 diff -u $testroot/stderr.expected $testroot/stderr
1994 test_done "$testroot" "$ret"
1997 test_parseargs "$@"
1998 run_test test_merge_basic
1999 run_test test_merge_forward
2000 run_test test_merge_forward_commit
2001 run_test test_merge_forward_interrupt
2002 run_test test_merge_backward
2003 run_test test_merge_continue
2004 run_test test_merge_continue_new_commit
2005 run_test test_merge_abort
2006 run_test test_merge_in_progress
2007 run_test test_merge_path_prefix
2008 run_test test_merge_missing_file
2009 run_test test_merge_no_op
2010 run_test test_merge_imported_branch
2011 run_test test_merge_interrupt
2012 run_test test_merge_umask
2013 run_test test_merge_gitconfig_author
2014 run_test test_merge_fetched_branch
2015 run_test test_merge_fetched_branch_remote