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
418 echo -n "got: merge is a fast-forward; " > $testroot/stderr.expected
419 echo "this is incompatible with got merge -n" \
420 >> $testroot/stderr.expected
421 cmp -s $testroot/stderr.expected $testroot/stderr
422 ret=$?
423 if [ $ret -ne 0 ]; then
424 diff -u $testroot/stderr.expected $testroot/stderr
425 test_done "$testroot" "$ret"
426 return 1
427 fi
429 (cd $testroot/wt && got merge newbranch \
430 > $testroot/stdout 2> $testroot/stderr)
431 ret=$?
432 if [ $ret -ne 0 ]; then
433 echo "got merge failed unexpectedly" >&2
434 test_done "$testroot" "$ret"
435 return 1
436 fi
438 echo "Forwarding refs/heads/master to refs/heads/newbranch" \
439 > $testroot/stdout.expected
440 echo "U beta" >> $testroot/stdout.expected
441 echo "Updated to commit $commit2" \
442 >> $testroot/stdout.expected
443 cmp -s $testroot/stdout.expected $testroot/stdout
444 ret=$?
445 if [ $ret -ne 0 ]; then
446 diff -u $testroot/stdout.expected $testroot/stdout
447 test_done "$testroot" "$ret"
448 return 1
449 fi
451 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
452 echo -n "commit $commit2 " > $testroot/stdout.expected
453 echo "(master, newbranch)" >> $testroot/stdout.expected
454 echo "commit $commit1" >> $testroot/stdout.expected
455 echo "commit $commit0" >> $testroot/stdout.expected
456 cmp -s $testroot/stdout.expected $testroot/stdout
457 ret=$?
458 if [ $ret -ne 0 ]; then
459 diff -u $testroot/stdout.expected $testroot/stdout
460 test_done "$testroot" "$ret"
461 return 1
462 fi
463 test_done "$testroot" "$ret"
466 test_merge_backward() {
467 local testroot=`test_init merge_backward`
468 local commit0=`git_show_head $testroot/repo`
470 (cd $testroot/repo && git checkout -q -b newbranch)
471 (cd $testroot/repo && git checkout -q master)
472 echo "modified alpha on master" > $testroot/repo/alpha
473 git_commit $testroot/repo -m "committing to alpha on master"
475 got checkout -b master $testroot/repo $testroot/wt > /dev/null
476 ret=$?
477 if [ $ret -ne 0 ]; then
478 echo "got checkout failed unexpectedly" >&2
479 test_done "$testroot" "$ret"
480 return 1
481 fi
483 (cd $testroot/wt && got merge newbranch \
484 > $testroot/stdout 2> $testroot/stderr)
485 ret=$?
486 if [ $ret -ne 0 ]; then
487 echo "got merge failed unexpectedly" >&2
488 test_done "$testroot" "$ret"
489 return 1
490 fi
491 echo "Already up-to-date" > $testroot/stdout.expected
492 cmp -s $testroot/stdout.expected $testroot/stdout
493 ret=$?
494 if [ $ret -ne 0 ]; then
495 diff -u $testroot/stdout.expected $testroot/stdout
496 test_done "$testroot" "$ret"
497 return 1
498 fi
499 test_done "$testroot" "$ret"
502 test_merge_continue() {
503 local testroot=`test_init merge_continue`
504 local commit0=`git_show_head $testroot/repo`
505 local commit0_author_time=`git_show_author_time $testroot/repo`
507 (cd $testroot/repo && git checkout -q -b newbranch)
508 echo "modified delta on branch" > $testroot/repo/gamma/delta
509 git_commit $testroot/repo -m "committing to delta on newbranch"
510 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
512 echo "modified alpha on branch" > $testroot/repo/alpha
513 git_commit $testroot/repo -m "committing to alpha on newbranch"
514 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
515 (cd $testroot/repo && git rm -q beta)
516 git_commit $testroot/repo -m "removing beta on newbranch"
517 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
518 echo "new file on branch" > $testroot/repo/epsilon/new
519 (cd $testroot/repo && git add epsilon/new)
520 git_commit $testroot/repo -m "adding new file on newbranch"
521 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
523 got checkout -b master $testroot/repo $testroot/wt > /dev/null
524 ret=$?
525 if [ $ret -ne 0 ]; then
526 echo "got checkout failed unexpectedly" >&2
527 test_done "$testroot" "$ret"
528 return 1
529 fi
531 # create a conflicting commit
532 (cd $testroot/repo && git checkout -q master)
533 echo "modified alpha on master" > $testroot/repo/alpha
534 git_commit $testroot/repo -m "committing to alpha on master"
535 local master_commit=`git_show_head $testroot/repo`
537 # need an up-to-date work tree for 'got merge'
538 (cd $testroot/wt && got update > /dev/null)
539 ret=$?
540 if [ $ret -ne 0 ]; then
541 echo "got update failed unexpectedly" >&2
542 test_done "$testroot" "$ret"
543 return 1
544 fi
546 (cd $testroot/wt && got merge newbranch \
547 > $testroot/stdout 2> $testroot/stderr)
548 ret=$?
549 if [ $ret -eq 0 ]; then
550 echo "got merge succeeded unexpectedly" >&2
551 test_done "$testroot" "1"
552 return 1
553 fi
555 echo "C alpha" >> $testroot/stdout.expected
556 echo "D beta" >> $testroot/stdout.expected
557 echo "A epsilon/new" >> $testroot/stdout.expected
558 echo "G gamma/delta" >> $testroot/stdout.expected
559 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
560 cmp -s $testroot/stdout.expected $testroot/stdout
561 ret=$?
562 if [ $ret -ne 0 ]; then
563 diff -u $testroot/stdout.expected $testroot/stdout
564 test_done "$testroot" "$ret"
565 return 1
566 fi
568 echo "got: conflicts must be resolved before merging can continue" \
569 > $testroot/stderr.expected
570 cmp -s $testroot/stderr.expected $testroot/stderr
571 ret=$?
572 if [ $ret -ne 0 ]; then
573 diff -u $testroot/stderr.expected $testroot/stderr
574 test_done "$testroot" "$ret"
575 return 1
576 fi
578 (cd $testroot/wt && got status > $testroot/stdout)
580 echo "C alpha" > $testroot/stdout.expected
581 echo "D beta" >> $testroot/stdout.expected
582 echo "A epsilon/new" >> $testroot/stdout.expected
583 echo "M gamma/delta" >> $testroot/stdout.expected
584 cmp -s $testroot/stdout.expected $testroot/stdout
585 ret=$?
586 if [ $ret -ne 0 ]; then
587 diff -u $testroot/stdout.expected $testroot/stdout
588 test_done "$testroot" "$ret"
589 return 1
590 fi
592 echo '<<<<<<<' > $testroot/content.expected
593 echo "modified alpha on master" >> $testroot/content.expected
594 echo "||||||| 3-way merge base: commit $commit0" \
595 >> $testroot/content.expected
596 echo "alpha" >> $testroot/content.expected
597 echo "=======" >> $testroot/content.expected
598 echo "modified alpha on branch" >> $testroot/content.expected
599 echo ">>>>>>> merged change: commit $branch_commit3" \
600 >> $testroot/content.expected
601 cat $testroot/wt/alpha > $testroot/content
602 cmp -s $testroot/content.expected $testroot/content
603 ret=$?
604 if [ $ret -ne 0 ]; then
605 diff -u $testroot/content.expected $testroot/content
606 test_done "$testroot" "$ret"
607 return 1
608 fi
610 # resolve the conflict
611 echo "modified alpha by both branches" > $testroot/wt/alpha
613 (cd $testroot/wt && got merge -c > $testroot/stdout)
614 ret=$?
615 if [ $ret -ne 0 ]; then
616 echo "got merge failed unexpectedly" >&2
617 test_done "$testroot" "$ret"
618 return 1
619 fi
621 local merge_commit=`git_show_head $testroot/repo`
623 echo "M alpha" > $testroot/stdout.expected
624 echo "D beta" >> $testroot/stdout.expected
625 echo "A epsilon/new" >> $testroot/stdout.expected
626 echo "M gamma/delta" >> $testroot/stdout.expected
627 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
628 >> $testroot/stdout.expected
629 echo $merge_commit >> $testroot/stdout.expected
631 cmp -s $testroot/stdout.expected $testroot/stdout
632 ret=$?
633 if [ $ret -ne 0 ]; then
634 diff -u $testroot/stdout.expected $testroot/stdout
635 test_done "$testroot" "$ret"
636 return 1
637 fi
639 echo "modified delta on branch" > $testroot/content.expected
640 cat $testroot/wt/gamma/delta > $testroot/content
641 cmp -s $testroot/content.expected $testroot/content
642 ret=$?
643 if [ $ret -ne 0 ]; then
644 diff -u $testroot/content.expected $testroot/content
645 test_done "$testroot" "$ret"
646 return 1
647 fi
649 echo "modified alpha by both branches" > $testroot/content.expected
650 cat $testroot/wt/alpha > $testroot/content
651 cmp -s $testroot/content.expected $testroot/content
652 ret=$?
653 if [ $ret -ne 0 ]; then
654 diff -u $testroot/content.expected $testroot/content
655 test_done "$testroot" "$ret"
656 return 1
657 fi
659 if [ -e $testroot/wt/beta ]; then
660 echo "removed file beta still exists on disk" >&2
661 test_done "$testroot" "1"
662 return 1
663 fi
665 echo "new file on branch" > $testroot/content.expected
666 cat $testroot/wt/epsilon/new > $testroot/content
667 cmp -s $testroot/content.expected $testroot/content
668 ret=$?
669 if [ $ret -ne 0 ]; then
670 diff -u $testroot/content.expected $testroot/content
671 test_done "$testroot" "$ret"
672 return 1
673 fi
675 (cd $testroot/wt && got status > $testroot/stdout)
677 echo -n > $testroot/stdout.expected
678 cmp -s $testroot/stdout.expected $testroot/stdout
679 ret=$?
680 if [ $ret -ne 0 ]; then
681 diff -u $testroot/stdout.expected $testroot/stdout
682 test_done "$testroot" "$ret"
683 return 1
684 fi
686 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
687 echo "commit $merge_commit (master)" > $testroot/stdout.expected
688 echo "commit $master_commit" >> $testroot/stdout.expected
689 echo "commit $commit0" >> $testroot/stdout.expected
690 cmp -s $testroot/stdout.expected $testroot/stdout
691 ret=$?
692 if [ $ret -ne 0 ]; then
693 diff -u $testroot/stdout.expected $testroot/stdout
694 test_done "$testroot" "$ret"
695 return 1
696 fi
698 (cd $testroot/wt && got update > $testroot/stdout)
700 echo 'Already up-to-date' > $testroot/stdout.expected
701 cmp -s $testroot/stdout.expected $testroot/stdout
702 ret=$?
703 if [ $ret -ne 0 ]; then
704 diff -u $testroot/stdout.expected $testroot/stdout
705 test_done "$testroot" "$ret"
706 return 1
707 fi
709 # We should have created a merge commit with two parents.
710 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
711 echo "parent 1: $master_commit" > $testroot/stdout.expected
712 echo "parent 2: $branch_commit3" >> $testroot/stdout.expected
713 cmp -s $testroot/stdout.expected $testroot/stdout
714 ret=$?
715 if [ $ret -ne 0 ]; then
716 diff -u $testroot/stdout.expected $testroot/stdout
717 fi
718 test_done "$testroot" "$ret"
721 test_merge_continue_new_commit() {
722 # "got merge -c" should refuse to run if the current branch tip has
723 # changed since the merge was started, to avoid clobbering the changes.
724 local testroot=`test_init merge_continue_new_commit`
726 (cd $testroot/repo && git checkout -q -b newbranch)
727 echo "modified delta on branch" > $testroot/repo/gamma/delta
728 git_commit $testroot/repo -m "committing to delta on newbranch"
730 (cd $testroot/repo && git checkout -q master)
731 echo "modified alpha on master" > $testroot/repo/alpha
732 git_commit $testroot/repo -m "committing to alpha on master"
734 got checkout -b master $testroot/repo $testroot/wt > /dev/null
735 ret=$?
736 if [ $ret -ne 0 ]; then
737 echo "got checkout failed unexpectedly" >&2
738 test_done "$testroot" "$ret"
739 return 1
740 fi
742 (cd $testroot/wt && got merge -n newbranch >/dev/null)
743 ret=$?
744 if [ $ret -ne 0 ]; then
745 echo "got merge failed unexpectedly" >&2
746 test_done "$testroot" "$ret"
747 return 1
748 fi
750 echo "modified alpha again on master" > $testroot/repo/alpha
751 git_commit $testroot/repo -m "committing to alpha on master again"
753 (cd $testroot/wt && got merge -c > $testroot/stdout 2> $testroot/stderr)
754 ret=$?
755 if [ $ret -eq 0 ]; then
756 echo "got merge succeeded unexpectedly" >&2
757 test_done "$testroot" "1"
758 return 1
759 fi
761 echo -n > $testroot/stdout.expected
762 cmp -s $testroot/stdout.expected $testroot/stdout
763 ret=$?
764 if [ $ret -ne 0 ]; then
765 diff -u $testroot/stdout.expected $testroot/stdout
766 test_done "$testroot" "$ret"
767 return 1
768 fi
770 echo -n "got: merging cannot proceed because the work tree is no " \
771 > $testroot/stderr.expected
772 echo "longer up-to-date; merge must be aborted and retried" \
773 >> $testroot/stderr.expected
774 cmp -s $testroot/stderr.expected $testroot/stderr
775 ret=$?
776 if [ $ret -ne 0 ]; then
777 diff -u $testroot/stderr.expected $testroot/stderr
778 fi
779 test_done "$testroot" "$ret"
782 test_merge_abort() {
783 local testroot=`test_init merge_abort`
784 local commit0=`git_show_head $testroot/repo`
785 local commit0_author_time=`git_show_author_time $testroot/repo`
787 (cd $testroot/repo && git checkout -q -b newbranch)
788 echo "modified delta on branch" > $testroot/repo/gamma/delta
789 git_commit $testroot/repo -m "committing to delta on newbranch"
790 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
792 echo "modified alpha on branch" > $testroot/repo/alpha
793 git_commit $testroot/repo -m "committing to alpha on newbranch"
794 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
795 (cd $testroot/repo && git rm -q beta)
796 git_commit $testroot/repo -m "removing beta on newbranch"
797 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
798 echo "new file on branch" > $testroot/repo/epsilon/new
799 (cd $testroot/repo && git add epsilon/new)
800 git_commit $testroot/repo -m "adding new file on newbranch"
801 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
802 (cd $testroot/repo && ln -s alpha symlink && git add symlink)
803 git_commit $testroot/repo -m "adding symlink on newbranch"
804 local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
806 got checkout -b master $testroot/repo $testroot/wt > /dev/null
807 ret=$?
808 if [ $ret -ne 0 ]; then
809 echo "got checkout failed unexpectedly" >&2
810 test_done "$testroot" "$ret"
811 return 1
812 fi
814 # unrelated unversioned file in work tree
815 touch $testroot/wt/unversioned-file
817 # create a conflicting commit
818 (cd $testroot/repo && git checkout -q master)
819 echo "modified alpha on master" > $testroot/repo/alpha
820 git_commit $testroot/repo -m "committing to alpha on master"
821 local master_commit=`git_show_head $testroot/repo`
823 # need an up-to-date work tree for 'got merge'
824 (cd $testroot/wt && got update > /dev/null)
825 ret=$?
826 if [ $ret -ne 0 ]; then
827 echo "got update failed unexpectedly" >&2
828 test_done "$testroot" "$ret"
829 return 1
830 fi
832 (cd $testroot/wt && got merge newbranch \
833 > $testroot/stdout 2> $testroot/stderr)
834 ret=$?
835 if [ $ret -eq 0 ]; then
836 echo "got merge succeeded unexpectedly" >&2
837 test_done "$testroot" "1"
838 return 1
839 fi
841 echo "C alpha" >> $testroot/stdout.expected
842 echo "D beta" >> $testroot/stdout.expected
843 echo "A epsilon/new" >> $testroot/stdout.expected
844 echo "G gamma/delta" >> $testroot/stdout.expected
845 echo "A symlink" >> $testroot/stdout.expected
846 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
847 cmp -s $testroot/stdout.expected $testroot/stdout
848 ret=$?
849 if [ $ret -ne 0 ]; then
850 diff -u $testroot/stdout.expected $testroot/stdout
851 test_done "$testroot" "$ret"
852 return 1
853 fi
855 echo "got: conflicts must be resolved before merging can continue" \
856 > $testroot/stderr.expected
857 cmp -s $testroot/stderr.expected $testroot/stderr
858 ret=$?
859 if [ $ret -ne 0 ]; then
860 diff -u $testroot/stderr.expected $testroot/stderr
861 test_done "$testroot" "$ret"
862 return 1
863 fi
865 # unrelated added file added during conflict resolution
866 touch $testroot/wt/added-file
867 (cd $testroot/wt && got add added-file > /dev/null)
869 (cd $testroot/wt && got status > $testroot/stdout)
871 echo "A added-file" > $testroot/stdout.expected
872 echo "C alpha" >> $testroot/stdout.expected
873 echo "D beta" >> $testroot/stdout.expected
874 echo "A epsilon/new" >> $testroot/stdout.expected
875 echo "M gamma/delta" >> $testroot/stdout.expected
876 echo "A symlink" >> $testroot/stdout.expected
877 echo "? unversioned-file" >> $testroot/stdout.expected
878 cmp -s $testroot/stdout.expected $testroot/stdout
879 ret=$?
880 if [ $ret -ne 0 ]; then
881 diff -u $testroot/stdout.expected $testroot/stdout
882 test_done "$testroot" "$ret"
883 return 1
884 fi
886 (cd $testroot/wt && got merge -a > $testroot/stdout)
887 ret=$?
888 if [ $ret -ne 0 ]; then
889 echo "got merge failed unexpectedly" >&2
890 test_done "$testroot" "$ret"
891 return 1
892 fi
894 echo "R added-file" > $testroot/stdout.expected
895 echo "R alpha" >> $testroot/stdout.expected
896 echo "R beta" >> $testroot/stdout.expected
897 echo "R epsilon/new" >> $testroot/stdout.expected
898 echo "R gamma/delta" >> $testroot/stdout.expected
899 echo "R symlink" >> $testroot/stdout.expected
900 echo "G added-file" >> $testroot/stdout.expected
901 echo "Merge of refs/heads/newbranch aborted" \
902 >> $testroot/stdout.expected
904 cmp -s $testroot/stdout.expected $testroot/stdout
905 ret=$?
906 if [ $ret -ne 0 ]; then
907 diff -u $testroot/stdout.expected $testroot/stdout
908 test_done "$testroot" "$ret"
909 return 1
910 fi
912 echo "delta" > $testroot/content.expected
913 cat $testroot/wt/gamma/delta > $testroot/content
914 cmp -s $testroot/content.expected $testroot/content
915 ret=$?
916 if [ $ret -ne 0 ]; then
917 diff -u $testroot/content.expected $testroot/content
918 test_done "$testroot" "$ret"
919 return 1
920 fi
922 echo "modified alpha on master" > $testroot/content.expected
923 cat $testroot/wt/alpha > $testroot/content
924 cmp -s $testroot/content.expected $testroot/content
925 ret=$?
926 if [ $ret -ne 0 ]; then
927 diff -u $testroot/content.expected $testroot/content
928 test_done "$testroot" "$ret"
929 return 1
930 fi
932 echo "beta" > $testroot/content.expected
933 cat $testroot/wt/beta > $testroot/content
934 cmp -s $testroot/content.expected $testroot/content
935 ret=$?
936 if [ $ret -ne 0 ]; then
937 diff -u $testroot/content.expected $testroot/content
938 test_done "$testroot" "$ret"
939 return 1
940 fi
942 if [ -e $testroot/wt/epsilon/new ]; then
943 echo "reverted file epsilon/new still exists on disk" >&2
944 test_done "$testroot" "1"
945 return 1
946 fi
948 if [ -e $testroot/wt/symlink ]; then
949 echo "reverted symlink still exists on disk" >&2
950 test_done "$testroot" "1"
951 return 1
952 fi
954 (cd $testroot/wt && got status > $testroot/stdout)
956 echo "? added-file" > $testroot/stdout.expected
957 echo "? unversioned-file" >> $testroot/stdout.expected
958 cmp -s $testroot/stdout.expected $testroot/stdout
959 ret=$?
960 if [ $ret -ne 0 ]; then
961 diff -u $testroot/stdout.expected $testroot/stdout
962 test_done "$testroot" "$ret"
963 return 1
964 fi
966 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
967 echo "commit $master_commit (master)" > $testroot/stdout.expected
968 echo "commit $commit0" >> $testroot/stdout.expected
969 cmp -s $testroot/stdout.expected $testroot/stdout
970 ret=$?
971 if [ $ret -ne 0 ]; then
972 diff -u $testroot/stdout.expected $testroot/stdout
973 test_done "$testroot" "$ret"
974 return 1
975 fi
977 (cd $testroot/wt && got update > $testroot/stdout)
979 echo 'Already up-to-date' > $testroot/stdout.expected
980 cmp -s $testroot/stdout.expected $testroot/stdout
981 ret=$?
982 if [ $ret -ne 0 ]; then
983 diff -u $testroot/stdout.expected $testroot/stdout
984 fi
985 test_done "$testroot" "$ret"
988 test_merge_in_progress() {
989 local testroot=`test_init merge_in_progress`
990 local commit0=`git_show_head $testroot/repo`
991 local commit0_author_time=`git_show_author_time $testroot/repo`
993 (cd $testroot/repo && git checkout -q -b newbranch)
994 echo "modified alpha on branch" > $testroot/repo/alpha
995 git_commit $testroot/repo -m "committing to alpha on newbranch"
996 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
998 got checkout -b master $testroot/repo $testroot/wt > /dev/null
999 ret=$?
1000 if [ $ret -ne 0 ]; then
1001 echo "got checkout failed unexpectedly" >&2
1002 test_done "$testroot" "$ret"
1003 return 1
1006 # create a conflicting commit
1007 (cd $testroot/repo && git checkout -q master)
1008 echo "modified alpha on master" > $testroot/repo/alpha
1009 git_commit $testroot/repo -m "committing to alpha on master"
1010 local master_commit=`git_show_head $testroot/repo`
1012 # need an up-to-date work tree for 'got merge'
1013 (cd $testroot/wt && got update > /dev/null)
1014 ret=$?
1015 if [ $ret -ne 0 ]; then
1016 echo "got update failed unexpectedly" >&2
1017 test_done "$testroot" "$ret"
1018 return 1
1021 (cd $testroot/wt && got merge newbranch \
1022 > $testroot/stdout 2> $testroot/stderr)
1023 ret=$?
1024 if [ $ret -eq 0 ]; then
1025 echo "got merge succeeded unexpectedly" >&2
1026 test_done "$testroot" "1"
1027 return 1
1030 echo "C alpha" >> $testroot/stdout.expected
1031 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1032 cmp -s $testroot/stdout.expected $testroot/stdout
1033 ret=$?
1034 if [ $ret -ne 0 ]; then
1035 diff -u $testroot/stdout.expected $testroot/stdout
1036 test_done "$testroot" "$ret"
1037 return 1
1040 echo "got: conflicts must be resolved before merging can continue" \
1041 > $testroot/stderr.expected
1042 cmp -s $testroot/stderr.expected $testroot/stderr
1043 ret=$?
1044 if [ $ret -ne 0 ]; then
1045 diff -u $testroot/stderr.expected $testroot/stderr
1046 test_done "$testroot" "$ret"
1047 return 1
1050 (cd $testroot/wt && got status > $testroot/stdout)
1052 echo "C alpha" > $testroot/stdout.expected
1053 cmp -s $testroot/stdout.expected $testroot/stdout
1054 ret=$?
1055 if [ $ret -ne 0 ]; then
1056 diff -u $testroot/stdout.expected $testroot/stdout
1057 test_done "$testroot" "$ret"
1058 return 1
1061 for cmd in update commit histedit "rebase newbranch" \
1062 "integrate newbranch" "merge newbranch" "stage alpha"; do
1063 (cd $testroot/wt && got $cmd > $testroot/stdout \
1064 2> $testroot/stderr)
1065 ret=$?
1066 if [ $ret -eq 0 ]; then
1067 echo "got $cmd succeeded unexpectedly" >&2
1068 test_done "$testroot" "1"
1069 return 1
1072 echo -n > $testroot/stdout.expected
1073 cmp -s $testroot/stdout.expected $testroot/stdout
1074 ret=$?
1075 if [ $ret -ne 0 ]; then
1076 diff -u $testroot/stdout.expected $testroot/stdout
1077 test_done "$testroot" "$ret"
1078 return 1
1081 echo -n "got: a merge operation is in progress in this " \
1082 > $testroot/stderr.expected
1083 echo "work tree and must be continued or aborted first" \
1084 >> $testroot/stderr.expected
1085 cmp -s $testroot/stderr.expected $testroot/stderr
1086 ret=$?
1087 if [ $ret -ne 0 ]; then
1088 diff -u $testroot/stderr.expected $testroot/stderr
1089 test_done "$testroot" "$ret"
1090 return 1
1092 done
1094 test_done "$testroot" "$ret"
1097 test_merge_path_prefix() {
1098 local testroot=`test_init merge_path_prefix`
1099 local commit0=`git_show_head $testroot/repo`
1100 local commit0_author_time=`git_show_author_time $testroot/repo`
1102 (cd $testroot/repo && git checkout -q -b newbranch)
1103 echo "modified alpha on branch" > $testroot/repo/alpha
1104 git_commit $testroot/repo -m "committing to alpha on newbranch"
1105 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1107 got checkout -p epsilon -b master $testroot/repo $testroot/wt \
1108 > /dev/null
1109 ret=$?
1110 if [ $ret -ne 0 ]; then
1111 echo "got checkout failed unexpectedly" >&2
1112 test_done "$testroot" "$ret"
1113 return 1
1116 # create a conflicting commit
1117 (cd $testroot/repo && git checkout -q master)
1118 echo "modified alpha on master" > $testroot/repo/alpha
1119 git_commit $testroot/repo -m "committing to alpha on master"
1120 local master_commit=`git_show_head $testroot/repo`
1122 # need an up-to-date work tree for 'got merge'
1123 (cd $testroot/wt && got update > /dev/null)
1124 ret=$?
1125 if [ $ret -ne 0 ]; then
1126 echo "got update failed unexpectedly" >&2
1127 test_done "$testroot" "$ret"
1128 return 1
1131 (cd $testroot/wt && got merge newbranch \
1132 > $testroot/stdout 2> $testroot/stderr)
1133 ret=$?
1134 if [ $ret -eq 0 ]; then
1135 echo "got merge succeeded unexpectedly" >&2
1136 test_done "$testroot" "1"
1137 return 1
1140 echo -n "got: cannot merge branch which contains changes outside " \
1141 > $testroot/stderr.expected
1142 echo "of this work tree's path prefix" >> $testroot/stderr.expected
1143 cmp -s $testroot/stderr.expected $testroot/stderr
1144 ret=$?
1145 if [ $ret -ne 0 ]; then
1146 diff -u $testroot/stderr.expected $testroot/stderr
1148 test_done "$testroot" "$ret"
1151 test_merge_missing_file() {
1152 local testroot=`test_init merge_missing_file`
1153 local commit0=`git_show_head $testroot/repo`
1154 local commit0_author_time=`git_show_author_time $testroot/repo`
1156 (cd $testroot/repo && git checkout -q -b newbranch)
1157 echo "modified alpha on branch" > $testroot/repo/alpha
1158 echo "modified delta on branch" > $testroot/repo/gamma/delta
1159 git_commit $testroot/repo -m "committing to alpha and delta"
1160 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1162 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1163 ret=$?
1164 if [ $ret -ne 0 ]; then
1165 echo "got checkout failed unexpectedly" >&2
1166 test_done "$testroot" "$ret"
1167 return 1
1170 # create a conflicting commit which renames alpha
1171 (cd $testroot/repo && git checkout -q master)
1172 (cd $testroot/repo && git mv alpha epsilon/alpha-moved)
1173 git_commit $testroot/repo -m "moving alpha on master"
1174 local master_commit=`git_show_head $testroot/repo`
1176 # need an up-to-date work tree for 'got merge'
1177 (cd $testroot/wt && got update > /dev/null)
1178 ret=$?
1179 if [ $ret -ne 0 ]; then
1180 echo "got update failed unexpectedly" >&2
1181 test_done "$testroot" "$ret"
1182 return 1
1185 (cd $testroot/wt && got merge newbranch \
1186 > $testroot/stdout 2> $testroot/stderr)
1187 ret=$?
1188 if [ $ret -eq 0 ]; then
1189 echo "got merge succeeded unexpectedly" >&2
1190 test_done "$testroot" "1"
1191 return 1
1194 echo "! alpha" > $testroot/stdout.expected
1195 echo "G gamma/delta" >> $testroot/stdout.expected
1196 echo -n "Files which had incoming changes but could not be found " \
1197 >> $testroot/stdout.expected
1198 echo "in the work tree: 1" >> $testroot/stdout.expected
1199 cmp -s $testroot/stdout.expected $testroot/stdout
1200 ret=$?
1201 if [ $ret -ne 0 ]; then
1202 diff -u $testroot/stdout.expected $testroot/stdout
1203 test_done "$testroot" "$ret"
1204 return 1
1207 echo -n "got: changes destined for some files " \
1208 > $testroot/stderr.expected
1209 echo -n "were not yet merged and should be merged manually if " \
1210 >> $testroot/stderr.expected
1211 echo "required before the merge operation is continued" \
1212 >> $testroot/stderr.expected
1213 cmp -s $testroot/stderr.expected $testroot/stderr
1214 ret=$?
1215 if [ $ret -ne 0 ]; then
1216 diff -u $testroot/stderr.expected $testroot/stderr
1217 test_done "$testroot" "$ret"
1218 return 1
1221 (cd $testroot/wt && got status > $testroot/stdout)
1223 echo "M gamma/delta" > $testroot/stdout.expected
1224 cmp -s $testroot/stdout.expected $testroot/stdout
1225 ret=$?
1226 if [ $ret -ne 0 ]; then
1227 diff -u $testroot/stdout.expected $testroot/stdout
1228 test_done "$testroot" "$ret"
1229 return 1
1232 test_done "$testroot" "$ret"
1235 test_merge_no_op() {
1236 local testroot=`test_init merge_no_op`
1237 local commit0=`git_show_head $testroot/repo`
1238 local commit0_author_time=`git_show_author_time $testroot/repo`
1240 (cd $testroot/repo && git checkout -q -b newbranch)
1241 echo "modified alpha on branch" > $testroot/repo/alpha
1242 git_commit $testroot/repo -m "committing to alpha on newbranch"
1243 local branch_commit=`git_show_branch_head $testroot/repo newbranch`
1245 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1246 ret=$?
1247 if [ $ret -ne 0 ]; then
1248 echo "got checkout failed unexpectedly" >&2
1249 test_done "$testroot" "$ret"
1250 return 1
1253 # create a conflicting commit
1254 (cd $testroot/repo && git checkout -q master)
1255 echo "modified alpha on master" > $testroot/repo/alpha
1256 git_commit $testroot/repo -m "committing to alpha on master"
1257 local master_commit=`git_show_head $testroot/repo`
1259 # need an up-to-date work tree for 'got merge'
1260 (cd $testroot/wt && got update > /dev/null)
1261 ret=$?
1262 if [ $ret -ne 0 ]; then
1263 echo "got update failed unexpectedly" >&2
1264 test_done "$testroot" "$ret"
1265 return 1
1268 (cd $testroot/wt && got merge newbranch \
1269 > $testroot/stdout 2> $testroot/stderr)
1270 ret=$?
1271 if [ $ret -eq 0 ]; then
1272 echo "got merge succeeded unexpectedly" >&2
1273 test_done "$testroot" "1"
1274 return 1
1277 echo "C alpha" >> $testroot/stdout.expected
1278 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1279 cmp -s $testroot/stdout.expected $testroot/stdout
1280 ret=$?
1281 if [ $ret -ne 0 ]; then
1282 diff -u $testroot/stdout.expected $testroot/stdout
1283 test_done "$testroot" "$ret"
1284 return 1
1287 echo "got: conflicts must be resolved before merging can continue" \
1288 > $testroot/stderr.expected
1289 cmp -s $testroot/stderr.expected $testroot/stderr
1290 ret=$?
1291 if [ $ret -ne 0 ]; then
1292 diff -u $testroot/stderr.expected $testroot/stderr
1293 test_done "$testroot" "$ret"
1294 return 1
1297 (cd $testroot/wt && got status > $testroot/stdout)
1299 echo "C alpha" > $testroot/stdout.expected
1300 cmp -s $testroot/stdout.expected $testroot/stdout
1301 ret=$?
1302 if [ $ret -ne 0 ]; then
1303 diff -u $testroot/stdout.expected $testroot/stdout
1304 test_done "$testroot" "$ret"
1305 return 1
1308 # resolve the conflict by reverting all changes; now it is no-op merge
1309 (cd $testroot/wt && got revert alpha > /dev/null)
1310 ret=$?
1311 if [ $ret -ne 0 ]; then
1312 echo "got revert failed unexpectedly" >&2
1313 test_done "$testroot" "$ret"
1314 return 1
1317 (cd $testroot/wt && got merge -c > $testroot/stdout \
1318 2> $testroot/stderr)
1319 ret=$?
1320 if [ $ret -ne 0 ]; then
1321 echo "got merge failed unexpectedly" >&2
1322 test_done "$testroot" "$ret"
1323 return 1
1326 echo -n '' > $testroot/stderr.expected
1327 cmp -s $testroot/stderr.expected $testroot/stderr
1328 ret=$?
1329 if [ $ret -ne 0 ]; then
1330 diff -u $testroot/stderr.expected $testroot/stderr
1331 test_done "$testroot" "$ret"
1332 return 1
1335 local merge_commit=`git_show_head $testroot/repo`
1336 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1337 > $testroot/stdout.expected
1338 echo $merge_commit >> $testroot/stdout.expected
1340 cmp -s $testroot/stdout.expected $testroot/stdout
1341 ret=$?
1342 if [ $ret -ne 0 ]; then
1343 diff -u $testroot/stdout.expected $testroot/stdout
1344 test_done "$testroot" "$ret"
1345 return 1
1348 (cd $testroot/wt && got status > $testroot/stdout)
1350 echo -n "" > $testroot/stdout.expected
1351 cmp -s $testroot/stdout.expected $testroot/stdout
1352 ret=$?
1353 if [ $ret -ne 0 ]; then
1354 diff -u $testroot/stdout.expected $testroot/stdout
1355 test_done "$testroot" "$ret"
1356 return 1
1359 # We should have created a merge commit with two parents.
1360 got log -r $testroot/repo -l1 -c $merge_commit | grep ^parent \
1361 > $testroot/stdout
1362 echo "parent 1: $master_commit" > $testroot/stdout.expected
1363 echo "parent 2: $branch_commit" >> $testroot/stdout.expected
1364 cmp -s $testroot/stdout.expected $testroot/stdout
1365 ret=$?
1366 if [ $ret -ne 0 ]; then
1367 diff -u $testroot/stdout.expected $testroot/stdout
1369 test_done "$testroot" "$ret"
1372 test_merge_imported_branch() {
1373 local testroot=`test_init merge_import`
1374 local commit0=`git_show_head $testroot/repo`
1375 local commit0_author_time=`git_show_author_time $testroot/repo`
1377 # import a new sub-tree to the 'files' branch such that
1378 # none of the files added here collide with existing ones
1379 mkdir -p $testroot/tree/there
1380 mkdir -p $testroot/tree/be/lots
1381 mkdir -p $testroot/tree/files
1382 echo "there should" > $testroot/tree/there/should
1383 echo "be lots of" > $testroot/tree/be/lots/of
1384 echo "files here" > $testroot/tree/files/here
1385 got import -r $testroot/repo -b files -m 'import files' \
1386 $testroot/tree > /dev/null
1388 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1389 ret=$?
1390 if [ $ret -ne 0 ]; then
1391 echo "got checkout failed unexpectedly" >&2
1392 test_done "$testroot" "$ret"
1393 return 1
1396 (cd $testroot/wt && got merge files > $testroot/stdout)
1397 ret=$?
1398 if [ $ret -ne 0 ]; then
1399 echo "got merge failed unexpectedly" >&2
1400 test_done "$testroot" "$ret"
1401 return 1
1404 local merge_commit0=`git_show_head $testroot/repo`
1405 cat > $testroot/stdout.expected <<EOF
1406 A be/lots/of
1407 A files/here
1408 A there/should
1409 Merged refs/heads/files into refs/heads/master: $merge_commit0
1410 EOF
1411 cmp -s $testroot/stdout.expected $testroot/stdout
1412 ret=$?
1413 if [ $ret -ne 0 ]; then
1414 diff -u $testroot/stdout.expected $testroot/stdout
1415 test_done "$testroot" "$ret"
1416 return 1
1419 # try to merge again while no new changes are available
1420 (cd $testroot/wt && got merge files > $testroot/stdout)
1421 ret=$?
1422 if [ $ret -ne 0 ]; then
1423 echo "got merge failed unexpectedly" >&2
1424 test_done "$testroot" "$ret"
1425 return 1
1427 echo "Already up-to-date" > $testroot/stdout.expected
1428 cmp -s $testroot/stdout.expected $testroot/stdout
1429 ret=$?
1430 if [ $ret -ne 0 ]; then
1431 diff -u $testroot/stdout.expected $testroot/stdout
1432 test_done "$testroot" "$ret"
1433 return 1
1436 # update the 'files' branch
1437 (cd $testroot/repo && git reset -q --hard master)
1438 (cd $testroot/repo && git checkout -q files)
1439 echo "indeed" > $testroot/repo/indeed
1440 (cd $testroot/repo && git add indeed)
1441 git_commit $testroot/repo -m "adding another file indeed"
1442 echo "be lots and lots of" > $testroot/repo/be/lots/of
1443 git_commit $testroot/repo -m "lots of changes"
1445 (cd $testroot/wt && got update > /dev/null)
1446 ret=$?
1447 if [ $ret -ne 0 ]; then
1448 echo "got update failed unexpectedly" >&2
1449 test_done "$testroot" "$ret"
1450 return 1
1453 # we should now be able to merge more changes from files branch
1454 (cd $testroot/wt && got merge files > $testroot/stdout)
1455 ret=$?
1456 if [ $ret -ne 0 ]; then
1457 echo "got merge failed unexpectedly" >&2
1458 test_done "$testroot" "$ret"
1459 return 1
1462 local merge_commit1=`git_show_branch_head $testroot/repo master`
1463 cat > $testroot/stdout.expected <<EOF
1464 G be/lots/of
1465 A indeed
1466 Merged refs/heads/files into refs/heads/master: $merge_commit1
1467 EOF
1469 cmp -s $testroot/stdout.expected $testroot/stdout
1470 ret=$?
1471 if [ $ret -ne 0 ]; then
1472 diff -u $testroot/stdout.expected $testroot/stdout
1474 test_done "$testroot" "$ret"
1477 test_merge_interrupt() {
1478 local testroot=`test_init merge_interrupt`
1479 local commit0=`git_show_head $testroot/repo`
1480 local commit0_author_time=`git_show_author_time $testroot/repo`
1482 (cd $testroot/repo && git checkout -q -b newbranch)
1483 echo "modified alpha on branch" > $testroot/repo/alpha
1484 git_commit $testroot/repo -m "committing to alpha on newbranch"
1485 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1487 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1488 ret=$?
1489 if [ $ret -ne 0 ]; then
1490 echo "got checkout failed unexpectedly" >&2
1491 test_done "$testroot" "$ret"
1492 return 1
1495 # create a non-conflicting commit
1496 (cd $testroot/repo && git checkout -q master)
1497 echo "modified beta on master" > $testroot/repo/beta
1498 git_commit $testroot/repo -m "committing to beta on master"
1499 local master_commit=`git_show_head $testroot/repo`
1501 # need an up-to-date work tree for 'got merge'
1502 (cd $testroot/wt && got update > /dev/null)
1503 ret=$?
1504 if [ $ret -ne 0 ]; then
1505 echo "got update failed unexpectedly" >&2
1506 test_done "$testroot" "$ret"
1507 return 1
1510 (cd $testroot/wt && got merge -n newbranch \
1511 > $testroot/stdout 2> $testroot/stderr)
1512 ret=$?
1513 if [ $ret -ne 0 ]; then
1514 echo "got merge failed unexpectedly" >&2
1515 test_done "$testroot" "1"
1516 return 1
1519 echo "G alpha" > $testroot/stdout.expected
1520 echo "Merge of refs/heads/newbranch interrupted on request" \
1521 >> $testroot/stdout.expected
1522 cmp -s $testroot/stdout.expected $testroot/stdout
1523 ret=$?
1524 if [ $ret -ne 0 ]; then
1525 diff -u $testroot/stdout.expected $testroot/stdout
1526 test_done "$testroot" "$ret"
1527 return 1
1530 (cd $testroot/wt && got status > $testroot/stdout)
1532 echo "M alpha" > $testroot/stdout.expected
1533 cmp -s $testroot/stdout.expected $testroot/stdout
1534 ret=$?
1535 if [ $ret -ne 0 ]; then
1536 diff -u $testroot/stdout.expected $testroot/stdout
1537 test_done "$testroot" "$ret"
1538 return 1
1541 echo "modified alpha on branch" > $testroot/content.expected
1542 cat $testroot/wt/alpha > $testroot/content
1543 cmp -s $testroot/content.expected $testroot/content
1544 ret=$?
1545 if [ $ret -ne 0 ]; then
1546 diff -u $testroot/content.expected $testroot/content
1547 test_done "$testroot" "$ret"
1548 return 1
1551 # adjust merge result
1552 echo "adjusted merge result" > $testroot/wt/alpha
1554 # continue the merge
1555 (cd $testroot/wt && got merge -c > $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
1563 local merge_commit=`git_show_head $testroot/repo`
1565 echo "M alpha" > $testroot/stdout.expected
1566 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1567 >> $testroot/stdout.expected
1568 echo $merge_commit >> $testroot/stdout.expected
1570 cmp -s $testroot/stdout.expected $testroot/stdout
1571 ret=$?
1572 if [ $ret -ne 0 ]; then
1573 diff -u $testroot/stdout.expected $testroot/stdout
1574 test_done "$testroot" "$ret"
1575 return 1
1578 (cd $testroot/wt && got status > $testroot/stdout)
1580 echo -n > $testroot/stdout.expected
1581 cmp -s $testroot/stdout.expected $testroot/stdout
1582 ret=$?
1583 if [ $ret -ne 0 ]; then
1584 diff -u $testroot/stdout.expected $testroot/stdout
1585 test_done "$testroot" "$ret"
1586 return 1
1589 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1590 echo "commit $merge_commit (master)" > $testroot/stdout.expected
1591 echo "commit $master_commit" >> $testroot/stdout.expected
1592 echo "commit $commit0" >> $testroot/stdout.expected
1593 cmp -s $testroot/stdout.expected $testroot/stdout
1594 ret=$?
1595 if [ $ret -ne 0 ]; then
1596 diff -u $testroot/stdout.expected $testroot/stdout
1597 test_done "$testroot" "$ret"
1598 return 1
1601 (cd $testroot/wt && got update > $testroot/stdout)
1603 echo 'Already up-to-date' > $testroot/stdout.expected
1604 cmp -s $testroot/stdout.expected $testroot/stdout
1605 ret=$?
1606 if [ $ret -ne 0 ]; then
1607 diff -u $testroot/stdout.expected $testroot/stdout
1608 test_done "$testroot" "$ret"
1609 return 1
1612 # We should have created a merge commit with two parents.
1613 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
1614 echo "parent 1: $master_commit" > $testroot/stdout.expected
1615 echo "parent 2: $branch_commit0" >> $testroot/stdout.expected
1616 cmp -s $testroot/stdout.expected $testroot/stdout
1617 ret=$?
1618 if [ $ret -ne 0 ]; then
1619 diff -u $testroot/stdout.expected $testroot/stdout
1621 test_done "$testroot" "$ret"
1624 test_merge_umask() {
1625 local testroot=`test_init merge_umask`
1627 (cd $testroot/repo && git checkout -q -b newbranch)
1628 echo "modified alpha on branch" >$testroot/repo/alpha
1629 git_commit "$testroot/repo" -m "committing alpha on newbranch"
1630 echo "modified delta on branch" >$testroot/repo/gamma/delta
1631 git_commit "$testroot/repo" -m "committing delta on newbranch"
1633 # diverge from newbranch
1634 (cd "$testroot/repo" && git checkout -q master)
1635 echo "modified beta on master" >$testroot/repo/beta
1636 git_commit "$testroot/repo" -m "committing zeto no master"
1638 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1640 # using a subshell to avoid clobbering global umask
1641 (umask 077 && cd "$testroot/wt" && got merge newbranch) >/dev/null
1643 for f in alpha gamma/delta; do
1644 ls -l "$testroot/wt/$f" | grep -q ^-rw-------
1645 if [ $? -ne 0 ]; then
1646 echo "$f is not 0600 after merge" >&2
1647 ls -l "$testroot/wt/$f" >&2
1648 test_done "$testroot" 1
1650 done
1652 test_done "$testroot" 0
1655 test_merge_gitconfig_author() {
1656 local testroot=`test_init merge_gitconfig_author`
1658 (cd $testroot/repo && git config user.name 'Flan Luck')
1659 (cd $testroot/repo && git config user.email 'flan_luck@openbsd.org')
1661 (cd $testroot/repo && git checkout -q -b newbranch)
1662 echo "modified alpha on branch" >$testroot/repo/alpha
1663 git_commit "$testroot/repo" -m "committing alpha on newbranch"
1664 echo "modified delta on branch" >$testroot/repo/gamma/delta
1665 git_commit "$testroot/repo" -m "committing delta on newbranch"
1667 # diverge from newbranch
1668 (cd "$testroot/repo" && git checkout -q master)
1669 echo "modified beta on master" >$testroot/repo/beta
1670 git_commit "$testroot/repo" -m "committing zeto no master"
1672 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1674 # unset in a subshell to avoid affecting our environment
1675 (unset GOT_IGNORE_GITCONFIG && cd $testroot/wt && \
1676 got merge newbranch > /dev/null)
1678 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
1679 ret=$?
1680 if [ $ret -ne 0 ]; then
1681 test_done "$testroot" "$ret"
1682 return 1
1685 echo "from: Flan Luck <flan_luck@openbsd.org>" \
1686 > $testroot/stdout.expected
1687 cmp -s $testroot/stdout.expected $testroot/stdout
1688 ret=$?
1689 if [ $ret -ne 0 ]; then
1690 diff -u $testroot/stdout.expected $testroot/stdout
1692 test_done "$testroot" "$ret"
1695 test_parseargs "$@"
1696 run_test test_merge_basic
1697 run_test test_merge_forward
1698 run_test test_merge_backward
1699 run_test test_merge_continue
1700 run_test test_merge_continue_new_commit
1701 run_test test_merge_abort
1702 run_test test_merge_in_progress
1703 run_test test_merge_path_prefix
1704 run_test test_merge_missing_file
1705 run_test test_merge_no_op
1706 run_test test_merge_imported_branch
1707 run_test test_merge_interrupt
1708 run_test test_merge_umask
1709 run_test test_merge_gitconfig_author