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 (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
53 fi
55 # create a divergent commit
56 (cd $testroot/repo && git checkout -q master)
57 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
58 git_commit $testroot/repo -m "committing to zeta on master"
59 local master_commit=`git_show_head $testroot/repo`
61 # need an up-to-date work tree for 'got merge'
62 (cd $testroot/wt && got merge newbranch \
63 > $testroot/stdout 2> $testroot/stderr)
64 ret=$?
65 if [ $ret -eq 0 ]; then
66 echo "got merge succeeded unexpectedly" >&2
67 test_done "$testroot" "1"
68 return 1
69 fi
70 echo -n "got: work tree must be updated before it can be used " \
71 > $testroot/stderr.expected
72 echo "to merge a branch" >> $testroot/stderr.expected
73 cmp -s $testroot/stderr.expected $testroot/stderr
74 ret=$?
75 if [ $ret -ne 0 ]; then
76 diff -u $testroot/stderr.expected $testroot/stderr
77 test_done "$testroot" "$ret"
78 return 1
79 fi
81 (cd $testroot/wt && got update > /dev/null)
82 ret=$?
83 if [ $ret -ne 0 ]; then
84 echo "got update failed unexpectedly" >&2
85 test_done "$testroot" "$ret"
86 return 1
87 fi
89 # must not use a mixed-commit work tree with 'got merge'
90 (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
91 ret=$?
92 if [ $ret -ne 0 ]; then
93 echo "got update failed unexpectedly" >&2
94 test_done "$testroot" "$ret"
95 return 1
96 fi
97 (cd $testroot/wt && got merge newbranch \
98 > $testroot/stdout 2> $testroot/stderr)
99 ret=$?
100 if [ $ret -eq 0 ]; then
101 echo "got merge succeeded unexpectedly" >&2
102 test_done "$testroot" "1"
103 return 1
104 fi
105 echo -n "got: work tree contains files from multiple base commits; " \
106 > $testroot/stderr.expected
107 echo "the entire work tree must be updated first" \
108 >> $testroot/stderr.expected
109 cmp -s $testroot/stderr.expected $testroot/stderr
110 ret=$?
111 if [ $ret -ne 0 ]; then
112 diff -u $testroot/stderr.expected $testroot/stderr
113 test_done "$testroot" "$ret"
114 return 1
115 fi
117 (cd $testroot/wt && got update > /dev/null)
118 ret=$?
119 if [ $ret -ne 0 ]; then
120 echo "got update failed unexpectedly" >&2
121 test_done "$testroot" "$ret"
122 return 1
123 fi
125 # must not have staged files with 'got merge'
126 echo "modified file alpha" > $testroot/wt/alpha
127 (cd $testroot/wt && got stage alpha > /dev/null)
128 ret=$?
129 if [ $ret -ne 0 ]; then
130 echo "got stage failed unexpectedly" >&2
131 test_done "$testroot" "$ret"
132 return 1
133 fi
134 (cd $testroot/wt && got merge newbranch \
135 > $testroot/stdout 2> $testroot/stderr)
136 ret=$?
137 if [ $ret -eq 0 ]; then
138 echo "got merge succeeded unexpectedly" >&2
139 test_done "$testroot" "1"
140 return 1
141 fi
142 echo "got: alpha: file is staged" > $testroot/stderr.expected
143 cmp -s $testroot/stderr.expected $testroot/stderr
144 ret=$?
145 if [ $ret -ne 0 ]; then
146 diff -u $testroot/stderr.expected $testroot/stderr
147 test_done "$testroot" "$ret"
148 return 1
149 fi
150 (cd $testroot/wt && got unstage alpha > /dev/null)
151 ret=$?
152 if [ $ret -ne 0 ]; then
153 echo "got unstage failed unexpectedly" >&2
154 test_done "$testroot" "$ret"
155 return 1
156 fi
158 # must not have local changes with 'got merge'
159 (cd $testroot/wt && got merge newbranch \
160 > $testroot/stdout 2> $testroot/stderr)
161 ret=$?
162 if [ $ret -eq 0 ]; then
163 echo "got merge succeeded unexpectedly" >&2
164 test_done "$testroot" "1"
165 return 1
166 fi
167 echo -n "got: work tree contains local changes; " \
168 > $testroot/stderr.expected
169 echo "these changes must be committed or reverted first" \
170 >> $testroot/stderr.expected
171 cmp -s $testroot/stderr.expected $testroot/stderr
172 ret=$?
173 if [ $ret -ne 0 ]; then
174 diff -u $testroot/stderr.expected $testroot/stderr
175 test_done "$testroot" "$ret"
176 return 1
177 fi
179 (cd $testroot/wt && got revert alpha > /dev/null)
180 ret=$?
181 if [ $ret -ne 0 ]; then
182 echo "got revert failed unexpectedly" >&2
183 test_done "$testroot" "$ret"
184 return 1
185 fi
187 (cd $testroot/wt && got merge newbranch > $testroot/stdout)
188 ret=$?
189 if [ $ret -ne 0 ]; then
190 echo "got merge failed unexpectedly" >&2
191 test_done "$testroot" "$ret"
192 return 1
193 fi
195 local merge_commit=`git_show_head $testroot/repo`
197 echo "G alpha" >> $testroot/stdout.expected
198 echo "D beta" >> $testroot/stdout.expected
199 echo "A dotgotbar.link" >> $testroot/stdout.expected
200 echo "A epsilon/new" >> $testroot/stdout.expected
201 echo "G gamma/delta" >> $testroot/stdout.expected
202 echo "A symlink" >> $testroot/stdout.expected
203 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
204 >> $testroot/stdout.expected
205 echo $merge_commit >> $testroot/stdout.expected
207 cmp -s $testroot/stdout.expected $testroot/stdout
208 ret=$?
209 if [ $ret -ne 0 ]; then
210 diff -u $testroot/stdout.expected $testroot/stdout
211 test_done "$testroot" "$ret"
212 return 1
213 fi
215 echo "modified delta on branch" > $testroot/content.expected
216 cat $testroot/wt/gamma/delta > $testroot/content
217 cmp -s $testroot/content.expected $testroot/content
218 ret=$?
219 if [ $ret -ne 0 ]; then
220 diff -u $testroot/content.expected $testroot/content
221 test_done "$testroot" "$ret"
222 return 1
223 fi
225 echo "modified alpha on branch" > $testroot/content.expected
226 cat $testroot/wt/alpha > $testroot/content
227 cmp -s $testroot/content.expected $testroot/content
228 ret=$?
229 if [ $ret -ne 0 ]; then
230 diff -u $testroot/content.expected $testroot/content
231 test_done "$testroot" "$ret"
232 return 1
233 fi
235 if [ -e $testroot/wt/beta ]; then
236 echo "removed file beta still exists on disk" >&2
237 test_done "$testroot" "1"
238 return 1
239 fi
241 echo "new file on branch" > $testroot/content.expected
242 cat $testroot/wt/epsilon/new > $testroot/content
243 cmp -s $testroot/content.expected $testroot/content
244 ret=$?
245 if [ $ret -ne 0 ]; then
246 diff -u $testroot/content.expected $testroot/content
247 test_done "$testroot" "$ret"
248 return 1
249 fi
251 if [ ! -h $testroot/wt/dotgotbar.link ]; then
252 echo "dotgotbar.link is not a symlink"
253 test_done "$testroot" "1"
254 return 1
255 fi
257 readlink $testroot/wt/symlink > $testroot/stdout
258 echo "alpha" > $testroot/stdout.expected
259 cmp -s $testroot/stdout.expected $testroot/stdout
260 ret=$?
261 if [ $ret -ne 0 ]; then
262 diff -u $testroot/stdout.expected $testroot/stdout
263 test_done "$testroot" "$ret"
264 return 1
265 fi
267 (cd $testroot/wt && got status > $testroot/stdout)
269 echo -n > $testroot/stdout.expected
270 cmp -s $testroot/stdout.expected $testroot/stdout
271 ret=$?
272 if [ $ret -ne 0 ]; then
273 diff -u $testroot/stdout.expected $testroot/stdout
274 test_done "$testroot" "$ret"
275 return 1
276 fi
278 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
279 echo "commit $merge_commit (master)" > $testroot/stdout.expected
280 echo "commit $master_commit" >> $testroot/stdout.expected
281 echo "commit $commit0" >> $testroot/stdout.expected
282 cmp -s $testroot/stdout.expected $testroot/stdout
283 ret=$?
284 if [ $ret -ne 0 ]; then
285 diff -u $testroot/stdout.expected $testroot/stdout
286 test_done "$testroot" "$ret"
287 return 1
288 fi
290 (cd $testroot/wt && got update > $testroot/stdout)
292 echo 'U dotgotbar.link' > $testroot/stdout.expected
293 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
294 git_show_head $testroot/repo >> $testroot/stdout.expected
295 echo >> $testroot/stdout.expected
296 cmp -s $testroot/stdout.expected $testroot/stdout
297 ret=$?
298 if [ $ret -ne 0 ]; then
299 diff -u $testroot/stdout.expected $testroot/stdout
300 test_done "$testroot" "$ret"
301 return 1
302 fi
304 # update has changed the bad symlink into a regular file
305 if [ -h $testroot/wt/dotgotbar.link ]; then
306 echo "dotgotbar.link is a symlink"
307 test_done "$testroot" "1"
308 return 1
309 fi
311 # We should have created a merge commit with two parents.
312 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
313 echo "parent 1: $master_commit" > $testroot/stdout.expected
314 echo "parent 2: $branch_commit5" >> $testroot/stdout.expected
315 cmp -s $testroot/stdout.expected $testroot/stdout
316 ret=$?
317 if [ $ret -ne 0 ]; then
318 diff -u $testroot/stdout.expected $testroot/stdout
319 test_done "$testroot" "$ret"
320 return 1
321 fi
323 got tree -r $testroot/repo -c $merge_commit -R > $testroot/stdout
324 ret=$?
325 if [ $ret -ne 0 ]; then
326 echo "got tree failed unexpectedly" >&2
327 test_done "$testroot" "$ret"
328 return 1
329 fi
331 # bad symlink dotgotbar.link appears as a symlink in the merge commit:
332 cat > $testroot/stdout.expected <<EOF
333 alpha
334 dotgotbar.link@ -> .got/bar
335 epsilon/
336 epsilon/new
337 epsilon/zeta
338 gamma/
339 gamma/delta
340 symlink@ -> alpha
341 EOF
342 cmp -s $testroot/stdout.expected $testroot/stdout
343 ret=$?
344 if [ $ret -ne 0 ]; then
345 diff -u $testroot/stdout.expected $testroot/stdout
346 fi
347 test_done "$testroot" "$ret"
350 test_merge_forward() {
351 local testroot=`test_init merge_forward`
352 local commit0=`git_show_head $testroot/repo`
354 # Create a commit before branching, which will be used to help test
355 # preconditions for "got merge".
356 echo "modified alpha" > $testroot/repo/alpha
357 git_commit $testroot/repo -m "common commit"
358 local commit1=`git_show_head $testroot/repo`
360 (cd $testroot/repo && git checkout -q -b newbranch)
361 echo "modified beta on branch" > $testroot/repo/beta
362 git_commit $testroot/repo -m "committing to beta on newbranch"
363 local commit2=`git_show_head $testroot/repo`
365 got checkout -b master $testroot/repo $testroot/wt > /dev/null
366 ret=$?
367 if [ $ret -ne 0 ]; then
368 echo "got checkout failed unexpectedly" >&2
369 test_done "$testroot" "$ret"
370 return 1
371 fi
373 # must not use a mixed-commit work tree with 'got merge'
374 (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
375 ret=$?
376 if [ $ret -ne 0 ]; then
377 echo "got update failed unexpectedly" >&2
378 test_done "$testroot" "$ret"
379 return 1
380 fi
381 (cd $testroot/wt && got merge newbranch \
382 > $testroot/stdout 2> $testroot/stderr)
383 ret=$?
384 if [ $ret -eq 0 ]; then
385 echo "got merge succeeded unexpectedly" >&2
386 test_done "$testroot" "$ret"
387 return 1
388 fi
389 echo -n "got: work tree contains files from multiple base commits; " \
390 > $testroot/stderr.expected
391 echo "the entire work tree must be updated first" \
392 >> $testroot/stderr.expected
393 cmp -s $testroot/stderr.expected $testroot/stderr
394 ret=$?
395 if [ $ret -ne 0 ]; then
396 diff -u $testroot/stderr.expected $testroot/stderr
397 test_done "$testroot" "$ret"
398 return 1
399 fi
401 (cd $testroot/wt && got update > /dev/null)
402 ret=$?
403 if [ $ret -ne 0 ]; then
404 echo "got update failed unexpectedly" >&2
405 test_done "$testroot" "$ret"
406 return 1
407 fi
409 # 'got merge -n' refuses to fast-forward
410 (cd $testroot/wt && got merge -n newbranch \
411 > $testroot/stdout 2> $testroot/stderr)
412 ret=$?
413 if [ $ret -eq 0 ]; then
414 echo "got merge succeeded unexpectedly" >&2
415 test_done "$testroot" "1"
416 return 1
417 fi
419 echo -n "got: there are no changes to merge since " \
420 > $testroot/stderr.expected
421 echo -n "refs/heads/newbranch is already based on " \
422 >> $testroot/stderr.expected
423 echo -n "refs/heads/master; merge cannot be interrupted " \
424 >> $testroot/stderr.expected
425 echo "for amending; -n: option cannot be used" \
426 >> $testroot/stderr.expected
428 cmp -s $testroot/stderr.expected $testroot/stderr
429 ret=$?
430 if [ $ret -ne 0 ]; then
431 diff -u $testroot/stderr.expected $testroot/stderr
432 test_done "$testroot" "$ret"
433 return 1
434 fi
436 (cd $testroot/wt && got merge newbranch \
437 > $testroot/stdout 2> $testroot/stderr)
438 ret=$?
439 if [ $ret -ne 0 ]; then
440 echo "got merge failed unexpectedly" >&2
441 test_done "$testroot" "$ret"
442 return 1
443 fi
445 echo "Forwarding refs/heads/master to refs/heads/newbranch" \
446 > $testroot/stdout.expected
447 echo "U beta" >> $testroot/stdout.expected
448 echo "Updated to commit $commit2" \
449 >> $testroot/stdout.expected
450 cmp -s $testroot/stdout.expected $testroot/stdout
451 ret=$?
452 if [ $ret -ne 0 ]; then
453 diff -u $testroot/stdout.expected $testroot/stdout
454 test_done "$testroot" "$ret"
455 return 1
456 fi
458 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
459 echo -n "commit $commit2 " > $testroot/stdout.expected
460 echo "(master, newbranch)" >> $testroot/stdout.expected
461 echo "commit $commit1" >> $testroot/stdout.expected
462 echo "commit $commit0" >> $testroot/stdout.expected
463 cmp -s $testroot/stdout.expected $testroot/stdout
464 ret=$?
465 if [ $ret -ne 0 ]; then
466 diff -u $testroot/stdout.expected $testroot/stdout
467 test_done "$testroot" "$ret"
468 return 1
469 fi
470 test_done "$testroot" "$ret"
473 test_merge_forward_commit() {
474 local testroot=`test_init merge_forward_commit`
475 local commit0=`git_show_head $testroot/repo`
477 (cd $testroot/repo && git checkout -q -b newbranch)
478 echo "modified alpha on branch" > $testroot/repo/alpha
479 git_commit $testroot/repo -m "committing to alpha on newbranch"
480 local commit1=`git_show_head $testroot/repo`
482 got checkout -b master $testroot/repo $testroot/wt > /dev/null
483 ret=$?
484 if [ $ret -ne 0 ]; then
485 echo "got checkout failed unexpectedly" >&2
486 test_done "$testroot" "$ret"
487 return 1
488 fi
490 (cd $testroot/wt && got merge -M newbranch > $testroot/stdout)
491 ret=$?
492 if [ $ret -ne 0 ]; then
493 echo "got merge failed unexpectedly" >&2
494 test_done "$testroot" "$ret"
495 return 1
496 fi
498 local merge_commit=`git_show_branch_head $testroot/repo master`
500 echo "G alpha" >> $testroot/stdout.expected
501 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
502 >> $testroot/stdout.expected
503 echo $merge_commit >> $testroot/stdout.expected
505 cmp -s $testroot/stdout.expected $testroot/stdout
506 ret=$?
507 if [ $ret -ne 0 ]; then
508 diff -u $testroot/stdout.expected $testroot/stdout
509 test_done "$testroot" "$ret"
510 return 1
511 fi
513 # We should have created a merge commit with two parents.
514 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
515 echo "parent 1: $commit0" > $testroot/stdout.expected
516 echo "parent 2: $commit1" >> $testroot/stdout.expected
517 cmp -s $testroot/stdout.expected $testroot/stdout
518 ret=$?
519 if [ $ret -ne 0 ]; then
520 diff -u $testroot/stdout.expected $testroot/stdout
521 test_done "$testroot" "$ret"
522 return 1
523 fi
525 test_done "$testroot" "$ret"
528 test_merge_forward_interrupt() {
529 # Test -M and -n options together.
530 local testroot=`test_init merge_forward_commit`
531 local commit0=`git_show_head $testroot/repo`
533 (cd $testroot/repo && git checkout -q -b newbranch)
534 echo "modified alpha on branch" > $testroot/repo/alpha
535 git_commit $testroot/repo -m "committing to alpha on newbranch"
536 local commit1=`git_show_head $testroot/repo`
538 got checkout -b master $testroot/repo $testroot/wt > /dev/null
539 ret=$?
540 if [ $ret -ne 0 ]; then
541 echo "got checkout failed unexpectedly" >&2
542 test_done "$testroot" "$ret"
543 return 1
544 fi
546 (cd $testroot/wt && got merge -M -n newbranch > $testroot/stdout)
547 ret=$?
548 if [ $ret -ne 0 ]; then
549 echo "got merge failed unexpectedly" >&2
550 test_done "$testroot" "$ret"
551 return 1
552 fi
554 echo "G alpha" > $testroot/stdout.expected
555 echo "Merge of refs/heads/newbranch interrupted on request" \
556 >> $testroot/stdout.expected
557 cmp -s $testroot/stdout.expected $testroot/stdout
558 ret=$?
559 if [ $ret -ne 0 ]; then
560 diff -u $testroot/stdout.expected $testroot/stdout
561 test_done "$testroot" "$ret"
562 return 1
563 fi
565 # Continue the merge.
566 (cd $testroot/wt && got merge -c > $testroot/stdout)
567 ret=$?
568 if [ $ret -ne 0 ]; then
569 echo "got merge failed unexpectedly" >&2
570 test_done "$testroot" "$ret"
571 return 1
572 fi
574 local merge_commit=`git_show_branch_head $testroot/repo master`
576 echo "M alpha" > $testroot/stdout.expected
577 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
578 >> $testroot/stdout.expected
579 echo $merge_commit >> $testroot/stdout.expected
581 cmp -s $testroot/stdout.expected $testroot/stdout
582 ret=$?
583 if [ $ret -ne 0 ]; then
584 diff -u $testroot/stdout.expected $testroot/stdout
585 test_done "$testroot" "$ret"
586 return 1
587 fi
589 # We should have created a merge commit with two parents.
590 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
591 echo "parent 1: $commit0" > $testroot/stdout.expected
592 echo "parent 2: $commit1" >> $testroot/stdout.expected
593 cmp -s $testroot/stdout.expected $testroot/stdout
594 ret=$?
595 if [ $ret -ne 0 ]; then
596 diff -u $testroot/stdout.expected $testroot/stdout
597 fi
598 test_done "$testroot" "$ret"
601 test_merge_backward() {
602 local testroot=`test_init merge_backward`
603 local commit0=`git_show_head $testroot/repo`
605 (cd $testroot/repo && git checkout -q -b newbranch)
606 (cd $testroot/repo && git checkout -q master)
607 echo "modified alpha on master" > $testroot/repo/alpha
608 git_commit $testroot/repo -m "committing to alpha on master"
610 got checkout -b master $testroot/repo $testroot/wt > /dev/null
611 ret=$?
612 if [ $ret -ne 0 ]; then
613 echo "got checkout failed unexpectedly" >&2
614 test_done "$testroot" "$ret"
615 return 1
616 fi
618 (cd $testroot/wt && got merge newbranch \
619 > $testroot/stdout 2> $testroot/stderr)
620 ret=$?
621 if [ $ret -ne 0 ]; then
622 echo "got merge failed unexpectedly" >&2
623 test_done "$testroot" "$ret"
624 return 1
625 fi
626 echo "Already up-to-date" > $testroot/stdout.expected
627 cmp -s $testroot/stdout.expected $testroot/stdout
628 ret=$?
629 if [ $ret -ne 0 ]; then
630 diff -u $testroot/stdout.expected $testroot/stdout
631 test_done "$testroot" "$ret"
632 return 1
633 fi
634 test_done "$testroot" "$ret"
637 test_merge_continue() {
638 local testroot=`test_init merge_continue`
639 local commit0=`git_show_head $testroot/repo`
640 local commit0_author_time=`git_show_author_time $testroot/repo`
642 (cd $testroot/repo && git checkout -q -b newbranch)
643 echo "modified delta on branch" > $testroot/repo/gamma/delta
644 git_commit $testroot/repo -m "committing to delta on newbranch"
645 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
647 echo "modified alpha on branch" > $testroot/repo/alpha
648 git_commit $testroot/repo -m "committing to alpha on newbranch"
649 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
650 (cd $testroot/repo && git rm -q beta)
651 git_commit $testroot/repo -m "removing beta on newbranch"
652 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
653 echo "new file on branch" > $testroot/repo/epsilon/new
654 (cd $testroot/repo && git add epsilon/new)
655 git_commit $testroot/repo -m "adding new file on newbranch"
656 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
658 got checkout -b master $testroot/repo $testroot/wt > /dev/null
659 ret=$?
660 if [ $ret -ne 0 ]; then
661 echo "got checkout failed unexpectedly" >&2
662 test_done "$testroot" "$ret"
663 return 1
664 fi
666 # create a conflicting commit
667 (cd $testroot/repo && git checkout -q master)
668 echo "modified alpha on master" > $testroot/repo/alpha
669 git_commit $testroot/repo -m "committing to alpha on master"
670 local master_commit=`git_show_head $testroot/repo`
672 # need an up-to-date work tree for 'got merge'
673 (cd $testroot/wt && got update > /dev/null)
674 ret=$?
675 if [ $ret -ne 0 ]; then
676 echo "got update failed unexpectedly" >&2
677 test_done "$testroot" "$ret"
678 return 1
679 fi
681 (cd $testroot/wt && got merge newbranch \
682 > $testroot/stdout 2> $testroot/stderr)
683 ret=$?
684 if [ $ret -eq 0 ]; then
685 echo "got merge succeeded unexpectedly" >&2
686 test_done "$testroot" "1"
687 return 1
688 fi
690 echo "C alpha" >> $testroot/stdout.expected
691 echo "D beta" >> $testroot/stdout.expected
692 echo "A epsilon/new" >> $testroot/stdout.expected
693 echo "G gamma/delta" >> $testroot/stdout.expected
694 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
695 cmp -s $testroot/stdout.expected $testroot/stdout
696 ret=$?
697 if [ $ret -ne 0 ]; then
698 diff -u $testroot/stdout.expected $testroot/stdout
699 test_done "$testroot" "$ret"
700 return 1
701 fi
703 echo "got: conflicts must be resolved before merging can continue" \
704 > $testroot/stderr.expected
705 cmp -s $testroot/stderr.expected $testroot/stderr
706 ret=$?
707 if [ $ret -ne 0 ]; then
708 diff -u $testroot/stderr.expected $testroot/stderr
709 test_done "$testroot" "$ret"
710 return 1
711 fi
713 (cd $testroot/wt && got status > $testroot/stdout)
715 echo "C alpha" > $testroot/stdout.expected
716 echo "D beta" >> $testroot/stdout.expected
717 echo "A epsilon/new" >> $testroot/stdout.expected
718 echo "M gamma/delta" >> $testroot/stdout.expected
719 cmp -s $testroot/stdout.expected $testroot/stdout
720 ret=$?
721 if [ $ret -ne 0 ]; then
722 diff -u $testroot/stdout.expected $testroot/stdout
723 test_done "$testroot" "$ret"
724 return 1
725 fi
727 echo '<<<<<<<' > $testroot/content.expected
728 echo "modified alpha on master" >> $testroot/content.expected
729 echo "||||||| 3-way merge base: commit $commit0" \
730 >> $testroot/content.expected
731 echo "alpha" >> $testroot/content.expected
732 echo "=======" >> $testroot/content.expected
733 echo "modified alpha on branch" >> $testroot/content.expected
734 echo ">>>>>>> merged change: commit $branch_commit3" \
735 >> $testroot/content.expected
736 cat $testroot/wt/alpha > $testroot/content
737 cmp -s $testroot/content.expected $testroot/content
738 ret=$?
739 if [ $ret -ne 0 ]; then
740 diff -u $testroot/content.expected $testroot/content
741 test_done "$testroot" "$ret"
742 return 1
743 fi
745 # resolve the conflict
746 echo "modified alpha by both branches" > $testroot/wt/alpha
748 (cd $testroot/wt && got merge -c > $testroot/stdout)
749 ret=$?
750 if [ $ret -ne 0 ]; then
751 echo "got merge failed unexpectedly" >&2
752 test_done "$testroot" "$ret"
753 return 1
754 fi
756 local merge_commit=`git_show_head $testroot/repo`
758 echo "M alpha" > $testroot/stdout.expected
759 echo "D beta" >> $testroot/stdout.expected
760 echo "A epsilon/new" >> $testroot/stdout.expected
761 echo "M gamma/delta" >> $testroot/stdout.expected
762 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
763 >> $testroot/stdout.expected
764 echo $merge_commit >> $testroot/stdout.expected
766 cmp -s $testroot/stdout.expected $testroot/stdout
767 ret=$?
768 if [ $ret -ne 0 ]; then
769 diff -u $testroot/stdout.expected $testroot/stdout
770 test_done "$testroot" "$ret"
771 return 1
772 fi
774 echo "modified delta on branch" > $testroot/content.expected
775 cat $testroot/wt/gamma/delta > $testroot/content
776 cmp -s $testroot/content.expected $testroot/content
777 ret=$?
778 if [ $ret -ne 0 ]; then
779 diff -u $testroot/content.expected $testroot/content
780 test_done "$testroot" "$ret"
781 return 1
782 fi
784 echo "modified alpha by both branches" > $testroot/content.expected
785 cat $testroot/wt/alpha > $testroot/content
786 cmp -s $testroot/content.expected $testroot/content
787 ret=$?
788 if [ $ret -ne 0 ]; then
789 diff -u $testroot/content.expected $testroot/content
790 test_done "$testroot" "$ret"
791 return 1
792 fi
794 if [ -e $testroot/wt/beta ]; then
795 echo "removed file beta still exists on disk" >&2
796 test_done "$testroot" "1"
797 return 1
798 fi
800 echo "new file on branch" > $testroot/content.expected
801 cat $testroot/wt/epsilon/new > $testroot/content
802 cmp -s $testroot/content.expected $testroot/content
803 ret=$?
804 if [ $ret -ne 0 ]; then
805 diff -u $testroot/content.expected $testroot/content
806 test_done "$testroot" "$ret"
807 return 1
808 fi
810 (cd $testroot/wt && got status > $testroot/stdout)
812 echo -n > $testroot/stdout.expected
813 cmp -s $testroot/stdout.expected $testroot/stdout
814 ret=$?
815 if [ $ret -ne 0 ]; then
816 diff -u $testroot/stdout.expected $testroot/stdout
817 test_done "$testroot" "$ret"
818 return 1
819 fi
821 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
822 echo "commit $merge_commit (master)" > $testroot/stdout.expected
823 echo "commit $master_commit" >> $testroot/stdout.expected
824 echo "commit $commit0" >> $testroot/stdout.expected
825 cmp -s $testroot/stdout.expected $testroot/stdout
826 ret=$?
827 if [ $ret -ne 0 ]; then
828 diff -u $testroot/stdout.expected $testroot/stdout
829 test_done "$testroot" "$ret"
830 return 1
831 fi
833 (cd $testroot/wt && got update > $testroot/stdout)
835 echo 'Already up-to-date' > $testroot/stdout.expected
836 cmp -s $testroot/stdout.expected $testroot/stdout
837 ret=$?
838 if [ $ret -ne 0 ]; then
839 diff -u $testroot/stdout.expected $testroot/stdout
840 test_done "$testroot" "$ret"
841 return 1
842 fi
844 # We should have created a merge commit with two parents.
845 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
846 echo "parent 1: $master_commit" > $testroot/stdout.expected
847 echo "parent 2: $branch_commit3" >> $testroot/stdout.expected
848 cmp -s $testroot/stdout.expected $testroot/stdout
849 ret=$?
850 if [ $ret -ne 0 ]; then
851 diff -u $testroot/stdout.expected $testroot/stdout
852 fi
853 test_done "$testroot" "$ret"
856 test_merge_continue_new_commit() {
857 # "got merge -c" should refuse to run if the current branch tip has
858 # changed since the merge was started, to avoid clobbering the changes.
859 local testroot=`test_init merge_continue_new_commit`
861 (cd $testroot/repo && git checkout -q -b newbranch)
862 echo "modified delta on branch" > $testroot/repo/gamma/delta
863 git_commit $testroot/repo -m "committing to delta on newbranch"
865 (cd $testroot/repo && git checkout -q master)
866 echo "modified alpha on master" > $testroot/repo/alpha
867 git_commit $testroot/repo -m "committing to alpha on master"
869 got checkout -b master $testroot/repo $testroot/wt > /dev/null
870 ret=$?
871 if [ $ret -ne 0 ]; then
872 echo "got checkout failed unexpectedly" >&2
873 test_done "$testroot" "$ret"
874 return 1
875 fi
877 (cd $testroot/wt && got merge -n newbranch >/dev/null)
878 ret=$?
879 if [ $ret -ne 0 ]; then
880 echo "got merge failed unexpectedly" >&2
881 test_done "$testroot" "$ret"
882 return 1
883 fi
885 echo "modified alpha again on master" > $testroot/repo/alpha
886 git_commit $testroot/repo -m "committing to alpha on master again"
888 (cd $testroot/wt && got merge -c > $testroot/stdout 2> $testroot/stderr)
889 ret=$?
890 if [ $ret -eq 0 ]; then
891 echo "got merge succeeded unexpectedly" >&2
892 test_done "$testroot" "1"
893 return 1
894 fi
896 echo -n > $testroot/stdout.expected
897 cmp -s $testroot/stdout.expected $testroot/stdout
898 ret=$?
899 if [ $ret -ne 0 ]; then
900 diff -u $testroot/stdout.expected $testroot/stdout
901 test_done "$testroot" "$ret"
902 return 1
903 fi
905 echo -n "got: merging cannot proceed because the work tree is no " \
906 > $testroot/stderr.expected
907 echo "longer up-to-date; merge must be aborted and retried" \
908 >> $testroot/stderr.expected
909 cmp -s $testroot/stderr.expected $testroot/stderr
910 ret=$?
911 if [ $ret -ne 0 ]; then
912 diff -u $testroot/stderr.expected $testroot/stderr
913 fi
914 test_done "$testroot" "$ret"
917 test_merge_abort() {
918 local testroot=`test_init merge_abort`
919 local commit0=`git_show_head $testroot/repo`
920 local commit0_author_time=`git_show_author_time $testroot/repo`
922 (cd $testroot/repo && git checkout -q -b newbranch)
923 echo "modified delta on branch" > $testroot/repo/gamma/delta
924 git_commit $testroot/repo -m "committing to delta on newbranch"
925 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
927 echo "modified alpha on branch" > $testroot/repo/alpha
928 git_commit $testroot/repo -m "committing to alpha on newbranch"
929 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
930 (cd $testroot/repo && git rm -q beta)
931 git_commit $testroot/repo -m "removing beta on newbranch"
932 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
933 echo "new file on branch" > $testroot/repo/epsilon/new
934 (cd $testroot/repo && git add epsilon/new)
935 git_commit $testroot/repo -m "adding new file on newbranch"
936 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
937 (cd $testroot/repo && ln -s alpha symlink && git add symlink)
938 git_commit $testroot/repo -m "adding symlink on newbranch"
939 local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
941 got checkout -b master $testroot/repo $testroot/wt > /dev/null
942 ret=$?
943 if [ $ret -ne 0 ]; then
944 echo "got checkout failed unexpectedly" >&2
945 test_done "$testroot" "$ret"
946 return 1
947 fi
949 # unrelated unversioned file in work tree
950 touch $testroot/wt/unversioned-file
952 # create a conflicting commit
953 (cd $testroot/repo && git checkout -q master)
954 echo "modified alpha on master" > $testroot/repo/alpha
955 git_commit $testroot/repo -m "committing to alpha on master"
956 local master_commit=`git_show_head $testroot/repo`
958 # need an up-to-date work tree for 'got merge'
959 (cd $testroot/wt && got update > /dev/null)
960 ret=$?
961 if [ $ret -ne 0 ]; then
962 echo "got update failed unexpectedly" >&2
963 test_done "$testroot" "$ret"
964 return 1
965 fi
967 (cd $testroot/wt && got merge newbranch \
968 > $testroot/stdout 2> $testroot/stderr)
969 ret=$?
970 if [ $ret -eq 0 ]; then
971 echo "got merge succeeded unexpectedly" >&2
972 test_done "$testroot" "1"
973 return 1
974 fi
976 echo "C alpha" >> $testroot/stdout.expected
977 echo "D beta" >> $testroot/stdout.expected
978 echo "A epsilon/new" >> $testroot/stdout.expected
979 echo "G gamma/delta" >> $testroot/stdout.expected
980 echo "A symlink" >> $testroot/stdout.expected
981 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
982 cmp -s $testroot/stdout.expected $testroot/stdout
983 ret=$?
984 if [ $ret -ne 0 ]; then
985 diff -u $testroot/stdout.expected $testroot/stdout
986 test_done "$testroot" "$ret"
987 return 1
988 fi
990 echo "got: conflicts must be resolved before merging can continue" \
991 > $testroot/stderr.expected
992 cmp -s $testroot/stderr.expected $testroot/stderr
993 ret=$?
994 if [ $ret -ne 0 ]; then
995 diff -u $testroot/stderr.expected $testroot/stderr
996 test_done "$testroot" "$ret"
997 return 1
998 fi
1000 # unrelated added file added during conflict resolution
1001 touch $testroot/wt/added-file
1002 (cd $testroot/wt && got add added-file > /dev/null)
1004 (cd $testroot/wt && got status > $testroot/stdout)
1006 echo "A added-file" > $testroot/stdout.expected
1007 echo "C alpha" >> $testroot/stdout.expected
1008 echo "D beta" >> $testroot/stdout.expected
1009 echo "A epsilon/new" >> $testroot/stdout.expected
1010 echo "M gamma/delta" >> $testroot/stdout.expected
1011 echo "A symlink" >> $testroot/stdout.expected
1012 echo "? unversioned-file" >> $testroot/stdout.expected
1013 cmp -s $testroot/stdout.expected $testroot/stdout
1014 ret=$?
1015 if [ $ret -ne 0 ]; then
1016 diff -u $testroot/stdout.expected $testroot/stdout
1017 test_done "$testroot" "$ret"
1018 return 1
1021 (cd $testroot/wt && got merge -a > $testroot/stdout)
1022 ret=$?
1023 if [ $ret -ne 0 ]; then
1024 echo "got merge failed unexpectedly" >&2
1025 test_done "$testroot" "$ret"
1026 return 1
1029 echo "R added-file" > $testroot/stdout.expected
1030 echo "R alpha" >> $testroot/stdout.expected
1031 echo "R beta" >> $testroot/stdout.expected
1032 echo "R epsilon/new" >> $testroot/stdout.expected
1033 echo "R gamma/delta" >> $testroot/stdout.expected
1034 echo "R symlink" >> $testroot/stdout.expected
1035 echo "G added-file" >> $testroot/stdout.expected
1036 echo "Merge of refs/heads/newbranch aborted" \
1037 >> $testroot/stdout.expected
1039 cmp -s $testroot/stdout.expected $testroot/stdout
1040 ret=$?
1041 if [ $ret -ne 0 ]; then
1042 diff -u $testroot/stdout.expected $testroot/stdout
1043 test_done "$testroot" "$ret"
1044 return 1
1047 echo "delta" > $testroot/content.expected
1048 cat $testroot/wt/gamma/delta > $testroot/content
1049 cmp -s $testroot/content.expected $testroot/content
1050 ret=$?
1051 if [ $ret -ne 0 ]; then
1052 diff -u $testroot/content.expected $testroot/content
1053 test_done "$testroot" "$ret"
1054 return 1
1057 echo "modified alpha on master" > $testroot/content.expected
1058 cat $testroot/wt/alpha > $testroot/content
1059 cmp -s $testroot/content.expected $testroot/content
1060 ret=$?
1061 if [ $ret -ne 0 ]; then
1062 diff -u $testroot/content.expected $testroot/content
1063 test_done "$testroot" "$ret"
1064 return 1
1067 echo "beta" > $testroot/content.expected
1068 cat $testroot/wt/beta > $testroot/content
1069 cmp -s $testroot/content.expected $testroot/content
1070 ret=$?
1071 if [ $ret -ne 0 ]; then
1072 diff -u $testroot/content.expected $testroot/content
1073 test_done "$testroot" "$ret"
1074 return 1
1077 if [ -e $testroot/wt/epsilon/new ]; then
1078 echo "reverted file epsilon/new still exists on disk" >&2
1079 test_done "$testroot" "1"
1080 return 1
1083 if [ -e $testroot/wt/symlink ]; then
1084 echo "reverted symlink still exists on disk" >&2
1085 test_done "$testroot" "1"
1086 return 1
1089 (cd $testroot/wt && got status > $testroot/stdout)
1091 echo "? added-file" > $testroot/stdout.expected
1092 echo "? unversioned-file" >> $testroot/stdout.expected
1093 cmp -s $testroot/stdout.expected $testroot/stdout
1094 ret=$?
1095 if [ $ret -ne 0 ]; then
1096 diff -u $testroot/stdout.expected $testroot/stdout
1097 test_done "$testroot" "$ret"
1098 return 1
1101 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1102 echo "commit $master_commit (master)" > $testroot/stdout.expected
1103 echo "commit $commit0" >> $testroot/stdout.expected
1104 cmp -s $testroot/stdout.expected $testroot/stdout
1105 ret=$?
1106 if [ $ret -ne 0 ]; then
1107 diff -u $testroot/stdout.expected $testroot/stdout
1108 test_done "$testroot" "$ret"
1109 return 1
1112 (cd $testroot/wt && got update > $testroot/stdout)
1114 echo 'Already up-to-date' > $testroot/stdout.expected
1115 cmp -s $testroot/stdout.expected $testroot/stdout
1116 ret=$?
1117 if [ $ret -ne 0 ]; then
1118 diff -u $testroot/stdout.expected $testroot/stdout
1120 test_done "$testroot" "$ret"
1123 test_merge_in_progress() {
1124 local testroot=`test_init merge_in_progress`
1125 local commit0=`git_show_head $testroot/repo`
1126 local commit0_author_time=`git_show_author_time $testroot/repo`
1128 (cd $testroot/repo && git checkout -q -b newbranch)
1129 echo "modified alpha on branch" > $testroot/repo/alpha
1130 git_commit $testroot/repo -m "committing to alpha on newbranch"
1131 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1133 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1134 ret=$?
1135 if [ $ret -ne 0 ]; then
1136 echo "got checkout failed unexpectedly" >&2
1137 test_done "$testroot" "$ret"
1138 return 1
1141 # create a conflicting commit
1142 (cd $testroot/repo && git checkout -q master)
1143 echo "modified alpha on master" > $testroot/repo/alpha
1144 git_commit $testroot/repo -m "committing to alpha on master"
1145 local master_commit=`git_show_head $testroot/repo`
1147 # need an up-to-date work tree for 'got merge'
1148 (cd $testroot/wt && got update > /dev/null)
1149 ret=$?
1150 if [ $ret -ne 0 ]; then
1151 echo "got update failed unexpectedly" >&2
1152 test_done "$testroot" "$ret"
1153 return 1
1156 (cd $testroot/wt && got merge newbranch \
1157 > $testroot/stdout 2> $testroot/stderr)
1158 ret=$?
1159 if [ $ret -eq 0 ]; then
1160 echo "got merge succeeded unexpectedly" >&2
1161 test_done "$testroot" "1"
1162 return 1
1165 echo "C alpha" >> $testroot/stdout.expected
1166 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1167 cmp -s $testroot/stdout.expected $testroot/stdout
1168 ret=$?
1169 if [ $ret -ne 0 ]; then
1170 diff -u $testroot/stdout.expected $testroot/stdout
1171 test_done "$testroot" "$ret"
1172 return 1
1175 echo "got: conflicts must be resolved before merging can continue" \
1176 > $testroot/stderr.expected
1177 cmp -s $testroot/stderr.expected $testroot/stderr
1178 ret=$?
1179 if [ $ret -ne 0 ]; then
1180 diff -u $testroot/stderr.expected $testroot/stderr
1181 test_done "$testroot" "$ret"
1182 return 1
1185 (cd $testroot/wt && got status > $testroot/stdout)
1187 echo "C alpha" > $testroot/stdout.expected
1188 cmp -s $testroot/stdout.expected $testroot/stdout
1189 ret=$?
1190 if [ $ret -ne 0 ]; then
1191 diff -u $testroot/stdout.expected $testroot/stdout
1192 test_done "$testroot" "$ret"
1193 return 1
1196 for cmd in update commit histedit "rebase newbranch" \
1197 "integrate newbranch" "merge newbranch" "stage alpha"; do
1198 (cd $testroot/wt && got $cmd > $testroot/stdout \
1199 2> $testroot/stderr)
1200 ret=$?
1201 if [ $ret -eq 0 ]; then
1202 echo "got $cmd succeeded unexpectedly" >&2
1203 test_done "$testroot" "1"
1204 return 1
1207 echo -n > $testroot/stdout.expected
1208 cmp -s $testroot/stdout.expected $testroot/stdout
1209 ret=$?
1210 if [ $ret -ne 0 ]; then
1211 diff -u $testroot/stdout.expected $testroot/stdout
1212 test_done "$testroot" "$ret"
1213 return 1
1216 echo -n "got: a merge operation is in progress in this " \
1217 > $testroot/stderr.expected
1218 echo "work tree and must be continued or aborted first" \
1219 >> $testroot/stderr.expected
1220 cmp -s $testroot/stderr.expected $testroot/stderr
1221 ret=$?
1222 if [ $ret -ne 0 ]; then
1223 diff -u $testroot/stderr.expected $testroot/stderr
1224 test_done "$testroot" "$ret"
1225 return 1
1227 done
1229 test_done "$testroot" "$ret"
1232 test_merge_path_prefix() {
1233 local testroot=`test_init merge_path_prefix`
1234 local commit0=`git_show_head $testroot/repo`
1235 local commit0_author_time=`git_show_author_time $testroot/repo`
1237 (cd $testroot/repo && git checkout -q -b newbranch)
1238 echo "modified alpha on branch" > $testroot/repo/alpha
1239 git_commit $testroot/repo -m "committing to alpha on newbranch"
1240 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1242 got checkout -p epsilon -b master $testroot/repo $testroot/wt \
1243 > /dev/null
1244 ret=$?
1245 if [ $ret -ne 0 ]; then
1246 echo "got checkout failed unexpectedly" >&2
1247 test_done "$testroot" "$ret"
1248 return 1
1251 # create a conflicting commit
1252 (cd $testroot/repo && git checkout -q master)
1253 echo "modified alpha on master" > $testroot/repo/alpha
1254 git_commit $testroot/repo -m "committing to alpha on master"
1255 local master_commit=`git_show_head $testroot/repo`
1257 # need an up-to-date work tree for 'got merge'
1258 (cd $testroot/wt && got update > /dev/null)
1259 ret=$?
1260 if [ $ret -ne 0 ]; then
1261 echo "got update failed unexpectedly" >&2
1262 test_done "$testroot" "$ret"
1263 return 1
1266 (cd $testroot/wt && got merge newbranch \
1267 > $testroot/stdout 2> $testroot/stderr)
1268 ret=$?
1269 if [ $ret -eq 0 ]; then
1270 echo "got merge succeeded unexpectedly" >&2
1271 test_done "$testroot" "1"
1272 return 1
1275 echo -n "got: cannot merge branch which contains changes outside " \
1276 > $testroot/stderr.expected
1277 echo "of this work tree's path prefix" >> $testroot/stderr.expected
1278 cmp -s $testroot/stderr.expected $testroot/stderr
1279 ret=$?
1280 if [ $ret -ne 0 ]; then
1281 diff -u $testroot/stderr.expected $testroot/stderr
1283 test_done "$testroot" "$ret"
1286 test_merge_missing_file() {
1287 local testroot=`test_init merge_missing_file`
1288 local commit0=`git_show_head $testroot/repo`
1289 local commit0_author_time=`git_show_author_time $testroot/repo`
1291 (cd $testroot/repo && git checkout -q -b newbranch)
1292 echo "modified alpha on branch" > $testroot/repo/alpha
1293 echo "modified delta on branch" > $testroot/repo/gamma/delta
1294 git_commit $testroot/repo -m "committing to alpha and delta"
1295 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1297 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1298 ret=$?
1299 if [ $ret -ne 0 ]; then
1300 echo "got checkout failed unexpectedly" >&2
1301 test_done "$testroot" "$ret"
1302 return 1
1305 # create a conflicting commit which renames alpha
1306 (cd $testroot/repo && git checkout -q master)
1307 (cd $testroot/repo && git mv alpha epsilon/alpha-moved)
1308 git_commit $testroot/repo -m "moving alpha on master"
1309 local master_commit=`git_show_head $testroot/repo`
1311 # need an up-to-date work tree for 'got merge'
1312 (cd $testroot/wt && got update > /dev/null)
1313 ret=$?
1314 if [ $ret -ne 0 ]; then
1315 echo "got update failed unexpectedly" >&2
1316 test_done "$testroot" "$ret"
1317 return 1
1320 (cd $testroot/wt && got merge newbranch \
1321 > $testroot/stdout 2> $testroot/stderr)
1322 ret=$?
1323 if [ $ret -eq 0 ]; then
1324 echo "got merge succeeded unexpectedly" >&2
1325 test_done "$testroot" "1"
1326 return 1
1329 echo "! alpha" > $testroot/stdout.expected
1330 echo "G gamma/delta" >> $testroot/stdout.expected
1331 echo -n "Files which had incoming changes but could not be found " \
1332 >> $testroot/stdout.expected
1333 echo "in the work tree: 1" >> $testroot/stdout.expected
1334 cmp -s $testroot/stdout.expected $testroot/stdout
1335 ret=$?
1336 if [ $ret -ne 0 ]; then
1337 diff -u $testroot/stdout.expected $testroot/stdout
1338 test_done "$testroot" "$ret"
1339 return 1
1342 echo -n "got: changes destined for some files " \
1343 > $testroot/stderr.expected
1344 echo -n "were not yet merged and should be merged manually if " \
1345 >> $testroot/stderr.expected
1346 echo "required before the merge operation is continued" \
1347 >> $testroot/stderr.expected
1348 cmp -s $testroot/stderr.expected $testroot/stderr
1349 ret=$?
1350 if [ $ret -ne 0 ]; then
1351 diff -u $testroot/stderr.expected $testroot/stderr
1352 test_done "$testroot" "$ret"
1353 return 1
1356 (cd $testroot/wt && got status > $testroot/stdout)
1358 echo "M gamma/delta" > $testroot/stdout.expected
1359 cmp -s $testroot/stdout.expected $testroot/stdout
1360 ret=$?
1361 if [ $ret -ne 0 ]; then
1362 diff -u $testroot/stdout.expected $testroot/stdout
1363 test_done "$testroot" "$ret"
1364 return 1
1367 test_done "$testroot" "$ret"
1370 test_merge_no_op() {
1371 local testroot=`test_init merge_no_op`
1372 local commit0=`git_show_head $testroot/repo`
1373 local commit0_author_time=`git_show_author_time $testroot/repo`
1375 (cd $testroot/repo && git checkout -q -b newbranch)
1376 echo "modified alpha on branch" > $testroot/repo/alpha
1377 git_commit $testroot/repo -m "committing to alpha on newbranch"
1378 local branch_commit=`git_show_branch_head $testroot/repo newbranch`
1380 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1381 ret=$?
1382 if [ $ret -ne 0 ]; then
1383 echo "got checkout failed unexpectedly" >&2
1384 test_done "$testroot" "$ret"
1385 return 1
1388 # create a conflicting commit
1389 (cd $testroot/repo && git checkout -q master)
1390 echo "modified alpha on master" > $testroot/repo/alpha
1391 git_commit $testroot/repo -m "committing to alpha on master"
1392 local master_commit=`git_show_head $testroot/repo`
1394 # need an up-to-date work tree for 'got merge'
1395 (cd $testroot/wt && got update > /dev/null)
1396 ret=$?
1397 if [ $ret -ne 0 ]; then
1398 echo "got update failed unexpectedly" >&2
1399 test_done "$testroot" "$ret"
1400 return 1
1403 (cd $testroot/wt && got merge newbranch \
1404 > $testroot/stdout 2> $testroot/stderr)
1405 ret=$?
1406 if [ $ret -eq 0 ]; then
1407 echo "got merge succeeded unexpectedly" >&2
1408 test_done "$testroot" "1"
1409 return 1
1412 echo "C alpha" >> $testroot/stdout.expected
1413 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1414 cmp -s $testroot/stdout.expected $testroot/stdout
1415 ret=$?
1416 if [ $ret -ne 0 ]; then
1417 diff -u $testroot/stdout.expected $testroot/stdout
1418 test_done "$testroot" "$ret"
1419 return 1
1422 echo "got: conflicts must be resolved before merging can continue" \
1423 > $testroot/stderr.expected
1424 cmp -s $testroot/stderr.expected $testroot/stderr
1425 ret=$?
1426 if [ $ret -ne 0 ]; then
1427 diff -u $testroot/stderr.expected $testroot/stderr
1428 test_done "$testroot" "$ret"
1429 return 1
1432 (cd $testroot/wt && got status > $testroot/stdout)
1434 echo "C alpha" > $testroot/stdout.expected
1435 cmp -s $testroot/stdout.expected $testroot/stdout
1436 ret=$?
1437 if [ $ret -ne 0 ]; then
1438 diff -u $testroot/stdout.expected $testroot/stdout
1439 test_done "$testroot" "$ret"
1440 return 1
1443 # resolve the conflict by reverting all changes; now it is no-op merge
1444 (cd $testroot/wt && got revert alpha > /dev/null)
1445 ret=$?
1446 if [ $ret -ne 0 ]; then
1447 echo "got revert failed unexpectedly" >&2
1448 test_done "$testroot" "$ret"
1449 return 1
1452 (cd $testroot/wt && got merge -c > $testroot/stdout \
1453 2> $testroot/stderr)
1454 ret=$?
1455 if [ $ret -ne 0 ]; then
1456 echo "got merge failed unexpectedly" >&2
1457 test_done "$testroot" "$ret"
1458 return 1
1461 echo -n '' > $testroot/stderr.expected
1462 cmp -s $testroot/stderr.expected $testroot/stderr
1463 ret=$?
1464 if [ $ret -ne 0 ]; then
1465 diff -u $testroot/stderr.expected $testroot/stderr
1466 test_done "$testroot" "$ret"
1467 return 1
1470 local merge_commit=`git_show_head $testroot/repo`
1471 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1472 > $testroot/stdout.expected
1473 echo $merge_commit >> $testroot/stdout.expected
1475 cmp -s $testroot/stdout.expected $testroot/stdout
1476 ret=$?
1477 if [ $ret -ne 0 ]; then
1478 diff -u $testroot/stdout.expected $testroot/stdout
1479 test_done "$testroot" "$ret"
1480 return 1
1483 (cd $testroot/wt && got status > $testroot/stdout)
1485 echo -n "" > $testroot/stdout.expected
1486 cmp -s $testroot/stdout.expected $testroot/stdout
1487 ret=$?
1488 if [ $ret -ne 0 ]; then
1489 diff -u $testroot/stdout.expected $testroot/stdout
1490 test_done "$testroot" "$ret"
1491 return 1
1494 # We should have created a merge commit with two parents.
1495 got log -r $testroot/repo -l1 -c $merge_commit | grep ^parent \
1496 > $testroot/stdout
1497 echo "parent 1: $master_commit" > $testroot/stdout.expected
1498 echo "parent 2: $branch_commit" >> $testroot/stdout.expected
1499 cmp -s $testroot/stdout.expected $testroot/stdout
1500 ret=$?
1501 if [ $ret -ne 0 ]; then
1502 diff -u $testroot/stdout.expected $testroot/stdout
1504 test_done "$testroot" "$ret"
1507 test_merge_imported_branch() {
1508 local testroot=`test_init merge_import`
1509 local commit0=`git_show_head $testroot/repo`
1510 local commit0_author_time=`git_show_author_time $testroot/repo`
1512 # import a new sub-tree to the 'files' branch such that
1513 # none of the files added here collide with existing ones
1514 mkdir -p $testroot/tree/there
1515 mkdir -p $testroot/tree/be/lots
1516 mkdir -p $testroot/tree/files
1517 echo "there should" > $testroot/tree/there/should
1518 echo "be lots of" > $testroot/tree/be/lots/of
1519 echo "files here" > $testroot/tree/files/here
1520 got import -r $testroot/repo -b files -m 'import files' \
1521 $testroot/tree > /dev/null
1523 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1524 ret=$?
1525 if [ $ret -ne 0 ]; then
1526 echo "got checkout failed unexpectedly" >&2
1527 test_done "$testroot" "$ret"
1528 return 1
1531 (cd $testroot/wt && got merge files > $testroot/stdout)
1532 ret=$?
1533 if [ $ret -ne 0 ]; then
1534 echo "got merge failed unexpectedly" >&2
1535 test_done "$testroot" "$ret"
1536 return 1
1539 local merge_commit0=`git_show_head $testroot/repo`
1540 cat > $testroot/stdout.expected <<EOF
1541 A be/lots/of
1542 A files/here
1543 A there/should
1544 Merged refs/heads/files into refs/heads/master: $merge_commit0
1545 EOF
1546 cmp -s $testroot/stdout.expected $testroot/stdout
1547 ret=$?
1548 if [ $ret -ne 0 ]; then
1549 diff -u $testroot/stdout.expected $testroot/stdout
1550 test_done "$testroot" "$ret"
1551 return 1
1554 # try to merge again while no new changes are available
1555 (cd $testroot/wt && got merge files > $testroot/stdout)
1556 ret=$?
1557 if [ $ret -ne 0 ]; then
1558 echo "got merge failed unexpectedly" >&2
1559 test_done "$testroot" "$ret"
1560 return 1
1562 echo "Already up-to-date" > $testroot/stdout.expected
1563 cmp -s $testroot/stdout.expected $testroot/stdout
1564 ret=$?
1565 if [ $ret -ne 0 ]; then
1566 diff -u $testroot/stdout.expected $testroot/stdout
1567 test_done "$testroot" "$ret"
1568 return 1
1571 # update the 'files' branch
1572 (cd $testroot/repo && git reset -q --hard master)
1573 (cd $testroot/repo && git checkout -q files)
1574 echo "indeed" > $testroot/repo/indeed
1575 (cd $testroot/repo && git add indeed)
1576 git_commit $testroot/repo -m "adding another file indeed"
1577 echo "be lots and lots of" > $testroot/repo/be/lots/of
1578 git_commit $testroot/repo -m "lots of changes"
1580 (cd $testroot/wt && got update > /dev/null)
1581 ret=$?
1582 if [ $ret -ne 0 ]; then
1583 echo "got update failed unexpectedly" >&2
1584 test_done "$testroot" "$ret"
1585 return 1
1588 # we should now be able to merge more changes from files branch
1589 (cd $testroot/wt && got merge files > $testroot/stdout)
1590 ret=$?
1591 if [ $ret -ne 0 ]; then
1592 echo "got merge failed unexpectedly" >&2
1593 test_done "$testroot" "$ret"
1594 return 1
1597 local merge_commit1=`git_show_branch_head $testroot/repo master`
1598 cat > $testroot/stdout.expected <<EOF
1599 G be/lots/of
1600 A indeed
1601 Merged refs/heads/files into refs/heads/master: $merge_commit1
1602 EOF
1604 cmp -s $testroot/stdout.expected $testroot/stdout
1605 ret=$?
1606 if [ $ret -ne 0 ]; then
1607 diff -u $testroot/stdout.expected $testroot/stdout
1609 test_done "$testroot" "$ret"
1612 test_merge_interrupt() {
1613 local testroot=`test_init merge_interrupt`
1614 local commit0=`git_show_head $testroot/repo`
1615 local commit0_author_time=`git_show_author_time $testroot/repo`
1617 (cd $testroot/repo && git checkout -q -b newbranch)
1618 echo "modified alpha on branch" > $testroot/repo/alpha
1619 git_commit $testroot/repo -m "committing to alpha on newbranch"
1620 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1622 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1623 ret=$?
1624 if [ $ret -ne 0 ]; then
1625 echo "got checkout failed unexpectedly" >&2
1626 test_done "$testroot" "$ret"
1627 return 1
1630 # create a non-conflicting commit
1631 (cd $testroot/repo && git checkout -q master)
1632 echo "modified beta on master" > $testroot/repo/beta
1633 git_commit $testroot/repo -m "committing to beta on master"
1634 local master_commit=`git_show_head $testroot/repo`
1636 # need an up-to-date work tree for 'got merge'
1637 (cd $testroot/wt && got update > /dev/null)
1638 ret=$?
1639 if [ $ret -ne 0 ]; then
1640 echo "got update failed unexpectedly" >&2
1641 test_done "$testroot" "$ret"
1642 return 1
1645 (cd $testroot/wt && got merge -n newbranch \
1646 > $testroot/stdout 2> $testroot/stderr)
1647 ret=$?
1648 if [ $ret -ne 0 ]; then
1649 echo "got merge failed unexpectedly" >&2
1650 test_done "$testroot" "1"
1651 return 1
1654 echo "G alpha" > $testroot/stdout.expected
1655 echo "Merge of refs/heads/newbranch interrupted on request" \
1656 >> $testroot/stdout.expected
1657 cmp -s $testroot/stdout.expected $testroot/stdout
1658 ret=$?
1659 if [ $ret -ne 0 ]; then
1660 diff -u $testroot/stdout.expected $testroot/stdout
1661 test_done "$testroot" "$ret"
1662 return 1
1665 (cd $testroot/wt && got status > $testroot/stdout)
1667 echo "M alpha" > $testroot/stdout.expected
1668 cmp -s $testroot/stdout.expected $testroot/stdout
1669 ret=$?
1670 if [ $ret -ne 0 ]; then
1671 diff -u $testroot/stdout.expected $testroot/stdout
1672 test_done "$testroot" "$ret"
1673 return 1
1676 echo "modified alpha on branch" > $testroot/content.expected
1677 cat $testroot/wt/alpha > $testroot/content
1678 cmp -s $testroot/content.expected $testroot/content
1679 ret=$?
1680 if [ $ret -ne 0 ]; then
1681 diff -u $testroot/content.expected $testroot/content
1682 test_done "$testroot" "$ret"
1683 return 1
1686 # adjust merge result
1687 echo "adjusted merge result" > $testroot/wt/alpha
1689 # continue the merge
1690 (cd $testroot/wt && got merge -c > $testroot/stdout)
1691 ret=$?
1692 if [ $ret -ne 0 ]; then
1693 echo "got merge failed unexpectedly" >&2
1694 test_done "$testroot" "$ret"
1695 return 1
1698 local merge_commit=`git_show_head $testroot/repo`
1700 echo "M alpha" > $testroot/stdout.expected
1701 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1702 >> $testroot/stdout.expected
1703 echo $merge_commit >> $testroot/stdout.expected
1705 cmp -s $testroot/stdout.expected $testroot/stdout
1706 ret=$?
1707 if [ $ret -ne 0 ]; then
1708 diff -u $testroot/stdout.expected $testroot/stdout
1709 test_done "$testroot" "$ret"
1710 return 1
1713 (cd $testroot/wt && got status > $testroot/stdout)
1715 echo -n > $testroot/stdout.expected
1716 cmp -s $testroot/stdout.expected $testroot/stdout
1717 ret=$?
1718 if [ $ret -ne 0 ]; then
1719 diff -u $testroot/stdout.expected $testroot/stdout
1720 test_done "$testroot" "$ret"
1721 return 1
1724 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1725 echo "commit $merge_commit (master)" > $testroot/stdout.expected
1726 echo "commit $master_commit" >> $testroot/stdout.expected
1727 echo "commit $commit0" >> $testroot/stdout.expected
1728 cmp -s $testroot/stdout.expected $testroot/stdout
1729 ret=$?
1730 if [ $ret -ne 0 ]; then
1731 diff -u $testroot/stdout.expected $testroot/stdout
1732 test_done "$testroot" "$ret"
1733 return 1
1736 (cd $testroot/wt && got update > $testroot/stdout)
1738 echo 'Already up-to-date' > $testroot/stdout.expected
1739 cmp -s $testroot/stdout.expected $testroot/stdout
1740 ret=$?
1741 if [ $ret -ne 0 ]; then
1742 diff -u $testroot/stdout.expected $testroot/stdout
1743 test_done "$testroot" "$ret"
1744 return 1
1747 # We should have created a merge commit with two parents.
1748 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
1749 echo "parent 1: $master_commit" > $testroot/stdout.expected
1750 echo "parent 2: $branch_commit0" >> $testroot/stdout.expected
1751 cmp -s $testroot/stdout.expected $testroot/stdout
1752 ret=$?
1753 if [ $ret -ne 0 ]; then
1754 diff -u $testroot/stdout.expected $testroot/stdout
1756 test_done "$testroot" "$ret"
1759 test_merge_umask() {
1760 local testroot=`test_init merge_umask`
1762 (cd $testroot/repo && git checkout -q -b newbranch)
1763 echo "modified alpha on branch" >$testroot/repo/alpha
1764 git_commit "$testroot/repo" -m "committing alpha on newbranch"
1765 echo "modified delta on branch" >$testroot/repo/gamma/delta
1766 git_commit "$testroot/repo" -m "committing delta on newbranch"
1768 # diverge from newbranch
1769 (cd "$testroot/repo" && git checkout -q master)
1770 echo "modified beta on master" >$testroot/repo/beta
1771 git_commit "$testroot/repo" -m "committing zeto no master"
1773 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1775 # using a subshell to avoid clobbering global umask
1776 (umask 077 && cd "$testroot/wt" && got merge newbranch) >/dev/null
1778 for f in alpha gamma/delta; do
1779 ls -l "$testroot/wt/$f" | grep -q ^-rw-------
1780 if [ $? -ne 0 ]; then
1781 echo "$f is not 0600 after merge" >&2
1782 ls -l "$testroot/wt/$f" >&2
1783 test_done "$testroot" 1
1785 done
1787 test_done "$testroot" 0
1790 test_merge_gitconfig_author() {
1791 local testroot=`test_init merge_gitconfig_author`
1793 (cd $testroot/repo && git config user.name 'Flan Luck')
1794 (cd $testroot/repo && git config user.email 'flan_luck@openbsd.org')
1796 (cd $testroot/repo && git checkout -q -b newbranch)
1797 echo "modified alpha on branch" >$testroot/repo/alpha
1798 git_commit "$testroot/repo" -m "committing alpha on newbranch"
1799 echo "modified delta on branch" >$testroot/repo/gamma/delta
1800 git_commit "$testroot/repo" -m "committing delta on newbranch"
1802 # diverge from newbranch
1803 (cd "$testroot/repo" && git checkout -q master)
1804 echo "modified beta on master" >$testroot/repo/beta
1805 git_commit "$testroot/repo" -m "committing zeto no master"
1807 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1809 # unset in a subshell to avoid affecting our environment
1810 (unset GOT_IGNORE_GITCONFIG && cd $testroot/wt && \
1811 got merge newbranch > /dev/null)
1813 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
1814 ret=$?
1815 if [ $ret -ne 0 ]; then
1816 test_done "$testroot" "$ret"
1817 return 1
1820 echo "from: Flan Luck <flan_luck@openbsd.org>" \
1821 > $testroot/stdout.expected
1822 cmp -s $testroot/stdout.expected $testroot/stdout
1823 ret=$?
1824 if [ $ret -ne 0 ]; then
1825 diff -u $testroot/stdout.expected $testroot/stdout
1827 test_done "$testroot" "$ret"
1830 test_merge_fetched_branch() {
1831 local testroot=`test_init merge_fetched_branch`
1832 local testurl=ssh://127.0.0.1/$testroot
1833 local commit_id=`git_show_head $testroot/repo`
1835 got clone -q $testurl/repo $testroot/repo-clone
1836 ret=$?
1837 if [ $ret -ne 0 ]; then
1838 echo "got clone command failed unexpectedly" >&2
1839 test_done "$testroot" "$ret"
1840 return 1
1843 echo "modified alpha" > $testroot/repo/alpha
1844 git_commit $testroot/repo -m "modified alpha"
1845 local commit_id2=`git_show_head $testroot/repo`
1847 got fetch -q -r $testroot/repo-clone > $testroot/stdout
1848 ret=$?
1849 if [ $ret -ne 0 ]; then
1850 echo "got fetch command failed unexpectedly" >&2
1851 test_done "$testroot" "$ret"
1852 return 1
1855 echo -n > $testroot/stdout.expected
1857 cmp -s $testroot/stdout $testroot/stdout.expected
1858 ret=$?
1859 if [ $ret -ne 0 ]; then
1860 diff -u $testroot/stdout.expected $testroot/stdout
1861 test_done "$testroot" "$ret"
1862 return 1
1865 got ref -l -r $testroot/repo-clone > $testroot/stdout
1867 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1868 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1869 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1870 >> $testroot/stdout.expected
1871 echo "refs/remotes/origin/master: $commit_id2" \
1872 >> $testroot/stdout.expected
1874 cmp -s $testroot/stdout $testroot/stdout.expected
1875 ret=$?
1876 if [ $ret -ne 0 ]; then
1877 diff -u $testroot/stdout.expected $testroot/stdout
1878 test_done "$testroot" "$ret"
1879 return 1
1882 got checkout $testroot/repo-clone $testroot/wt > /dev/null
1884 echo "modified beta" > $testroot/wt/beta
1885 (cd $testroot/wt && got commit -m "modified beta" > /dev/null)
1886 local commit_id3=`git_show_head $testroot/repo-clone`
1888 (cd $testroot/wt && got update > /dev/null)
1889 (cd $testroot/wt && got merge origin/master > $testroot/stdout)
1890 local merge_commit_id=`git_show_head $testroot/repo-clone`
1892 cat > $testroot/stdout.expected <<EOF
1893 G alpha
1894 Merged refs/remotes/origin/master into refs/heads/master: $merge_commit_id
1895 EOF
1897 cmp -s $testroot/stdout $testroot/stdout.expected
1898 ret=$?
1899 if [ $ret -ne 0 ]; then
1900 diff -u $testroot/stdout.expected $testroot/stdout
1902 test_done "$testroot" "$ret"
1905 test_merge_fetched_branch_remote() {
1906 local testroot=`test_init merge_fetched_branch_remote`
1907 local testurl=ssh://127.0.0.1/$testroot
1908 local commit_id=`git_show_head $testroot/repo`
1910 got clone -q $testurl/repo $testroot/repo-clone
1911 ret=$?
1912 if [ $ret -ne 0 ]; then
1913 echo "got clone command failed unexpectedly" >&2
1914 test_done "$testroot" "$ret"
1915 return 1
1918 echo "modified alpha" > $testroot/repo/alpha
1919 git_commit $testroot/repo -m "modified alpha"
1920 local commit_id2=`git_show_head $testroot/repo`
1922 got fetch -q -r $testroot/repo-clone > $testroot/stdout
1923 ret=$?
1924 if [ $ret -ne 0 ]; then
1925 echo "got fetch command failed unexpectedly" >&2
1926 test_done "$testroot" "$ret"
1927 return 1
1930 echo -n > $testroot/stdout.expected
1932 cmp -s $testroot/stdout $testroot/stdout.expected
1933 ret=$?
1934 if [ $ret -ne 0 ]; then
1935 diff -u $testroot/stdout.expected $testroot/stdout
1936 test_done "$testroot" "$ret"
1937 return 1
1940 got ref -l -r $testroot/repo-clone > $testroot/stdout
1942 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1943 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1944 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1945 >> $testroot/stdout.expected
1946 echo "refs/remotes/origin/master: $commit_id2" \
1947 >> $testroot/stdout.expected
1949 cmp -s $testroot/stdout $testroot/stdout.expected
1950 ret=$?
1951 if [ $ret -ne 0 ]; then
1952 diff -u $testroot/stdout.expected $testroot/stdout
1953 test_done "$testroot" "$ret"
1954 return 1
1957 got checkout $testroot/repo-clone $testroot/wt > /dev/null
1959 echo "modified beta" > $testroot/wt/beta
1960 (cd $testroot/wt && got commit -m "modified beta" > /dev/null)
1961 local commit_id3=`git_show_head $testroot/repo-clone`
1963 (cd $testroot/wt && got update -b origin/master > /dev/null)
1964 (cd $testroot/wt && got merge master > \
1965 $testroot/stdout 2> $testroot/stderr)
1966 local merge_commit_id=`git_show_head $testroot/repo-clone`
1968 echo -n > $testroot/stdout.expected
1970 cmp -s $testroot/stdout $testroot/stdout.expected
1971 ret=$?
1972 if [ $ret -ne 0 ]; then
1973 diff -u $testroot/stdout.expected $testroot/stdout
1974 test_done "$testroot" "$ret"
1975 return 1
1978 echo -n "got: work tree's current branch refs/remotes/origin/master " \
1979 > $testroot/stderr.expected
1980 echo -n 'is outside the "refs/heads/" reference namespace; ' \
1981 >> $testroot/stderr.expected
1982 echo -n "update -b required: will not commit to a branch " \
1983 >> $testroot/stderr.expected
1984 echo 'outside the "refs/heads/" reference namespace' \
1985 >> $testroot/stderr.expected
1987 cmp -s $testroot/stderr $testroot/stderr.expected
1988 ret=$?
1989 if [ $ret -ne 0 ]; then
1990 diff -u $testroot/stderr.expected $testroot/stderr
1992 test_done "$testroot" "$ret"
1995 test_parseargs "$@"
1996 run_test test_merge_basic
1997 run_test test_merge_forward
1998 run_test test_merge_forward_commit
1999 run_test test_merge_forward_interrupt
2000 run_test test_merge_backward
2001 run_test test_merge_continue
2002 run_test test_merge_continue_new_commit
2003 run_test test_merge_abort
2004 run_test test_merge_in_progress
2005 run_test test_merge_path_prefix
2006 run_test test_merge_missing_file
2007 run_test test_merge_no_op
2008 run_test test_merge_imported_branch
2009 run_test test_merge_interrupt
2010 run_test test_merge_umask
2011 run_test test_merge_gitconfig_author
2012 run_test test_merge_fetched_branch
2013 run_test test_merge_fetched_branch_remote