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_backward() {
474 local testroot=`test_init merge_backward`
475 local commit0=`git_show_head $testroot/repo`
477 (cd $testroot/repo && git checkout -q -b newbranch)
478 (cd $testroot/repo && git checkout -q master)
479 echo "modified alpha on master" > $testroot/repo/alpha
480 git_commit $testroot/repo -m "committing to alpha on master"
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 newbranch \
491 > $testroot/stdout 2> $testroot/stderr)
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
498 echo "Already up-to-date" > $testroot/stdout.expected
499 cmp -s $testroot/stdout.expected $testroot/stdout
500 ret=$?
501 if [ $ret -ne 0 ]; then
502 diff -u $testroot/stdout.expected $testroot/stdout
503 test_done "$testroot" "$ret"
504 return 1
505 fi
506 test_done "$testroot" "$ret"
509 test_merge_continue() {
510 local testroot=`test_init merge_continue`
511 local commit0=`git_show_head $testroot/repo`
512 local commit0_author_time=`git_show_author_time $testroot/repo`
514 (cd $testroot/repo && git checkout -q -b newbranch)
515 echo "modified delta on branch" > $testroot/repo/gamma/delta
516 git_commit $testroot/repo -m "committing to delta on newbranch"
517 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
519 echo "modified alpha on branch" > $testroot/repo/alpha
520 git_commit $testroot/repo -m "committing to alpha on newbranch"
521 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
522 (cd $testroot/repo && git rm -q beta)
523 git_commit $testroot/repo -m "removing beta on newbranch"
524 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
525 echo "new file on branch" > $testroot/repo/epsilon/new
526 (cd $testroot/repo && git add epsilon/new)
527 git_commit $testroot/repo -m "adding new file on newbranch"
528 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
530 got checkout -b master $testroot/repo $testroot/wt > /dev/null
531 ret=$?
532 if [ $ret -ne 0 ]; then
533 echo "got checkout failed unexpectedly" >&2
534 test_done "$testroot" "$ret"
535 return 1
536 fi
538 # create a conflicting commit
539 (cd $testroot/repo && git checkout -q master)
540 echo "modified alpha on master" > $testroot/repo/alpha
541 git_commit $testroot/repo -m "committing to alpha on master"
542 local master_commit=`git_show_head $testroot/repo`
544 # need an up-to-date work tree for 'got merge'
545 (cd $testroot/wt && got update > /dev/null)
546 ret=$?
547 if [ $ret -ne 0 ]; then
548 echo "got update failed unexpectedly" >&2
549 test_done "$testroot" "$ret"
550 return 1
551 fi
553 (cd $testroot/wt && got merge newbranch \
554 > $testroot/stdout 2> $testroot/stderr)
555 ret=$?
556 if [ $ret -eq 0 ]; then
557 echo "got merge succeeded unexpectedly" >&2
558 test_done "$testroot" "1"
559 return 1
560 fi
562 echo "C alpha" >> $testroot/stdout.expected
563 echo "D beta" >> $testroot/stdout.expected
564 echo "A epsilon/new" >> $testroot/stdout.expected
565 echo "G gamma/delta" >> $testroot/stdout.expected
566 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
567 cmp -s $testroot/stdout.expected $testroot/stdout
568 ret=$?
569 if [ $ret -ne 0 ]; then
570 diff -u $testroot/stdout.expected $testroot/stdout
571 test_done "$testroot" "$ret"
572 return 1
573 fi
575 echo "got: conflicts must be resolved before merging can continue" \
576 > $testroot/stderr.expected
577 cmp -s $testroot/stderr.expected $testroot/stderr
578 ret=$?
579 if [ $ret -ne 0 ]; then
580 diff -u $testroot/stderr.expected $testroot/stderr
581 test_done "$testroot" "$ret"
582 return 1
583 fi
585 (cd $testroot/wt && got status > $testroot/stdout)
587 echo "C alpha" > $testroot/stdout.expected
588 echo "D beta" >> $testroot/stdout.expected
589 echo "A epsilon/new" >> $testroot/stdout.expected
590 echo "M gamma/delta" >> $testroot/stdout.expected
591 cmp -s $testroot/stdout.expected $testroot/stdout
592 ret=$?
593 if [ $ret -ne 0 ]; then
594 diff -u $testroot/stdout.expected $testroot/stdout
595 test_done "$testroot" "$ret"
596 return 1
597 fi
599 echo '<<<<<<<' > $testroot/content.expected
600 echo "modified alpha on master" >> $testroot/content.expected
601 echo "||||||| 3-way merge base: commit $commit0" \
602 >> $testroot/content.expected
603 echo "alpha" >> $testroot/content.expected
604 echo "=======" >> $testroot/content.expected
605 echo "modified alpha on branch" >> $testroot/content.expected
606 echo ">>>>>>> merged change: commit $branch_commit3" \
607 >> $testroot/content.expected
608 cat $testroot/wt/alpha > $testroot/content
609 cmp -s $testroot/content.expected $testroot/content
610 ret=$?
611 if [ $ret -ne 0 ]; then
612 diff -u $testroot/content.expected $testroot/content
613 test_done "$testroot" "$ret"
614 return 1
615 fi
617 # resolve the conflict
618 echo "modified alpha by both branches" > $testroot/wt/alpha
620 (cd $testroot/wt && got merge -c > $testroot/stdout)
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
628 local merge_commit=`git_show_head $testroot/repo`
630 echo "M alpha" > $testroot/stdout.expected
631 echo "D beta" >> $testroot/stdout.expected
632 echo "A epsilon/new" >> $testroot/stdout.expected
633 echo "M gamma/delta" >> $testroot/stdout.expected
634 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
635 >> $testroot/stdout.expected
636 echo $merge_commit >> $testroot/stdout.expected
638 cmp -s $testroot/stdout.expected $testroot/stdout
639 ret=$?
640 if [ $ret -ne 0 ]; then
641 diff -u $testroot/stdout.expected $testroot/stdout
642 test_done "$testroot" "$ret"
643 return 1
644 fi
646 echo "modified delta on branch" > $testroot/content.expected
647 cat $testroot/wt/gamma/delta > $testroot/content
648 cmp -s $testroot/content.expected $testroot/content
649 ret=$?
650 if [ $ret -ne 0 ]; then
651 diff -u $testroot/content.expected $testroot/content
652 test_done "$testroot" "$ret"
653 return 1
654 fi
656 echo "modified alpha by both branches" > $testroot/content.expected
657 cat $testroot/wt/alpha > $testroot/content
658 cmp -s $testroot/content.expected $testroot/content
659 ret=$?
660 if [ $ret -ne 0 ]; then
661 diff -u $testroot/content.expected $testroot/content
662 test_done "$testroot" "$ret"
663 return 1
664 fi
666 if [ -e $testroot/wt/beta ]; then
667 echo "removed file beta still exists on disk" >&2
668 test_done "$testroot" "1"
669 return 1
670 fi
672 echo "new file on branch" > $testroot/content.expected
673 cat $testroot/wt/epsilon/new > $testroot/content
674 cmp -s $testroot/content.expected $testroot/content
675 ret=$?
676 if [ $ret -ne 0 ]; then
677 diff -u $testroot/content.expected $testroot/content
678 test_done "$testroot" "$ret"
679 return 1
680 fi
682 (cd $testroot/wt && got status > $testroot/stdout)
684 echo -n > $testroot/stdout.expected
685 cmp -s $testroot/stdout.expected $testroot/stdout
686 ret=$?
687 if [ $ret -ne 0 ]; then
688 diff -u $testroot/stdout.expected $testroot/stdout
689 test_done "$testroot" "$ret"
690 return 1
691 fi
693 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
694 echo "commit $merge_commit (master)" > $testroot/stdout.expected
695 echo "commit $master_commit" >> $testroot/stdout.expected
696 echo "commit $commit0" >> $testroot/stdout.expected
697 cmp -s $testroot/stdout.expected $testroot/stdout
698 ret=$?
699 if [ $ret -ne 0 ]; then
700 diff -u $testroot/stdout.expected $testroot/stdout
701 test_done "$testroot" "$ret"
702 return 1
703 fi
705 (cd $testroot/wt && got update > $testroot/stdout)
707 echo 'Already up-to-date' > $testroot/stdout.expected
708 cmp -s $testroot/stdout.expected $testroot/stdout
709 ret=$?
710 if [ $ret -ne 0 ]; then
711 diff -u $testroot/stdout.expected $testroot/stdout
712 test_done "$testroot" "$ret"
713 return 1
714 fi
716 # We should have created a merge commit with two parents.
717 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
718 echo "parent 1: $master_commit" > $testroot/stdout.expected
719 echo "parent 2: $branch_commit3" >> $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 fi
725 test_done "$testroot" "$ret"
728 test_merge_continue_new_commit() {
729 # "got merge -c" should refuse to run if the current branch tip has
730 # changed since the merge was started, to avoid clobbering the changes.
731 local testroot=`test_init merge_continue_new_commit`
733 (cd $testroot/repo && git checkout -q -b newbranch)
734 echo "modified delta on branch" > $testroot/repo/gamma/delta
735 git_commit $testroot/repo -m "committing to delta on newbranch"
737 (cd $testroot/repo && git checkout -q master)
738 echo "modified alpha on master" > $testroot/repo/alpha
739 git_commit $testroot/repo -m "committing to alpha on master"
741 got checkout -b master $testroot/repo $testroot/wt > /dev/null
742 ret=$?
743 if [ $ret -ne 0 ]; then
744 echo "got checkout failed unexpectedly" >&2
745 test_done "$testroot" "$ret"
746 return 1
747 fi
749 (cd $testroot/wt && got merge -n newbranch >/dev/null)
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 echo "modified alpha again on master" > $testroot/repo/alpha
758 git_commit $testroot/repo -m "committing to alpha on master again"
760 (cd $testroot/wt && got merge -c > $testroot/stdout 2> $testroot/stderr)
761 ret=$?
762 if [ $ret -eq 0 ]; then
763 echo "got merge succeeded unexpectedly" >&2
764 test_done "$testroot" "1"
765 return 1
766 fi
768 echo -n > $testroot/stdout.expected
769 cmp -s $testroot/stdout.expected $testroot/stdout
770 ret=$?
771 if [ $ret -ne 0 ]; then
772 diff -u $testroot/stdout.expected $testroot/stdout
773 test_done "$testroot" "$ret"
774 return 1
775 fi
777 echo -n "got: merging cannot proceed because the work tree is no " \
778 > $testroot/stderr.expected
779 echo "longer up-to-date; merge must be aborted and retried" \
780 >> $testroot/stderr.expected
781 cmp -s $testroot/stderr.expected $testroot/stderr
782 ret=$?
783 if [ $ret -ne 0 ]; then
784 diff -u $testroot/stderr.expected $testroot/stderr
785 fi
786 test_done "$testroot" "$ret"
789 test_merge_abort() {
790 local testroot=`test_init merge_abort`
791 local commit0=`git_show_head $testroot/repo`
792 local commit0_author_time=`git_show_author_time $testroot/repo`
794 (cd $testroot/repo && git checkout -q -b newbranch)
795 echo "modified delta on branch" > $testroot/repo/gamma/delta
796 git_commit $testroot/repo -m "committing to delta on newbranch"
797 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
799 echo "modified alpha on branch" > $testroot/repo/alpha
800 git_commit $testroot/repo -m "committing to alpha on newbranch"
801 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
802 (cd $testroot/repo && git rm -q beta)
803 git_commit $testroot/repo -m "removing beta on newbranch"
804 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
805 echo "new file on branch" > $testroot/repo/epsilon/new
806 (cd $testroot/repo && git add epsilon/new)
807 git_commit $testroot/repo -m "adding new file on newbranch"
808 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
809 (cd $testroot/repo && ln -s alpha symlink && git add symlink)
810 git_commit $testroot/repo -m "adding symlink on newbranch"
811 local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
813 got checkout -b master $testroot/repo $testroot/wt > /dev/null
814 ret=$?
815 if [ $ret -ne 0 ]; then
816 echo "got checkout failed unexpectedly" >&2
817 test_done "$testroot" "$ret"
818 return 1
819 fi
821 # unrelated unversioned file in work tree
822 touch $testroot/wt/unversioned-file
824 # create a conflicting commit
825 (cd $testroot/repo && git checkout -q master)
826 echo "modified alpha on master" > $testroot/repo/alpha
827 git_commit $testroot/repo -m "committing to alpha on master"
828 local master_commit=`git_show_head $testroot/repo`
830 # need an up-to-date work tree for 'got merge'
831 (cd $testroot/wt && got update > /dev/null)
832 ret=$?
833 if [ $ret -ne 0 ]; then
834 echo "got update failed unexpectedly" >&2
835 test_done "$testroot" "$ret"
836 return 1
837 fi
839 (cd $testroot/wt && got merge newbranch \
840 > $testroot/stdout 2> $testroot/stderr)
841 ret=$?
842 if [ $ret -eq 0 ]; then
843 echo "got merge succeeded unexpectedly" >&2
844 test_done "$testroot" "1"
845 return 1
846 fi
848 echo "C alpha" >> $testroot/stdout.expected
849 echo "D beta" >> $testroot/stdout.expected
850 echo "A epsilon/new" >> $testroot/stdout.expected
851 echo "G gamma/delta" >> $testroot/stdout.expected
852 echo "A symlink" >> $testroot/stdout.expected
853 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
854 cmp -s $testroot/stdout.expected $testroot/stdout
855 ret=$?
856 if [ $ret -ne 0 ]; then
857 diff -u $testroot/stdout.expected $testroot/stdout
858 test_done "$testroot" "$ret"
859 return 1
860 fi
862 echo "got: conflicts must be resolved before merging can continue" \
863 > $testroot/stderr.expected
864 cmp -s $testroot/stderr.expected $testroot/stderr
865 ret=$?
866 if [ $ret -ne 0 ]; then
867 diff -u $testroot/stderr.expected $testroot/stderr
868 test_done "$testroot" "$ret"
869 return 1
870 fi
872 # unrelated added file added during conflict resolution
873 touch $testroot/wt/added-file
874 (cd $testroot/wt && got add added-file > /dev/null)
876 (cd $testroot/wt && got status > $testroot/stdout)
878 echo "A added-file" > $testroot/stdout.expected
879 echo "C alpha" >> $testroot/stdout.expected
880 echo "D beta" >> $testroot/stdout.expected
881 echo "A epsilon/new" >> $testroot/stdout.expected
882 echo "M gamma/delta" >> $testroot/stdout.expected
883 echo "A symlink" >> $testroot/stdout.expected
884 echo "? unversioned-file" >> $testroot/stdout.expected
885 cmp -s $testroot/stdout.expected $testroot/stdout
886 ret=$?
887 if [ $ret -ne 0 ]; then
888 diff -u $testroot/stdout.expected $testroot/stdout
889 test_done "$testroot" "$ret"
890 return 1
891 fi
893 (cd $testroot/wt && got merge -a > $testroot/stdout)
894 ret=$?
895 if [ $ret -ne 0 ]; then
896 echo "got merge failed unexpectedly" >&2
897 test_done "$testroot" "$ret"
898 return 1
899 fi
901 echo "R added-file" > $testroot/stdout.expected
902 echo "R alpha" >> $testroot/stdout.expected
903 echo "R beta" >> $testroot/stdout.expected
904 echo "R epsilon/new" >> $testroot/stdout.expected
905 echo "R gamma/delta" >> $testroot/stdout.expected
906 echo "R symlink" >> $testroot/stdout.expected
907 echo "G added-file" >> $testroot/stdout.expected
908 echo "Merge of refs/heads/newbranch aborted" \
909 >> $testroot/stdout.expected
911 cmp -s $testroot/stdout.expected $testroot/stdout
912 ret=$?
913 if [ $ret -ne 0 ]; then
914 diff -u $testroot/stdout.expected $testroot/stdout
915 test_done "$testroot" "$ret"
916 return 1
917 fi
919 echo "delta" > $testroot/content.expected
920 cat $testroot/wt/gamma/delta > $testroot/content
921 cmp -s $testroot/content.expected $testroot/content
922 ret=$?
923 if [ $ret -ne 0 ]; then
924 diff -u $testroot/content.expected $testroot/content
925 test_done "$testroot" "$ret"
926 return 1
927 fi
929 echo "modified alpha on master" > $testroot/content.expected
930 cat $testroot/wt/alpha > $testroot/content
931 cmp -s $testroot/content.expected $testroot/content
932 ret=$?
933 if [ $ret -ne 0 ]; then
934 diff -u $testroot/content.expected $testroot/content
935 test_done "$testroot" "$ret"
936 return 1
937 fi
939 echo "beta" > $testroot/content.expected
940 cat $testroot/wt/beta > $testroot/content
941 cmp -s $testroot/content.expected $testroot/content
942 ret=$?
943 if [ $ret -ne 0 ]; then
944 diff -u $testroot/content.expected $testroot/content
945 test_done "$testroot" "$ret"
946 return 1
947 fi
949 if [ -e $testroot/wt/epsilon/new ]; then
950 echo "reverted file epsilon/new still exists on disk" >&2
951 test_done "$testroot" "1"
952 return 1
953 fi
955 if [ -e $testroot/wt/symlink ]; then
956 echo "reverted symlink still exists on disk" >&2
957 test_done "$testroot" "1"
958 return 1
959 fi
961 (cd $testroot/wt && got status > $testroot/stdout)
963 echo "? added-file" > $testroot/stdout.expected
964 echo "? unversioned-file" >> $testroot/stdout.expected
965 cmp -s $testroot/stdout.expected $testroot/stdout
966 ret=$?
967 if [ $ret -ne 0 ]; then
968 diff -u $testroot/stdout.expected $testroot/stdout
969 test_done "$testroot" "$ret"
970 return 1
971 fi
973 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
974 echo "commit $master_commit (master)" > $testroot/stdout.expected
975 echo "commit $commit0" >> $testroot/stdout.expected
976 cmp -s $testroot/stdout.expected $testroot/stdout
977 ret=$?
978 if [ $ret -ne 0 ]; then
979 diff -u $testroot/stdout.expected $testroot/stdout
980 test_done "$testroot" "$ret"
981 return 1
982 fi
984 (cd $testroot/wt && got update > $testroot/stdout)
986 echo 'Already up-to-date' > $testroot/stdout.expected
987 cmp -s $testroot/stdout.expected $testroot/stdout
988 ret=$?
989 if [ $ret -ne 0 ]; then
990 diff -u $testroot/stdout.expected $testroot/stdout
991 fi
992 test_done "$testroot" "$ret"
995 test_merge_in_progress() {
996 local testroot=`test_init merge_in_progress`
997 local commit0=`git_show_head $testroot/repo`
998 local commit0_author_time=`git_show_author_time $testroot/repo`
1000 (cd $testroot/repo && git checkout -q -b newbranch)
1001 echo "modified alpha on branch" > $testroot/repo/alpha
1002 git_commit $testroot/repo -m "committing to alpha on newbranch"
1003 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1005 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1006 ret=$?
1007 if [ $ret -ne 0 ]; then
1008 echo "got checkout failed unexpectedly" >&2
1009 test_done "$testroot" "$ret"
1010 return 1
1013 # create a conflicting commit
1014 (cd $testroot/repo && git checkout -q master)
1015 echo "modified alpha on master" > $testroot/repo/alpha
1016 git_commit $testroot/repo -m "committing to alpha on master"
1017 local master_commit=`git_show_head $testroot/repo`
1019 # need an up-to-date work tree for 'got merge'
1020 (cd $testroot/wt && got update > /dev/null)
1021 ret=$?
1022 if [ $ret -ne 0 ]; then
1023 echo "got update failed unexpectedly" >&2
1024 test_done "$testroot" "$ret"
1025 return 1
1028 (cd $testroot/wt && got merge newbranch \
1029 > $testroot/stdout 2> $testroot/stderr)
1030 ret=$?
1031 if [ $ret -eq 0 ]; then
1032 echo "got merge succeeded unexpectedly" >&2
1033 test_done "$testroot" "1"
1034 return 1
1037 echo "C alpha" >> $testroot/stdout.expected
1038 echo "Files with new merge conflicts: 1" >> $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 "got: conflicts must be resolved before merging can continue" \
1048 > $testroot/stderr.expected
1049 cmp -s $testroot/stderr.expected $testroot/stderr
1050 ret=$?
1051 if [ $ret -ne 0 ]; then
1052 diff -u $testroot/stderr.expected $testroot/stderr
1053 test_done "$testroot" "$ret"
1054 return 1
1057 (cd $testroot/wt && got status > $testroot/stdout)
1059 echo "C alpha" > $testroot/stdout.expected
1060 cmp -s $testroot/stdout.expected $testroot/stdout
1061 ret=$?
1062 if [ $ret -ne 0 ]; then
1063 diff -u $testroot/stdout.expected $testroot/stdout
1064 test_done "$testroot" "$ret"
1065 return 1
1068 for cmd in update commit histedit "rebase newbranch" \
1069 "integrate newbranch" "merge newbranch" "stage alpha"; do
1070 (cd $testroot/wt && got $cmd > $testroot/stdout \
1071 2> $testroot/stderr)
1072 ret=$?
1073 if [ $ret -eq 0 ]; then
1074 echo "got $cmd succeeded unexpectedly" >&2
1075 test_done "$testroot" "1"
1076 return 1
1079 echo -n > $testroot/stdout.expected
1080 cmp -s $testroot/stdout.expected $testroot/stdout
1081 ret=$?
1082 if [ $ret -ne 0 ]; then
1083 diff -u $testroot/stdout.expected $testroot/stdout
1084 test_done "$testroot" "$ret"
1085 return 1
1088 echo -n "got: a merge operation is in progress in this " \
1089 > $testroot/stderr.expected
1090 echo "work tree and must be continued or aborted first" \
1091 >> $testroot/stderr.expected
1092 cmp -s $testroot/stderr.expected $testroot/stderr
1093 ret=$?
1094 if [ $ret -ne 0 ]; then
1095 diff -u $testroot/stderr.expected $testroot/stderr
1096 test_done "$testroot" "$ret"
1097 return 1
1099 done
1101 test_done "$testroot" "$ret"
1104 test_merge_path_prefix() {
1105 local testroot=`test_init merge_path_prefix`
1106 local commit0=`git_show_head $testroot/repo`
1107 local commit0_author_time=`git_show_author_time $testroot/repo`
1109 (cd $testroot/repo && git checkout -q -b newbranch)
1110 echo "modified alpha on branch" > $testroot/repo/alpha
1111 git_commit $testroot/repo -m "committing to alpha on newbranch"
1112 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1114 got checkout -p epsilon -b master $testroot/repo $testroot/wt \
1115 > /dev/null
1116 ret=$?
1117 if [ $ret -ne 0 ]; then
1118 echo "got checkout failed unexpectedly" >&2
1119 test_done "$testroot" "$ret"
1120 return 1
1123 # create a conflicting commit
1124 (cd $testroot/repo && git checkout -q master)
1125 echo "modified alpha on master" > $testroot/repo/alpha
1126 git_commit $testroot/repo -m "committing to alpha on master"
1127 local master_commit=`git_show_head $testroot/repo`
1129 # need an up-to-date work tree for 'got merge'
1130 (cd $testroot/wt && got update > /dev/null)
1131 ret=$?
1132 if [ $ret -ne 0 ]; then
1133 echo "got update failed unexpectedly" >&2
1134 test_done "$testroot" "$ret"
1135 return 1
1138 (cd $testroot/wt && got merge newbranch \
1139 > $testroot/stdout 2> $testroot/stderr)
1140 ret=$?
1141 if [ $ret -eq 0 ]; then
1142 echo "got merge succeeded unexpectedly" >&2
1143 test_done "$testroot" "1"
1144 return 1
1147 echo -n "got: cannot merge branch which contains changes outside " \
1148 > $testroot/stderr.expected
1149 echo "of this work tree's path prefix" >> $testroot/stderr.expected
1150 cmp -s $testroot/stderr.expected $testroot/stderr
1151 ret=$?
1152 if [ $ret -ne 0 ]; then
1153 diff -u $testroot/stderr.expected $testroot/stderr
1155 test_done "$testroot" "$ret"
1158 test_merge_missing_file() {
1159 local testroot=`test_init merge_missing_file`
1160 local commit0=`git_show_head $testroot/repo`
1161 local commit0_author_time=`git_show_author_time $testroot/repo`
1163 (cd $testroot/repo && git checkout -q -b newbranch)
1164 echo "modified alpha on branch" > $testroot/repo/alpha
1165 echo "modified delta on branch" > $testroot/repo/gamma/delta
1166 git_commit $testroot/repo -m "committing to alpha and delta"
1167 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1169 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1170 ret=$?
1171 if [ $ret -ne 0 ]; then
1172 echo "got checkout failed unexpectedly" >&2
1173 test_done "$testroot" "$ret"
1174 return 1
1177 # create a conflicting commit which renames alpha
1178 (cd $testroot/repo && git checkout -q master)
1179 (cd $testroot/repo && git mv alpha epsilon/alpha-moved)
1180 git_commit $testroot/repo -m "moving alpha on master"
1181 local master_commit=`git_show_head $testroot/repo`
1183 # need an up-to-date work tree for 'got merge'
1184 (cd $testroot/wt && got update > /dev/null)
1185 ret=$?
1186 if [ $ret -ne 0 ]; then
1187 echo "got update failed unexpectedly" >&2
1188 test_done "$testroot" "$ret"
1189 return 1
1192 (cd $testroot/wt && got merge newbranch \
1193 > $testroot/stdout 2> $testroot/stderr)
1194 ret=$?
1195 if [ $ret -eq 0 ]; then
1196 echo "got merge succeeded unexpectedly" >&2
1197 test_done "$testroot" "1"
1198 return 1
1201 echo "! alpha" > $testroot/stdout.expected
1202 echo "G gamma/delta" >> $testroot/stdout.expected
1203 echo -n "Files which had incoming changes but could not be found " \
1204 >> $testroot/stdout.expected
1205 echo "in the work tree: 1" >> $testroot/stdout.expected
1206 cmp -s $testroot/stdout.expected $testroot/stdout
1207 ret=$?
1208 if [ $ret -ne 0 ]; then
1209 diff -u $testroot/stdout.expected $testroot/stdout
1210 test_done "$testroot" "$ret"
1211 return 1
1214 echo -n "got: changes destined for some files " \
1215 > $testroot/stderr.expected
1216 echo -n "were not yet merged and should be merged manually if " \
1217 >> $testroot/stderr.expected
1218 echo "required before the merge operation is continued" \
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
1228 (cd $testroot/wt && got status > $testroot/stdout)
1230 echo "M gamma/delta" > $testroot/stdout.expected
1231 cmp -s $testroot/stdout.expected $testroot/stdout
1232 ret=$?
1233 if [ $ret -ne 0 ]; then
1234 diff -u $testroot/stdout.expected $testroot/stdout
1235 test_done "$testroot" "$ret"
1236 return 1
1239 test_done "$testroot" "$ret"
1242 test_merge_no_op() {
1243 local testroot=`test_init merge_no_op`
1244 local commit0=`git_show_head $testroot/repo`
1245 local commit0_author_time=`git_show_author_time $testroot/repo`
1247 (cd $testroot/repo && git checkout -q -b newbranch)
1248 echo "modified alpha on branch" > $testroot/repo/alpha
1249 git_commit $testroot/repo -m "committing to alpha on newbranch"
1250 local branch_commit=`git_show_branch_head $testroot/repo newbranch`
1252 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1253 ret=$?
1254 if [ $ret -ne 0 ]; then
1255 echo "got checkout failed unexpectedly" >&2
1256 test_done "$testroot" "$ret"
1257 return 1
1260 # create a conflicting commit
1261 (cd $testroot/repo && git checkout -q master)
1262 echo "modified alpha on master" > $testroot/repo/alpha
1263 git_commit $testroot/repo -m "committing to alpha on master"
1264 local master_commit=`git_show_head $testroot/repo`
1266 # need an up-to-date work tree for 'got merge'
1267 (cd $testroot/wt && got update > /dev/null)
1268 ret=$?
1269 if [ $ret -ne 0 ]; then
1270 echo "got update failed unexpectedly" >&2
1271 test_done "$testroot" "$ret"
1272 return 1
1275 (cd $testroot/wt && got merge newbranch \
1276 > $testroot/stdout 2> $testroot/stderr)
1277 ret=$?
1278 if [ $ret -eq 0 ]; then
1279 echo "got merge succeeded unexpectedly" >&2
1280 test_done "$testroot" "1"
1281 return 1
1284 echo "C alpha" >> $testroot/stdout.expected
1285 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1286 cmp -s $testroot/stdout.expected $testroot/stdout
1287 ret=$?
1288 if [ $ret -ne 0 ]; then
1289 diff -u $testroot/stdout.expected $testroot/stdout
1290 test_done "$testroot" "$ret"
1291 return 1
1294 echo "got: conflicts must be resolved before merging can continue" \
1295 > $testroot/stderr.expected
1296 cmp -s $testroot/stderr.expected $testroot/stderr
1297 ret=$?
1298 if [ $ret -ne 0 ]; then
1299 diff -u $testroot/stderr.expected $testroot/stderr
1300 test_done "$testroot" "$ret"
1301 return 1
1304 (cd $testroot/wt && got status > $testroot/stdout)
1306 echo "C alpha" > $testroot/stdout.expected
1307 cmp -s $testroot/stdout.expected $testroot/stdout
1308 ret=$?
1309 if [ $ret -ne 0 ]; then
1310 diff -u $testroot/stdout.expected $testroot/stdout
1311 test_done "$testroot" "$ret"
1312 return 1
1315 # resolve the conflict by reverting all changes; now it is no-op merge
1316 (cd $testroot/wt && got revert alpha > /dev/null)
1317 ret=$?
1318 if [ $ret -ne 0 ]; then
1319 echo "got revert failed unexpectedly" >&2
1320 test_done "$testroot" "$ret"
1321 return 1
1324 (cd $testroot/wt && got merge -c > $testroot/stdout \
1325 2> $testroot/stderr)
1326 ret=$?
1327 if [ $ret -ne 0 ]; then
1328 echo "got merge failed unexpectedly" >&2
1329 test_done "$testroot" "$ret"
1330 return 1
1333 echo -n '' > $testroot/stderr.expected
1334 cmp -s $testroot/stderr.expected $testroot/stderr
1335 ret=$?
1336 if [ $ret -ne 0 ]; then
1337 diff -u $testroot/stderr.expected $testroot/stderr
1338 test_done "$testroot" "$ret"
1339 return 1
1342 local merge_commit=`git_show_head $testroot/repo`
1343 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1344 > $testroot/stdout.expected
1345 echo $merge_commit >> $testroot/stdout.expected
1347 cmp -s $testroot/stdout.expected $testroot/stdout
1348 ret=$?
1349 if [ $ret -ne 0 ]; then
1350 diff -u $testroot/stdout.expected $testroot/stdout
1351 test_done "$testroot" "$ret"
1352 return 1
1355 (cd $testroot/wt && got status > $testroot/stdout)
1357 echo -n "" > $testroot/stdout.expected
1358 cmp -s $testroot/stdout.expected $testroot/stdout
1359 ret=$?
1360 if [ $ret -ne 0 ]; then
1361 diff -u $testroot/stdout.expected $testroot/stdout
1362 test_done "$testroot" "$ret"
1363 return 1
1366 # We should have created a merge commit with two parents.
1367 got log -r $testroot/repo -l1 -c $merge_commit | grep ^parent \
1368 > $testroot/stdout
1369 echo "parent 1: $master_commit" > $testroot/stdout.expected
1370 echo "parent 2: $branch_commit" >> $testroot/stdout.expected
1371 cmp -s $testroot/stdout.expected $testroot/stdout
1372 ret=$?
1373 if [ $ret -ne 0 ]; then
1374 diff -u $testroot/stdout.expected $testroot/stdout
1376 test_done "$testroot" "$ret"
1379 test_merge_imported_branch() {
1380 local testroot=`test_init merge_import`
1381 local commit0=`git_show_head $testroot/repo`
1382 local commit0_author_time=`git_show_author_time $testroot/repo`
1384 # import a new sub-tree to the 'files' branch such that
1385 # none of the files added here collide with existing ones
1386 mkdir -p $testroot/tree/there
1387 mkdir -p $testroot/tree/be/lots
1388 mkdir -p $testroot/tree/files
1389 echo "there should" > $testroot/tree/there/should
1390 echo "be lots of" > $testroot/tree/be/lots/of
1391 echo "files here" > $testroot/tree/files/here
1392 got import -r $testroot/repo -b files -m 'import files' \
1393 $testroot/tree > /dev/null
1395 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1396 ret=$?
1397 if [ $ret -ne 0 ]; then
1398 echo "got checkout failed unexpectedly" >&2
1399 test_done "$testroot" "$ret"
1400 return 1
1403 (cd $testroot/wt && got merge files > $testroot/stdout)
1404 ret=$?
1405 if [ $ret -ne 0 ]; then
1406 echo "got merge failed unexpectedly" >&2
1407 test_done "$testroot" "$ret"
1408 return 1
1411 local merge_commit0=`git_show_head $testroot/repo`
1412 cat > $testroot/stdout.expected <<EOF
1413 A be/lots/of
1414 A files/here
1415 A there/should
1416 Merged refs/heads/files into refs/heads/master: $merge_commit0
1417 EOF
1418 cmp -s $testroot/stdout.expected $testroot/stdout
1419 ret=$?
1420 if [ $ret -ne 0 ]; then
1421 diff -u $testroot/stdout.expected $testroot/stdout
1422 test_done "$testroot" "$ret"
1423 return 1
1426 # try to merge again while no new changes are available
1427 (cd $testroot/wt && got merge files > $testroot/stdout)
1428 ret=$?
1429 if [ $ret -ne 0 ]; then
1430 echo "got merge failed unexpectedly" >&2
1431 test_done "$testroot" "$ret"
1432 return 1
1434 echo "Already up-to-date" > $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 # update the 'files' branch
1444 (cd $testroot/repo && git reset -q --hard master)
1445 (cd $testroot/repo && git checkout -q files)
1446 echo "indeed" > $testroot/repo/indeed
1447 (cd $testroot/repo && git add indeed)
1448 git_commit $testroot/repo -m "adding another file indeed"
1449 echo "be lots and lots of" > $testroot/repo/be/lots/of
1450 git_commit $testroot/repo -m "lots of changes"
1452 (cd $testroot/wt && got update > /dev/null)
1453 ret=$?
1454 if [ $ret -ne 0 ]; then
1455 echo "got update failed unexpectedly" >&2
1456 test_done "$testroot" "$ret"
1457 return 1
1460 # we should now be able to merge more changes from files branch
1461 (cd $testroot/wt && got merge files > $testroot/stdout)
1462 ret=$?
1463 if [ $ret -ne 0 ]; then
1464 echo "got merge failed unexpectedly" >&2
1465 test_done "$testroot" "$ret"
1466 return 1
1469 local merge_commit1=`git_show_branch_head $testroot/repo master`
1470 cat > $testroot/stdout.expected <<EOF
1471 G be/lots/of
1472 A indeed
1473 Merged refs/heads/files into refs/heads/master: $merge_commit1
1474 EOF
1476 cmp -s $testroot/stdout.expected $testroot/stdout
1477 ret=$?
1478 if [ $ret -ne 0 ]; then
1479 diff -u $testroot/stdout.expected $testroot/stdout
1481 test_done "$testroot" "$ret"
1484 test_merge_interrupt() {
1485 local testroot=`test_init merge_interrupt`
1486 local commit0=`git_show_head $testroot/repo`
1487 local commit0_author_time=`git_show_author_time $testroot/repo`
1489 (cd $testroot/repo && git checkout -q -b newbranch)
1490 echo "modified alpha on branch" > $testroot/repo/alpha
1491 git_commit $testroot/repo -m "committing to alpha on newbranch"
1492 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1494 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1495 ret=$?
1496 if [ $ret -ne 0 ]; then
1497 echo "got checkout failed unexpectedly" >&2
1498 test_done "$testroot" "$ret"
1499 return 1
1502 # create a non-conflicting commit
1503 (cd $testroot/repo && git checkout -q master)
1504 echo "modified beta on master" > $testroot/repo/beta
1505 git_commit $testroot/repo -m "committing to beta on master"
1506 local master_commit=`git_show_head $testroot/repo`
1508 # need an up-to-date work tree for 'got merge'
1509 (cd $testroot/wt && got update > /dev/null)
1510 ret=$?
1511 if [ $ret -ne 0 ]; then
1512 echo "got update failed unexpectedly" >&2
1513 test_done "$testroot" "$ret"
1514 return 1
1517 (cd $testroot/wt && got merge -n newbranch \
1518 > $testroot/stdout 2> $testroot/stderr)
1519 ret=$?
1520 if [ $ret -ne 0 ]; then
1521 echo "got merge failed unexpectedly" >&2
1522 test_done "$testroot" "1"
1523 return 1
1526 echo "G alpha" > $testroot/stdout.expected
1527 echo "Merge of refs/heads/newbranch interrupted on request" \
1528 >> $testroot/stdout.expected
1529 cmp -s $testroot/stdout.expected $testroot/stdout
1530 ret=$?
1531 if [ $ret -ne 0 ]; then
1532 diff -u $testroot/stdout.expected $testroot/stdout
1533 test_done "$testroot" "$ret"
1534 return 1
1537 (cd $testroot/wt && got status > $testroot/stdout)
1539 echo "M alpha" > $testroot/stdout.expected
1540 cmp -s $testroot/stdout.expected $testroot/stdout
1541 ret=$?
1542 if [ $ret -ne 0 ]; then
1543 diff -u $testroot/stdout.expected $testroot/stdout
1544 test_done "$testroot" "$ret"
1545 return 1
1548 echo "modified alpha on branch" > $testroot/content.expected
1549 cat $testroot/wt/alpha > $testroot/content
1550 cmp -s $testroot/content.expected $testroot/content
1551 ret=$?
1552 if [ $ret -ne 0 ]; then
1553 diff -u $testroot/content.expected $testroot/content
1554 test_done "$testroot" "$ret"
1555 return 1
1558 # adjust merge result
1559 echo "adjusted merge result" > $testroot/wt/alpha
1561 # continue the merge
1562 (cd $testroot/wt && got merge -c > $testroot/stdout)
1563 ret=$?
1564 if [ $ret -ne 0 ]; then
1565 echo "got merge failed unexpectedly" >&2
1566 test_done "$testroot" "$ret"
1567 return 1
1570 local merge_commit=`git_show_head $testroot/repo`
1572 echo "M alpha" > $testroot/stdout.expected
1573 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1574 >> $testroot/stdout.expected
1575 echo $merge_commit >> $testroot/stdout.expected
1577 cmp -s $testroot/stdout.expected $testroot/stdout
1578 ret=$?
1579 if [ $ret -ne 0 ]; then
1580 diff -u $testroot/stdout.expected $testroot/stdout
1581 test_done "$testroot" "$ret"
1582 return 1
1585 (cd $testroot/wt && got status > $testroot/stdout)
1587 echo -n > $testroot/stdout.expected
1588 cmp -s $testroot/stdout.expected $testroot/stdout
1589 ret=$?
1590 if [ $ret -ne 0 ]; then
1591 diff -u $testroot/stdout.expected $testroot/stdout
1592 test_done "$testroot" "$ret"
1593 return 1
1596 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1597 echo "commit $merge_commit (master)" > $testroot/stdout.expected
1598 echo "commit $master_commit" >> $testroot/stdout.expected
1599 echo "commit $commit0" >> $testroot/stdout.expected
1600 cmp -s $testroot/stdout.expected $testroot/stdout
1601 ret=$?
1602 if [ $ret -ne 0 ]; then
1603 diff -u $testroot/stdout.expected $testroot/stdout
1604 test_done "$testroot" "$ret"
1605 return 1
1608 (cd $testroot/wt && got update > $testroot/stdout)
1610 echo 'Already up-to-date' > $testroot/stdout.expected
1611 cmp -s $testroot/stdout.expected $testroot/stdout
1612 ret=$?
1613 if [ $ret -ne 0 ]; then
1614 diff -u $testroot/stdout.expected $testroot/stdout
1615 test_done "$testroot" "$ret"
1616 return 1
1619 # We should have created a merge commit with two parents.
1620 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
1621 echo "parent 1: $master_commit" > $testroot/stdout.expected
1622 echo "parent 2: $branch_commit0" >> $testroot/stdout.expected
1623 cmp -s $testroot/stdout.expected $testroot/stdout
1624 ret=$?
1625 if [ $ret -ne 0 ]; then
1626 diff -u $testroot/stdout.expected $testroot/stdout
1628 test_done "$testroot" "$ret"
1631 test_merge_umask() {
1632 local testroot=`test_init merge_umask`
1634 (cd $testroot/repo && git checkout -q -b newbranch)
1635 echo "modified alpha on branch" >$testroot/repo/alpha
1636 git_commit "$testroot/repo" -m "committing alpha on newbranch"
1637 echo "modified delta on branch" >$testroot/repo/gamma/delta
1638 git_commit "$testroot/repo" -m "committing delta on newbranch"
1640 # diverge from newbranch
1641 (cd "$testroot/repo" && git checkout -q master)
1642 echo "modified beta on master" >$testroot/repo/beta
1643 git_commit "$testroot/repo" -m "committing zeto no master"
1645 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1647 # using a subshell to avoid clobbering global umask
1648 (umask 077 && cd "$testroot/wt" && got merge newbranch) >/dev/null
1650 for f in alpha gamma/delta; do
1651 ls -l "$testroot/wt/$f" | grep -q ^-rw-------
1652 if [ $? -ne 0 ]; then
1653 echo "$f is not 0600 after merge" >&2
1654 ls -l "$testroot/wt/$f" >&2
1655 test_done "$testroot" 1
1657 done
1659 test_done "$testroot" 0
1662 test_merge_gitconfig_author() {
1663 local testroot=`test_init merge_gitconfig_author`
1665 (cd $testroot/repo && git config user.name 'Flan Luck')
1666 (cd $testroot/repo && git config user.email 'flan_luck@openbsd.org')
1668 (cd $testroot/repo && git checkout -q -b newbranch)
1669 echo "modified alpha on branch" >$testroot/repo/alpha
1670 git_commit "$testroot/repo" -m "committing alpha on newbranch"
1671 echo "modified delta on branch" >$testroot/repo/gamma/delta
1672 git_commit "$testroot/repo" -m "committing delta on newbranch"
1674 # diverge from newbranch
1675 (cd "$testroot/repo" && git checkout -q master)
1676 echo "modified beta on master" >$testroot/repo/beta
1677 git_commit "$testroot/repo" -m "committing zeto no master"
1679 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1681 # unset in a subshell to avoid affecting our environment
1682 (unset GOT_IGNORE_GITCONFIG && cd $testroot/wt && \
1683 got merge newbranch > /dev/null)
1685 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
1686 ret=$?
1687 if [ $ret -ne 0 ]; then
1688 test_done "$testroot" "$ret"
1689 return 1
1692 echo "from: Flan Luck <flan_luck@openbsd.org>" \
1693 > $testroot/stdout.expected
1694 cmp -s $testroot/stdout.expected $testroot/stdout
1695 ret=$?
1696 if [ $ret -ne 0 ]; then
1697 diff -u $testroot/stdout.expected $testroot/stdout
1699 test_done "$testroot" "$ret"
1702 test_merge_fetched_branch() {
1703 local testroot=`test_init merge_fetched_branch`
1704 local testurl=ssh://127.0.0.1/$testroot
1705 local commit_id=`git_show_head $testroot/repo`
1707 got clone -q $testurl/repo $testroot/repo-clone
1708 ret=$?
1709 if [ $ret -ne 0 ]; then
1710 echo "got clone command failed unexpectedly" >&2
1711 test_done "$testroot" "$ret"
1712 return 1
1715 echo "modified alpha" > $testroot/repo/alpha
1716 git_commit $testroot/repo -m "modified alpha"
1717 local commit_id2=`git_show_head $testroot/repo`
1719 got fetch -q -r $testroot/repo-clone > $testroot/stdout
1720 ret=$?
1721 if [ $ret -ne 0 ]; then
1722 echo "got fetch command failed unexpectedly" >&2
1723 test_done "$testroot" "$ret"
1724 return 1
1727 echo -n > $testroot/stdout.expected
1729 cmp -s $testroot/stdout $testroot/stdout.expected
1730 ret=$?
1731 if [ $ret -ne 0 ]; then
1732 diff -u $testroot/stdout.expected $testroot/stdout
1733 test_done "$testroot" "$ret"
1734 return 1
1737 got ref -l -r $testroot/repo-clone > $testroot/stdout
1739 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1740 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1741 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1742 >> $testroot/stdout.expected
1743 echo "refs/remotes/origin/master: $commit_id2" \
1744 >> $testroot/stdout.expected
1746 cmp -s $testroot/stdout $testroot/stdout.expected
1747 ret=$?
1748 if [ $ret -ne 0 ]; then
1749 diff -u $testroot/stdout.expected $testroot/stdout
1750 test_done "$testroot" "$ret"
1751 return 1
1754 got checkout $testroot/repo-clone $testroot/wt > /dev/null
1756 echo "modified beta" > $testroot/wt/beta
1757 (cd $testroot/wt && got commit -m "modified beta" > /dev/null)
1758 local commit_id3=`git_show_head $testroot/repo-clone`
1760 (cd $testroot/wt && got update > /dev/null)
1761 (cd $testroot/wt && got merge origin/master > $testroot/stdout)
1762 local merge_commit_id=`git_show_head $testroot/repo-clone`
1764 cat > $testroot/stdout.expected <<EOF
1765 G alpha
1766 Merged refs/remotes/origin/master into refs/heads/master: $merge_commit_id
1767 EOF
1769 cmp -s $testroot/stdout $testroot/stdout.expected
1770 ret=$?
1771 if [ $ret -ne 0 ]; then
1772 diff -u $testroot/stdout.expected $testroot/stdout
1774 test_done "$testroot" "$ret"
1777 test_merge_fetched_branch_remote() {
1778 local testroot=`test_init merge_fetched_branch_remote`
1779 local testurl=ssh://127.0.0.1/$testroot
1780 local commit_id=`git_show_head $testroot/repo`
1782 got clone -q $testurl/repo $testroot/repo-clone
1783 ret=$?
1784 if [ $ret -ne 0 ]; then
1785 echo "got clone command failed unexpectedly" >&2
1786 test_done "$testroot" "$ret"
1787 return 1
1790 echo "modified alpha" > $testroot/repo/alpha
1791 git_commit $testroot/repo -m "modified alpha"
1792 local commit_id2=`git_show_head $testroot/repo`
1794 got fetch -q -r $testroot/repo-clone > $testroot/stdout
1795 ret=$?
1796 if [ $ret -ne 0 ]; then
1797 echo "got fetch command failed unexpectedly" >&2
1798 test_done "$testroot" "$ret"
1799 return 1
1802 echo -n > $testroot/stdout.expected
1804 cmp -s $testroot/stdout $testroot/stdout.expected
1805 ret=$?
1806 if [ $ret -ne 0 ]; then
1807 diff -u $testroot/stdout.expected $testroot/stdout
1808 test_done "$testroot" "$ret"
1809 return 1
1812 got ref -l -r $testroot/repo-clone > $testroot/stdout
1814 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1815 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1816 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1817 >> $testroot/stdout.expected
1818 echo "refs/remotes/origin/master: $commit_id2" \
1819 >> $testroot/stdout.expected
1821 cmp -s $testroot/stdout $testroot/stdout.expected
1822 ret=$?
1823 if [ $ret -ne 0 ]; then
1824 diff -u $testroot/stdout.expected $testroot/stdout
1825 test_done "$testroot" "$ret"
1826 return 1
1829 got checkout $testroot/repo-clone $testroot/wt > /dev/null
1831 echo "modified beta" > $testroot/wt/beta
1832 (cd $testroot/wt && got commit -m "modified beta" > /dev/null)
1833 local commit_id3=`git_show_head $testroot/repo-clone`
1835 (cd $testroot/wt && got update -b origin/master > /dev/null)
1836 (cd $testroot/wt && got merge master > \
1837 $testroot/stdout 2> $testroot/stderr)
1838 local merge_commit_id=`git_show_head $testroot/repo-clone`
1840 echo -n > $testroot/stdout.expected
1842 cmp -s $testroot/stdout $testroot/stdout.expected
1843 ret=$?
1844 if [ $ret -ne 0 ]; then
1845 diff -u $testroot/stdout.expected $testroot/stdout
1846 test_done "$testroot" "$ret"
1847 return 1
1850 echo -n "got: work tree's current branch refs/remotes/origin/master " \
1851 > $testroot/stderr.expected
1852 echo -n 'is outside the "refs/heads/" reference namespace; ' \
1853 >> $testroot/stderr.expected
1854 echo -n "update -b required: will not commit to a branch " \
1855 >> $testroot/stderr.expected
1856 echo 'outside the "refs/heads/" reference namespace' \
1857 >> $testroot/stderr.expected
1859 cmp -s $testroot/stderr $testroot/stderr.expected
1860 ret=$?
1861 if [ $ret -ne 0 ]; then
1862 diff -u $testroot/stderr.expected $testroot/stderr
1864 test_done "$testroot" "$ret"
1867 test_parseargs "$@"
1868 run_test test_merge_basic
1869 run_test test_merge_forward
1870 run_test test_merge_backward
1871 run_test test_merge_continue
1872 run_test test_merge_continue_new_commit
1873 run_test test_merge_abort
1874 run_test test_merge_in_progress
1875 run_test test_merge_path_prefix
1876 run_test test_merge_missing_file
1877 run_test test_merge_no_op
1878 run_test test_merge_imported_branch
1879 run_test test_merge_interrupt
1880 run_test test_merge_umask
1881 run_test test_merge_gitconfig_author
1882 run_test test_merge_fetched_branch
1883 run_test test_merge_fetched_branch_remote