Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 test_merge_basic() {
20 local testroot=`test_init merge_basic`
21 local commit0=`git_show_head $testroot/repo`
22 local commit0_author_time=`git_show_author_time $testroot/repo`
24 git -C $testroot/repo checkout -q -b newbranch
25 echo "modified delta on branch" > $testroot/repo/gamma/delta
26 git_commit $testroot/repo -m "committing to delta on newbranch"
27 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
29 echo "modified alpha on branch" > $testroot/repo/alpha
30 git_commit $testroot/repo -m "committing to alpha on newbranch"
31 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
32 git -C $testroot/repo rm -q beta
33 git_commit $testroot/repo -m "removing beta on newbranch"
34 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
35 echo "new file on branch" > $testroot/repo/epsilon/new
36 git -C $testroot/repo add epsilon/new
37 git_commit $testroot/repo -m "adding new file on newbranch"
38 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
39 (cd $testroot/repo && ln -s alpha symlink)
40 git -C $testroot/repo add symlink
41 git_commit $testroot/repo -m "adding symlink on newbranch"
42 local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
43 (cd $testroot/repo && ln -sf .got/bar dotgotbar.link)
44 git -C $testroot/repo add dotgotbar.link
45 git_commit $testroot/repo -m "adding a bad symlink on newbranch"
46 local branch_commit5=`git_show_branch_head $testroot/repo newbranch`
48 got checkout -b master $testroot/repo $testroot/wt > /dev/null
49 ret=$?
50 if [ $ret -ne 0 ]; then
51 echo "got checkout failed unexpectedly" >&2
52 test_done "$testroot" "$ret"
53 return 1
54 fi
56 # create a divergent commit
57 git -C $testroot/repo checkout -q master
58 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
59 git_commit $testroot/repo -m "committing to zeta on master"
60 local master_commit=`git_show_head $testroot/repo`
62 # need an up-to-date work tree for 'got merge'
63 (cd $testroot/wt && got merge newbranch \
64 > $testroot/stdout 2> $testroot/stderr)
65 ret=$?
66 if [ $ret -eq 0 ]; then
67 echo "got merge succeeded unexpectedly" >&2
68 test_done "$testroot" "1"
69 return 1
70 fi
71 echo -n "got: work tree must be updated before it can be used " \
72 > $testroot/stderr.expected
73 echo "to merge a branch" >> $testroot/stderr.expected
74 cmp -s $testroot/stderr.expected $testroot/stderr
75 ret=$?
76 if [ $ret -ne 0 ]; then
77 diff -u $testroot/stderr.expected $testroot/stderr
78 test_done "$testroot" "$ret"
79 return 1
80 fi
82 (cd $testroot/wt && got update > /dev/null)
83 ret=$?
84 if [ $ret -ne 0 ]; then
85 echo "got update failed unexpectedly" >&2
86 test_done "$testroot" "$ret"
87 return 1
88 fi
90 # must not use a mixed-commit work tree with 'got merge'
91 (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
92 ret=$?
93 if [ $ret -ne 0 ]; then
94 echo "got update failed unexpectedly" >&2
95 test_done "$testroot" "$ret"
96 return 1
97 fi
98 (cd $testroot/wt && got merge newbranch \
99 > $testroot/stdout 2> $testroot/stderr)
100 ret=$?
101 if [ $ret -eq 0 ]; then
102 echo "got merge succeeded unexpectedly" >&2
103 test_done "$testroot" "1"
104 return 1
105 fi
106 echo -n "got: work tree contains files from multiple base commits; " \
107 > $testroot/stderr.expected
108 echo "the entire work tree must be updated first" \
109 >> $testroot/stderr.expected
110 cmp -s $testroot/stderr.expected $testroot/stderr
111 ret=$?
112 if [ $ret -ne 0 ]; then
113 diff -u $testroot/stderr.expected $testroot/stderr
114 test_done "$testroot" "$ret"
115 return 1
116 fi
118 (cd $testroot/wt && got update > /dev/null)
119 ret=$?
120 if [ $ret -ne 0 ]; then
121 echo "got update failed unexpectedly" >&2
122 test_done "$testroot" "$ret"
123 return 1
124 fi
126 # must not have staged files with 'got merge'
127 echo "modified file alpha" > $testroot/wt/alpha
128 (cd $testroot/wt && got stage alpha > /dev/null)
129 ret=$?
130 if [ $ret -ne 0 ]; then
131 echo "got stage failed unexpectedly" >&2
132 test_done "$testroot" "$ret"
133 return 1
134 fi
135 (cd $testroot/wt && got merge newbranch \
136 > $testroot/stdout 2> $testroot/stderr)
137 ret=$?
138 if [ $ret -eq 0 ]; then
139 echo "got merge succeeded unexpectedly" >&2
140 test_done "$testroot" "1"
141 return 1
142 fi
143 echo "got: alpha: file is staged" > $testroot/stderr.expected
144 cmp -s $testroot/stderr.expected $testroot/stderr
145 ret=$?
146 if [ $ret -ne 0 ]; then
147 diff -u $testroot/stderr.expected $testroot/stderr
148 test_done "$testroot" "$ret"
149 return 1
150 fi
151 (cd $testroot/wt && got unstage alpha > /dev/null)
152 ret=$?
153 if [ $ret -ne 0 ]; then
154 echo "got unstage failed unexpectedly" >&2
155 test_done "$testroot" "$ret"
156 return 1
157 fi
159 # must not have local changes with 'got merge'
160 (cd $testroot/wt && got merge newbranch \
161 > $testroot/stdout 2> $testroot/stderr)
162 ret=$?
163 if [ $ret -eq 0 ]; then
164 echo "got merge succeeded unexpectedly" >&2
165 test_done "$testroot" "1"
166 return 1
167 fi
168 echo -n "got: work tree contains local changes; " \
169 > $testroot/stderr.expected
170 echo "these changes must be committed or reverted first" \
171 >> $testroot/stderr.expected
172 cmp -s $testroot/stderr.expected $testroot/stderr
173 ret=$?
174 if [ $ret -ne 0 ]; then
175 diff -u $testroot/stderr.expected $testroot/stderr
176 test_done "$testroot" "$ret"
177 return 1
178 fi
180 (cd $testroot/wt && got revert alpha > /dev/null)
181 ret=$?
182 if [ $ret -ne 0 ]; then
183 echo "got revert failed unexpectedly" >&2
184 test_done "$testroot" "$ret"
185 return 1
186 fi
188 (cd $testroot/wt && got merge newbranch > $testroot/stdout)
189 ret=$?
190 if [ $ret -ne 0 ]; then
191 echo "got merge failed unexpectedly" >&2
192 test_done "$testroot" "$ret"
193 return 1
194 fi
196 local merge_commit=`git_show_head $testroot/repo`
198 echo "G alpha" >> $testroot/stdout.expected
199 echo "D beta" >> $testroot/stdout.expected
200 echo "A dotgotbar.link" >> $testroot/stdout.expected
201 echo "A epsilon/new" >> $testroot/stdout.expected
202 echo "G gamma/delta" >> $testroot/stdout.expected
203 echo "A symlink" >> $testroot/stdout.expected
204 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
205 >> $testroot/stdout.expected
206 echo $merge_commit >> $testroot/stdout.expected
208 cmp -s $testroot/stdout.expected $testroot/stdout
209 ret=$?
210 if [ $ret -ne 0 ]; then
211 diff -u $testroot/stdout.expected $testroot/stdout
212 test_done "$testroot" "$ret"
213 return 1
214 fi
216 echo "modified delta on branch" > $testroot/content.expected
217 cat $testroot/wt/gamma/delta > $testroot/content
218 cmp -s $testroot/content.expected $testroot/content
219 ret=$?
220 if [ $ret -ne 0 ]; then
221 diff -u $testroot/content.expected $testroot/content
222 test_done "$testroot" "$ret"
223 return 1
224 fi
226 echo "modified alpha on branch" > $testroot/content.expected
227 cat $testroot/wt/alpha > $testroot/content
228 cmp -s $testroot/content.expected $testroot/content
229 ret=$?
230 if [ $ret -ne 0 ]; then
231 diff -u $testroot/content.expected $testroot/content
232 test_done "$testroot" "$ret"
233 return 1
234 fi
236 if [ -e $testroot/wt/beta ]; then
237 echo "removed file beta still exists on disk" >&2
238 test_done "$testroot" "1"
239 return 1
240 fi
242 echo "new file on branch" > $testroot/content.expected
243 cat $testroot/wt/epsilon/new > $testroot/content
244 cmp -s $testroot/content.expected $testroot/content
245 ret=$?
246 if [ $ret -ne 0 ]; then
247 diff -u $testroot/content.expected $testroot/content
248 test_done "$testroot" "$ret"
249 return 1
250 fi
252 if [ ! -h $testroot/wt/dotgotbar.link ]; then
253 echo "dotgotbar.link is not a symlink"
254 test_done "$testroot" "1"
255 return 1
256 fi
258 readlink $testroot/wt/symlink > $testroot/stdout
259 echo "alpha" > $testroot/stdout.expected
260 cmp -s $testroot/stdout.expected $testroot/stdout
261 ret=$?
262 if [ $ret -ne 0 ]; then
263 diff -u $testroot/stdout.expected $testroot/stdout
264 test_done "$testroot" "$ret"
265 return 1
266 fi
268 (cd $testroot/wt && got status > $testroot/stdout)
270 echo -n > $testroot/stdout.expected
271 cmp -s $testroot/stdout.expected $testroot/stdout
272 ret=$?
273 if [ $ret -ne 0 ]; then
274 diff -u $testroot/stdout.expected $testroot/stdout
275 test_done "$testroot" "$ret"
276 return 1
277 fi
279 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
280 echo "commit $merge_commit (master)" > $testroot/stdout.expected
281 echo "commit $master_commit" >> $testroot/stdout.expected
282 echo "commit $commit0" >> $testroot/stdout.expected
283 cmp -s $testroot/stdout.expected $testroot/stdout
284 ret=$?
285 if [ $ret -ne 0 ]; then
286 diff -u $testroot/stdout.expected $testroot/stdout
287 test_done "$testroot" "$ret"
288 return 1
289 fi
291 (cd $testroot/wt && got update > $testroot/stdout)
293 echo 'U dotgotbar.link' > $testroot/stdout.expected
294 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
295 git_show_head $testroot/repo >> $testroot/stdout.expected
296 echo >> $testroot/stdout.expected
297 cmp -s $testroot/stdout.expected $testroot/stdout
298 ret=$?
299 if [ $ret -ne 0 ]; then
300 diff -u $testroot/stdout.expected $testroot/stdout
301 test_done "$testroot" "$ret"
302 return 1
303 fi
305 # update has changed the bad symlink into a regular file
306 if [ -h $testroot/wt/dotgotbar.link ]; then
307 echo "dotgotbar.link is a symlink"
308 test_done "$testroot" "1"
309 return 1
310 fi
312 # We should have created a merge commit with two parents.
313 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
314 echo "parent 1: $master_commit" > $testroot/stdout.expected
315 echo "parent 2: $branch_commit5" >> $testroot/stdout.expected
316 cmp -s $testroot/stdout.expected $testroot/stdout
317 ret=$?
318 if [ $ret -ne 0 ]; then
319 diff -u $testroot/stdout.expected $testroot/stdout
320 test_done "$testroot" "$ret"
321 return 1
322 fi
324 got tree -r $testroot/repo -c $merge_commit -R > $testroot/stdout
325 ret=$?
326 if [ $ret -ne 0 ]; then
327 echo "got tree failed unexpectedly" >&2
328 test_done "$testroot" "$ret"
329 return 1
330 fi
332 # bad symlink dotgotbar.link appears as a symlink in the merge commit:
333 cat > $testroot/stdout.expected <<EOF
334 alpha
335 dotgotbar.link@ -> .got/bar
336 epsilon/
337 epsilon/new
338 epsilon/zeta
339 gamma/
340 gamma/delta
341 symlink@ -> alpha
342 EOF
343 cmp -s $testroot/stdout.expected $testroot/stdout
344 ret=$?
345 if [ $ret -ne 0 ]; then
346 diff -u $testroot/stdout.expected $testroot/stdout
347 fi
348 test_done "$testroot" "$ret"
351 test_merge_forward() {
352 local testroot=`test_init merge_forward`
353 local commit0=`git_show_head $testroot/repo`
355 # Create a commit before branching, which will be used to help test
356 # preconditions for "got merge".
357 echo "modified alpha" > $testroot/repo/alpha
358 git_commit $testroot/repo -m "common commit"
359 local commit1=`git_show_head $testroot/repo`
361 git -C $testroot/repo checkout -q -b newbranch
362 echo "modified beta on branch" > $testroot/repo/beta
363 git_commit $testroot/repo -m "committing to beta on newbranch"
364 local commit2=`git_show_head $testroot/repo`
366 got checkout -b master $testroot/repo $testroot/wt > /dev/null
367 ret=$?
368 if [ $ret -ne 0 ]; then
369 echo "got checkout failed unexpectedly" >&2
370 test_done "$testroot" "$ret"
371 return 1
372 fi
374 # must not use a mixed-commit work tree with 'got merge'
375 (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
376 ret=$?
377 if [ $ret -ne 0 ]; then
378 echo "got update failed unexpectedly" >&2
379 test_done "$testroot" "$ret"
380 return 1
381 fi
382 (cd $testroot/wt && got merge newbranch \
383 > $testroot/stdout 2> $testroot/stderr)
384 ret=$?
385 if [ $ret -eq 0 ]; then
386 echo "got merge succeeded unexpectedly" >&2
387 test_done "$testroot" "$ret"
388 return 1
389 fi
390 echo -n "got: work tree contains files from multiple base commits; " \
391 > $testroot/stderr.expected
392 echo "the entire work tree must be updated first" \
393 >> $testroot/stderr.expected
394 cmp -s $testroot/stderr.expected $testroot/stderr
395 ret=$?
396 if [ $ret -ne 0 ]; then
397 diff -u $testroot/stderr.expected $testroot/stderr
398 test_done "$testroot" "$ret"
399 return 1
400 fi
402 (cd $testroot/wt && got update > /dev/null)
403 ret=$?
404 if [ $ret -ne 0 ]; then
405 echo "got update failed unexpectedly" >&2
406 test_done "$testroot" "$ret"
407 return 1
408 fi
410 # 'got merge -n' refuses to fast-forward
411 (cd $testroot/wt && got merge -n newbranch \
412 > $testroot/stdout 2> $testroot/stderr)
413 ret=$?
414 if [ $ret -eq 0 ]; then
415 echo "got merge succeeded unexpectedly" >&2
416 test_done "$testroot" "1"
417 return 1
418 fi
420 echo -n "got: there are no changes to merge since " \
421 > $testroot/stderr.expected
422 echo -n "refs/heads/newbranch is already based on " \
423 >> $testroot/stderr.expected
424 echo -n "refs/heads/master; merge cannot be interrupted " \
425 >> $testroot/stderr.expected
426 echo "for amending; -n: option cannot be used" \
427 >> $testroot/stderr.expected
429 cmp -s $testroot/stderr.expected $testroot/stderr
430 ret=$?
431 if [ $ret -ne 0 ]; then
432 diff -u $testroot/stderr.expected $testroot/stderr
433 test_done "$testroot" "$ret"
434 return 1
435 fi
437 (cd $testroot/wt && got merge newbranch \
438 > $testroot/stdout 2> $testroot/stderr)
439 ret=$?
440 if [ $ret -ne 0 ]; then
441 echo "got merge failed unexpectedly" >&2
442 test_done "$testroot" "$ret"
443 return 1
444 fi
446 echo "Forwarding refs/heads/master to refs/heads/newbranch" \
447 > $testroot/stdout.expected
448 echo "U beta" >> $testroot/stdout.expected
449 echo "Updated to commit $commit2" \
450 >> $testroot/stdout.expected
451 cmp -s $testroot/stdout.expected $testroot/stdout
452 ret=$?
453 if [ $ret -ne 0 ]; then
454 diff -u $testroot/stdout.expected $testroot/stdout
455 test_done "$testroot" "$ret"
456 return 1
457 fi
459 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
460 echo -n "commit $commit2 " > $testroot/stdout.expected
461 echo "(master, newbranch)" >> $testroot/stdout.expected
462 echo "commit $commit1" >> $testroot/stdout.expected
463 echo "commit $commit0" >> $testroot/stdout.expected
464 cmp -s $testroot/stdout.expected $testroot/stdout
465 ret=$?
466 if [ $ret -ne 0 ]; then
467 diff -u $testroot/stdout.expected $testroot/stdout
468 test_done "$testroot" "$ret"
469 return 1
470 fi
471 test_done "$testroot" "$ret"
474 test_merge_forward_commit() {
475 local testroot=`test_init merge_forward_commit`
476 local commit0=`git_show_head $testroot/repo`
478 git -C $testroot/repo checkout -q -b newbranch
479 echo "modified alpha on branch" > $testroot/repo/alpha
480 git_commit $testroot/repo -m "committing to alpha on newbranch"
481 local commit1=`git_show_head $testroot/repo`
483 got checkout -b master $testroot/repo $testroot/wt > /dev/null
484 ret=$?
485 if [ $ret -ne 0 ]; then
486 echo "got checkout failed unexpectedly" >&2
487 test_done "$testroot" "$ret"
488 return 1
489 fi
491 (cd $testroot/wt && got merge -M newbranch > $testroot/stdout)
492 ret=$?
493 if [ $ret -ne 0 ]; then
494 echo "got merge failed unexpectedly" >&2
495 test_done "$testroot" "$ret"
496 return 1
497 fi
499 local merge_commit=`git_show_branch_head $testroot/repo master`
501 echo "G alpha" >> $testroot/stdout.expected
502 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
503 >> $testroot/stdout.expected
504 echo $merge_commit >> $testroot/stdout.expected
506 cmp -s $testroot/stdout.expected $testroot/stdout
507 ret=$?
508 if [ $ret -ne 0 ]; then
509 diff -u $testroot/stdout.expected $testroot/stdout
510 test_done "$testroot" "$ret"
511 return 1
512 fi
514 # We should have created a merge commit with two parents.
515 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
516 echo "parent 1: $commit0" > $testroot/stdout.expected
517 echo "parent 2: $commit1" >> $testroot/stdout.expected
518 cmp -s $testroot/stdout.expected $testroot/stdout
519 ret=$?
520 if [ $ret -ne 0 ]; then
521 diff -u $testroot/stdout.expected $testroot/stdout
522 test_done "$testroot" "$ret"
523 return 1
524 fi
526 test_done "$testroot" "$ret"
529 test_merge_forward_interrupt() {
530 # Test -M and -n options together.
531 local testroot=`test_init merge_forward_commit`
532 local commit0=`git_show_head $testroot/repo`
534 git -C $testroot/repo checkout -q -b newbranch
535 echo "modified alpha on branch" > $testroot/repo/alpha
536 git_commit $testroot/repo -m "committing to alpha on newbranch"
537 local commit1=`git_show_head $testroot/repo`
539 got checkout -b master $testroot/repo $testroot/wt > /dev/null
540 ret=$?
541 if [ $ret -ne 0 ]; then
542 echo "got checkout failed unexpectedly" >&2
543 test_done "$testroot" "$ret"
544 return 1
545 fi
547 (cd $testroot/wt && got merge -M -n newbranch > $testroot/stdout)
548 ret=$?
549 if [ $ret -ne 0 ]; then
550 echo "got merge failed unexpectedly" >&2
551 test_done "$testroot" "$ret"
552 return 1
553 fi
555 echo "G alpha" > $testroot/stdout.expected
556 echo "Merge of refs/heads/newbranch interrupted on request" \
557 >> $testroot/stdout.expected
558 cmp -s $testroot/stdout.expected $testroot/stdout
559 ret=$?
560 if [ $ret -ne 0 ]; then
561 diff -u $testroot/stdout.expected $testroot/stdout
562 test_done "$testroot" "$ret"
563 return 1
564 fi
566 # Continue the merge.
567 (cd $testroot/wt && got merge -c > $testroot/stdout)
568 ret=$?
569 if [ $ret -ne 0 ]; then
570 echo "got merge failed unexpectedly" >&2
571 test_done "$testroot" "$ret"
572 return 1
573 fi
575 local merge_commit=`git_show_branch_head $testroot/repo master`
577 echo "M alpha" > $testroot/stdout.expected
578 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
579 >> $testroot/stdout.expected
580 echo $merge_commit >> $testroot/stdout.expected
582 cmp -s $testroot/stdout.expected $testroot/stdout
583 ret=$?
584 if [ $ret -ne 0 ]; then
585 diff -u $testroot/stdout.expected $testroot/stdout
586 test_done "$testroot" "$ret"
587 return 1
588 fi
590 # We should have created a merge commit with two parents.
591 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
592 echo "parent 1: $commit0" > $testroot/stdout.expected
593 echo "parent 2: $commit1" >> $testroot/stdout.expected
594 cmp -s $testroot/stdout.expected $testroot/stdout
595 ret=$?
596 if [ $ret -ne 0 ]; then
597 diff -u $testroot/stdout.expected $testroot/stdout
598 fi
599 test_done "$testroot" "$ret"
602 test_merge_backward() {
603 local testroot=`test_init merge_backward`
604 local commit0=`git_show_head $testroot/repo`
606 git -C $testroot/repo checkout -q -b newbranch
607 git -C $testroot/repo checkout -q master
608 echo "modified alpha on master" > $testroot/repo/alpha
609 git_commit $testroot/repo -m "committing to alpha on master"
611 got checkout -b master $testroot/repo $testroot/wt > /dev/null
612 ret=$?
613 if [ $ret -ne 0 ]; then
614 echo "got checkout failed unexpectedly" >&2
615 test_done "$testroot" "$ret"
616 return 1
617 fi
619 (cd $testroot/wt && got merge newbranch \
620 > $testroot/stdout 2> $testroot/stderr)
621 ret=$?
622 if [ $ret -ne 0 ]; then
623 echo "got merge failed unexpectedly" >&2
624 test_done "$testroot" "$ret"
625 return 1
626 fi
627 echo "Already up-to-date" > $testroot/stdout.expected
628 cmp -s $testroot/stdout.expected $testroot/stdout
629 ret=$?
630 if [ $ret -ne 0 ]; then
631 diff -u $testroot/stdout.expected $testroot/stdout
632 test_done "$testroot" "$ret"
633 return 1
634 fi
635 test_done "$testroot" "$ret"
638 test_merge_continue() {
639 local testroot=`test_init merge_continue`
640 local commit0=`git_show_head $testroot/repo`
641 local commit0_author_time=`git_show_author_time $testroot/repo`
643 git -C $testroot/repo checkout -q -b newbranch
644 echo "modified delta on branch" > $testroot/repo/gamma/delta
645 git_commit $testroot/repo -m "committing to delta on newbranch"
646 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
648 echo "modified alpha on branch" > $testroot/repo/alpha
649 git_commit $testroot/repo -m "committing to alpha on newbranch"
650 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
651 git -C $testroot/repo rm -q beta
652 git_commit $testroot/repo -m "removing beta on newbranch"
653 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
654 echo "new file on branch" > $testroot/repo/epsilon/new
655 git -C $testroot/repo add epsilon/new
656 git_commit $testroot/repo -m "adding new file on newbranch"
657 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
659 got checkout -b master $testroot/repo $testroot/wt > /dev/null
660 ret=$?
661 if [ $ret -ne 0 ]; then
662 echo "got checkout failed unexpectedly" >&2
663 test_done "$testroot" "$ret"
664 return 1
665 fi
667 # create a conflicting commit
668 git -C $testroot/repo checkout -q master
669 echo "modified alpha on master" > $testroot/repo/alpha
670 git_commit $testroot/repo -m "committing to alpha on master"
671 local master_commit=`git_show_head $testroot/repo`
673 # need an up-to-date work tree for 'got merge'
674 (cd $testroot/wt && got update > /dev/null)
675 ret=$?
676 if [ $ret -ne 0 ]; then
677 echo "got update failed unexpectedly" >&2
678 test_done "$testroot" "$ret"
679 return 1
680 fi
682 (cd $testroot/wt && got merge newbranch \
683 > $testroot/stdout 2> $testroot/stderr)
684 ret=$?
685 if [ $ret -eq 0 ]; then
686 echo "got merge succeeded unexpectedly" >&2
687 test_done "$testroot" "1"
688 return 1
689 fi
691 echo "C alpha" >> $testroot/stdout.expected
692 echo "D beta" >> $testroot/stdout.expected
693 echo "A epsilon/new" >> $testroot/stdout.expected
694 echo "G gamma/delta" >> $testroot/stdout.expected
695 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
696 cmp -s $testroot/stdout.expected $testroot/stdout
697 ret=$?
698 if [ $ret -ne 0 ]; then
699 diff -u $testroot/stdout.expected $testroot/stdout
700 test_done "$testroot" "$ret"
701 return 1
702 fi
704 echo "got: conflicts must be resolved before merging can continue" \
705 > $testroot/stderr.expected
706 cmp -s $testroot/stderr.expected $testroot/stderr
707 ret=$?
708 if [ $ret -ne 0 ]; then
709 diff -u $testroot/stderr.expected $testroot/stderr
710 test_done "$testroot" "$ret"
711 return 1
712 fi
714 (cd $testroot/wt && got status > $testroot/stdout)
716 cat > $testroot/stdout.expected <<EOF
717 C alpha
718 D beta
719 A epsilon/new
720 M gamma/delta
721 Work tree is merging refs/heads/newbranch into refs/heads/master
722 EOF
723 cmp -s $testroot/stdout.expected $testroot/stdout
724 ret=$?
725 if [ $ret -ne 0 ]; then
726 diff -u $testroot/stdout.expected $testroot/stdout
727 test_done "$testroot" "$ret"
728 return 1
729 fi
731 echo '<<<<<<<' > $testroot/content.expected
732 echo "modified alpha on master" >> $testroot/content.expected
733 echo "||||||| 3-way merge base: commit $commit0" \
734 >> $testroot/content.expected
735 echo "alpha" >> $testroot/content.expected
736 echo "=======" >> $testroot/content.expected
737 echo "modified alpha on branch" >> $testroot/content.expected
738 echo ">>>>>>> merged change: commit $branch_commit3" \
739 >> $testroot/content.expected
740 cat $testroot/wt/alpha > $testroot/content
741 cmp -s $testroot/content.expected $testroot/content
742 ret=$?
743 if [ $ret -ne 0 ]; then
744 diff -u $testroot/content.expected $testroot/content
745 test_done "$testroot" "$ret"
746 return 1
747 fi
749 # resolve the conflict
750 echo "modified alpha by both branches" > $testroot/wt/alpha
752 (cd $testroot/wt && got merge -c > $testroot/stdout)
753 ret=$?
754 if [ $ret -ne 0 ]; then
755 echo "got merge failed unexpectedly" >&2
756 test_done "$testroot" "$ret"
757 return 1
758 fi
760 local merge_commit=`git_show_head $testroot/repo`
762 echo "M alpha" > $testroot/stdout.expected
763 echo "D beta" >> $testroot/stdout.expected
764 echo "A epsilon/new" >> $testroot/stdout.expected
765 echo "M gamma/delta" >> $testroot/stdout.expected
766 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
767 >> $testroot/stdout.expected
768 echo $merge_commit >> $testroot/stdout.expected
770 cmp -s $testroot/stdout.expected $testroot/stdout
771 ret=$?
772 if [ $ret -ne 0 ]; then
773 diff -u $testroot/stdout.expected $testroot/stdout
774 test_done "$testroot" "$ret"
775 return 1
776 fi
778 echo "modified delta on branch" > $testroot/content.expected
779 cat $testroot/wt/gamma/delta > $testroot/content
780 cmp -s $testroot/content.expected $testroot/content
781 ret=$?
782 if [ $ret -ne 0 ]; then
783 diff -u $testroot/content.expected $testroot/content
784 test_done "$testroot" "$ret"
785 return 1
786 fi
788 echo "modified alpha by both branches" > $testroot/content.expected
789 cat $testroot/wt/alpha > $testroot/content
790 cmp -s $testroot/content.expected $testroot/content
791 ret=$?
792 if [ $ret -ne 0 ]; then
793 diff -u $testroot/content.expected $testroot/content
794 test_done "$testroot" "$ret"
795 return 1
796 fi
798 if [ -e $testroot/wt/beta ]; then
799 echo "removed file beta still exists on disk" >&2
800 test_done "$testroot" "1"
801 return 1
802 fi
804 echo "new file on branch" > $testroot/content.expected
805 cat $testroot/wt/epsilon/new > $testroot/content
806 cmp -s $testroot/content.expected $testroot/content
807 ret=$?
808 if [ $ret -ne 0 ]; then
809 diff -u $testroot/content.expected $testroot/content
810 test_done "$testroot" "$ret"
811 return 1
812 fi
814 (cd $testroot/wt && got status > $testroot/stdout)
816 echo -n > $testroot/stdout.expected
817 cmp -s $testroot/stdout.expected $testroot/stdout
818 ret=$?
819 if [ $ret -ne 0 ]; then
820 diff -u $testroot/stdout.expected $testroot/stdout
821 test_done "$testroot" "$ret"
822 return 1
823 fi
825 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
826 echo "commit $merge_commit (master)" > $testroot/stdout.expected
827 echo "commit $master_commit" >> $testroot/stdout.expected
828 echo "commit $commit0" >> $testroot/stdout.expected
829 cmp -s $testroot/stdout.expected $testroot/stdout
830 ret=$?
831 if [ $ret -ne 0 ]; then
832 diff -u $testroot/stdout.expected $testroot/stdout
833 test_done "$testroot" "$ret"
834 return 1
835 fi
837 (cd $testroot/wt && got update > $testroot/stdout)
839 echo 'Already up-to-date' > $testroot/stdout.expected
840 cmp -s $testroot/stdout.expected $testroot/stdout
841 ret=$?
842 if [ $ret -ne 0 ]; then
843 diff -u $testroot/stdout.expected $testroot/stdout
844 test_done "$testroot" "$ret"
845 return 1
846 fi
848 # We should have created a merge commit with two parents.
849 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
850 echo "parent 1: $master_commit" > $testroot/stdout.expected
851 echo "parent 2: $branch_commit3" >> $testroot/stdout.expected
852 cmp -s $testroot/stdout.expected $testroot/stdout
853 ret=$?
854 if [ $ret -ne 0 ]; then
855 diff -u $testroot/stdout.expected $testroot/stdout
856 fi
857 test_done "$testroot" "$ret"
860 test_merge_continue_new_commit() {
861 # "got merge -c" should refuse to run if the current branch tip has
862 # changed since the merge was started, to avoid clobbering the changes.
863 local testroot=`test_init merge_continue_new_commit`
865 git -C $testroot/repo checkout -q -b newbranch
866 echo "modified delta on branch" > $testroot/repo/gamma/delta
867 git_commit $testroot/repo -m "committing to delta on newbranch"
869 git -C $testroot/repo checkout -q master
870 echo "modified alpha on master" > $testroot/repo/alpha
871 git_commit $testroot/repo -m "committing to alpha on master"
873 got checkout -b master $testroot/repo $testroot/wt > /dev/null
874 ret=$?
875 if [ $ret -ne 0 ]; then
876 echo "got checkout failed unexpectedly" >&2
877 test_done "$testroot" "$ret"
878 return 1
879 fi
881 (cd $testroot/wt && got merge -n newbranch >/dev/null)
882 ret=$?
883 if [ $ret -ne 0 ]; then
884 echo "got merge failed unexpectedly" >&2
885 test_done "$testroot" "$ret"
886 return 1
887 fi
889 echo "modified alpha again on master" > $testroot/repo/alpha
890 git_commit $testroot/repo -m "committing to alpha on master again"
892 (cd $testroot/wt && got merge -c > $testroot/stdout 2> $testroot/stderr)
893 ret=$?
894 if [ $ret -eq 0 ]; then
895 echo "got merge succeeded unexpectedly" >&2
896 test_done "$testroot" "1"
897 return 1
898 fi
900 echo -n > $testroot/stdout.expected
901 cmp -s $testroot/stdout.expected $testroot/stdout
902 ret=$?
903 if [ $ret -ne 0 ]; then
904 diff -u $testroot/stdout.expected $testroot/stdout
905 test_done "$testroot" "$ret"
906 return 1
907 fi
909 echo -n "got: merging cannot proceed because the work tree is no " \
910 > $testroot/stderr.expected
911 echo "longer up-to-date; merge must be aborted and retried" \
912 >> $testroot/stderr.expected
913 cmp -s $testroot/stderr.expected $testroot/stderr
914 ret=$?
915 if [ $ret -ne 0 ]; then
916 diff -u $testroot/stderr.expected $testroot/stderr
917 fi
918 test_done "$testroot" "$ret"
921 test_merge_abort() {
922 local testroot=`test_init merge_abort`
923 local commit0=`git_show_head $testroot/repo`
924 local commit0_author_time=`git_show_author_time $testroot/repo`
926 git -C $testroot/repo checkout -q -b newbranch
927 echo "modified delta on branch" > $testroot/repo/gamma/delta
928 git_commit $testroot/repo -m "committing to delta on newbranch"
929 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
931 echo "modified alpha on branch" > $testroot/repo/alpha
932 git_commit $testroot/repo -m "committing to alpha on newbranch"
933 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
934 git -C $testroot/repo rm -q beta
935 git_commit $testroot/repo -m "removing beta on newbranch"
936 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
937 echo "new file on branch" > $testroot/repo/epsilon/new
938 git -C $testroot/repo add epsilon/new
939 git_commit $testroot/repo -m "adding new file on newbranch"
940 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
941 (cd $testroot/repo && ln -s alpha symlink)
942 git -C $testroot/repo add symlink
943 git_commit $testroot/repo -m "adding symlink on newbranch"
944 local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
946 got checkout -b master $testroot/repo $testroot/wt > /dev/null
947 ret=$?
948 if [ $ret -ne 0 ]; then
949 echo "got checkout failed unexpectedly" >&2
950 test_done "$testroot" "$ret"
951 return 1
952 fi
954 # unrelated unversioned file in work tree
955 touch $testroot/wt/unversioned-file
957 # create a conflicting commit
958 git -C $testroot/repo checkout -q master
959 echo "modified alpha on master" > $testroot/repo/alpha
960 git_commit $testroot/repo -m "committing to alpha on master"
961 local master_commit=`git_show_head $testroot/repo`
963 # need an up-to-date work tree for 'got merge'
964 (cd $testroot/wt && got update > /dev/null)
965 ret=$?
966 if [ $ret -ne 0 ]; then
967 echo "got update failed unexpectedly" >&2
968 test_done "$testroot" "$ret"
969 return 1
970 fi
972 (cd $testroot/wt && got merge newbranch \
973 > $testroot/stdout 2> $testroot/stderr)
974 ret=$?
975 if [ $ret -eq 0 ]; then
976 echo "got merge succeeded unexpectedly" >&2
977 test_done "$testroot" "1"
978 return 1
979 fi
981 echo "C alpha" >> $testroot/stdout.expected
982 echo "D beta" >> $testroot/stdout.expected
983 echo "A epsilon/new" >> $testroot/stdout.expected
984 echo "G gamma/delta" >> $testroot/stdout.expected
985 echo "A symlink" >> $testroot/stdout.expected
986 echo "Files with new merge conflicts: 1" >> $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 test_done "$testroot" "$ret"
992 return 1
993 fi
995 echo "got: conflicts must be resolved before merging can continue" \
996 > $testroot/stderr.expected
997 cmp -s $testroot/stderr.expected $testroot/stderr
998 ret=$?
999 if [ $ret -ne 0 ]; then
1000 diff -u $testroot/stderr.expected $testroot/stderr
1001 test_done "$testroot" "$ret"
1002 return 1
1005 # unrelated added file added during conflict resolution
1006 touch $testroot/wt/added-file
1007 (cd $testroot/wt && got add added-file > /dev/null)
1009 (cd $testroot/wt && got status > $testroot/stdout)
1011 cat > $testroot/stdout.expected <<EOF
1012 A added-file
1013 C alpha
1014 D beta
1015 A epsilon/new
1016 M gamma/delta
1017 A symlink
1018 ? unversioned-file
1019 Work tree is merging refs/heads/newbranch into refs/heads/master
1020 EOF
1021 cmp -s $testroot/stdout.expected $testroot/stdout
1022 ret=$?
1023 if [ $ret -ne 0 ]; then
1024 diff -u $testroot/stdout.expected $testroot/stdout
1025 test_done "$testroot" "$ret"
1026 return 1
1029 (cd $testroot/wt && got merge -a > $testroot/stdout)
1030 ret=$?
1031 if [ $ret -ne 0 ]; then
1032 echo "got merge failed unexpectedly" >&2
1033 test_done "$testroot" "$ret"
1034 return 1
1037 echo "R added-file" > $testroot/stdout.expected
1038 echo "R alpha" >> $testroot/stdout.expected
1039 echo "R beta" >> $testroot/stdout.expected
1040 echo "R epsilon/new" >> $testroot/stdout.expected
1041 echo "R gamma/delta" >> $testroot/stdout.expected
1042 echo "R symlink" >> $testroot/stdout.expected
1043 echo "G added-file" >> $testroot/stdout.expected
1044 echo "Merge of refs/heads/newbranch aborted" \
1045 >> $testroot/stdout.expected
1047 cmp -s $testroot/stdout.expected $testroot/stdout
1048 ret=$?
1049 if [ $ret -ne 0 ]; then
1050 diff -u $testroot/stdout.expected $testroot/stdout
1051 test_done "$testroot" "$ret"
1052 return 1
1055 echo "delta" > $testroot/content.expected
1056 cat $testroot/wt/gamma/delta > $testroot/content
1057 cmp -s $testroot/content.expected $testroot/content
1058 ret=$?
1059 if [ $ret -ne 0 ]; then
1060 diff -u $testroot/content.expected $testroot/content
1061 test_done "$testroot" "$ret"
1062 return 1
1065 echo "modified alpha on master" > $testroot/content.expected
1066 cat $testroot/wt/alpha > $testroot/content
1067 cmp -s $testroot/content.expected $testroot/content
1068 ret=$?
1069 if [ $ret -ne 0 ]; then
1070 diff -u $testroot/content.expected $testroot/content
1071 test_done "$testroot" "$ret"
1072 return 1
1075 echo "beta" > $testroot/content.expected
1076 cat $testroot/wt/beta > $testroot/content
1077 cmp -s $testroot/content.expected $testroot/content
1078 ret=$?
1079 if [ $ret -ne 0 ]; then
1080 diff -u $testroot/content.expected $testroot/content
1081 test_done "$testroot" "$ret"
1082 return 1
1085 if [ -e $testroot/wt/epsilon/new ]; then
1086 echo "reverted file epsilon/new still exists on disk" >&2
1087 test_done "$testroot" "1"
1088 return 1
1091 if [ -e $testroot/wt/symlink ]; then
1092 echo "reverted symlink still exists on disk" >&2
1093 test_done "$testroot" "1"
1094 return 1
1097 (cd $testroot/wt && got status > $testroot/stdout)
1099 echo "? added-file" > $testroot/stdout.expected
1100 echo "? unversioned-file" >> $testroot/stdout.expected
1101 cmp -s $testroot/stdout.expected $testroot/stdout
1102 ret=$?
1103 if [ $ret -ne 0 ]; then
1104 diff -u $testroot/stdout.expected $testroot/stdout
1105 test_done "$testroot" "$ret"
1106 return 1
1109 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1110 echo "commit $master_commit (master)" > $testroot/stdout.expected
1111 echo "commit $commit0" >> $testroot/stdout.expected
1112 cmp -s $testroot/stdout.expected $testroot/stdout
1113 ret=$?
1114 if [ $ret -ne 0 ]; then
1115 diff -u $testroot/stdout.expected $testroot/stdout
1116 test_done "$testroot" "$ret"
1117 return 1
1120 (cd $testroot/wt && got update > $testroot/stdout)
1122 echo 'Already up-to-date' > $testroot/stdout.expected
1123 cmp -s $testroot/stdout.expected $testroot/stdout
1124 ret=$?
1125 if [ $ret -ne 0 ]; then
1126 diff -u $testroot/stdout.expected $testroot/stdout
1128 test_done "$testroot" "$ret"
1131 test_merge_in_progress() {
1132 local testroot=`test_init merge_in_progress`
1133 local commit0=`git_show_head $testroot/repo`
1134 local commit0_author_time=`git_show_author_time $testroot/repo`
1136 git -C $testroot/repo checkout -q -b newbranch
1137 echo "modified alpha on branch" > $testroot/repo/alpha
1138 git_commit $testroot/repo -m "committing to alpha on newbranch"
1139 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1141 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1142 ret=$?
1143 if [ $ret -ne 0 ]; then
1144 echo "got checkout failed unexpectedly" >&2
1145 test_done "$testroot" "$ret"
1146 return 1
1149 # create a conflicting commit
1150 git -C $testroot/repo checkout -q master
1151 echo "modified alpha on master" > $testroot/repo/alpha
1152 git_commit $testroot/repo -m "committing to alpha on master"
1153 local master_commit=`git_show_head $testroot/repo`
1155 # need an up-to-date work tree for 'got merge'
1156 (cd $testroot/wt && got update > /dev/null)
1157 ret=$?
1158 if [ $ret -ne 0 ]; then
1159 echo "got update failed unexpectedly" >&2
1160 test_done "$testroot" "$ret"
1161 return 1
1164 (cd $testroot/wt && got merge newbranch \
1165 > $testroot/stdout 2> $testroot/stderr)
1166 ret=$?
1167 if [ $ret -eq 0 ]; then
1168 echo "got merge succeeded unexpectedly" >&2
1169 test_done "$testroot" "1"
1170 return 1
1173 echo "C alpha" >> $testroot/stdout.expected
1174 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1175 cmp -s $testroot/stdout.expected $testroot/stdout
1176 ret=$?
1177 if [ $ret -ne 0 ]; then
1178 diff -u $testroot/stdout.expected $testroot/stdout
1179 test_done "$testroot" "$ret"
1180 return 1
1183 echo "got: conflicts must be resolved before merging can continue" \
1184 > $testroot/stderr.expected
1185 cmp -s $testroot/stderr.expected $testroot/stderr
1186 ret=$?
1187 if [ $ret -ne 0 ]; then
1188 diff -u $testroot/stderr.expected $testroot/stderr
1189 test_done "$testroot" "$ret"
1190 return 1
1193 (cd $testroot/wt && got status > $testroot/stdout)
1195 cat > $testroot/stdout.expected <<EOF
1196 C alpha
1197 Work tree is merging refs/heads/newbranch into refs/heads/master
1198 EOF
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 for cmd in update commit histedit "rebase newbranch" \
1208 "integrate newbranch" "merge newbranch" "stage alpha"; do
1209 (cd $testroot/wt && got $cmd > $testroot/stdout \
1210 2> $testroot/stderr)
1211 ret=$?
1212 if [ $ret -eq 0 ]; then
1213 echo "got $cmd succeeded unexpectedly" >&2
1214 test_done "$testroot" "1"
1215 return 1
1218 echo -n > $testroot/stdout.expected
1219 cmp -s $testroot/stdout.expected $testroot/stdout
1220 ret=$?
1221 if [ $ret -ne 0 ]; then
1222 diff -u $testroot/stdout.expected $testroot/stdout
1223 test_done "$testroot" "$ret"
1224 return 1
1227 echo -n "got: a merge operation is in progress in this " \
1228 > $testroot/stderr.expected
1229 echo "work tree and must be continued or aborted first" \
1230 >> $testroot/stderr.expected
1231 cmp -s $testroot/stderr.expected $testroot/stderr
1232 ret=$?
1233 if [ $ret -ne 0 ]; then
1234 diff -u $testroot/stderr.expected $testroot/stderr
1235 test_done "$testroot" "$ret"
1236 return 1
1238 done
1240 test_done "$testroot" "$ret"
1243 test_merge_path_prefix() {
1244 local testroot=`test_init merge_path_prefix`
1245 local commit0=`git_show_head $testroot/repo`
1246 local commit0_author_time=`git_show_author_time $testroot/repo`
1248 git -C $testroot/repo checkout -q -b newbranch
1249 echo "modified alpha on branch" > $testroot/repo/alpha
1250 git_commit $testroot/repo -m "committing to alpha on newbranch"
1251 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1253 got checkout -p epsilon -b master $testroot/repo $testroot/wt \
1254 > /dev/null
1255 ret=$?
1256 if [ $ret -ne 0 ]; then
1257 echo "got checkout failed unexpectedly" >&2
1258 test_done "$testroot" "$ret"
1259 return 1
1262 # create a conflicting commit
1263 git -C $testroot/repo checkout -q master
1264 echo "modified alpha on master" > $testroot/repo/alpha
1265 git_commit $testroot/repo -m "committing to alpha on master"
1266 local master_commit=`git_show_head $testroot/repo`
1268 # need an up-to-date work tree for 'got merge'
1269 (cd $testroot/wt && got update > /dev/null)
1270 ret=$?
1271 if [ $ret -ne 0 ]; then
1272 echo "got update failed unexpectedly" >&2
1273 test_done "$testroot" "$ret"
1274 return 1
1277 (cd $testroot/wt && got merge newbranch \
1278 > $testroot/stdout 2> $testroot/stderr)
1279 ret=$?
1280 if [ $ret -eq 0 ]; then
1281 echo "got merge succeeded unexpectedly" >&2
1282 test_done "$testroot" "1"
1283 return 1
1286 echo -n "got: cannot merge branch which contains changes outside " \
1287 > $testroot/stderr.expected
1288 echo "of this work tree's path prefix" >> $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
1294 test_done "$testroot" "$ret"
1297 test_merge_missing_file() {
1298 local testroot=`test_init merge_missing_file`
1299 local commit0=`git_show_head $testroot/repo`
1300 local commit0_author_time=`git_show_author_time $testroot/repo`
1302 git -C $testroot/repo checkout -q -b newbranch
1303 echo "modified alpha on branch" > $testroot/repo/alpha
1304 echo "modified delta on branch" > $testroot/repo/gamma/delta
1305 git_commit $testroot/repo -m "committing to alpha and delta"
1306 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1308 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1309 ret=$?
1310 if [ $ret -ne 0 ]; then
1311 echo "got checkout failed unexpectedly" >&2
1312 test_done "$testroot" "$ret"
1313 return 1
1316 # create a conflicting commit which renames alpha
1317 git -C $testroot/repo checkout -q master
1318 git -C $testroot/repo mv alpha epsilon/alpha-moved
1319 git_commit $testroot/repo -m "moving alpha on master"
1320 local master_commit=`git_show_head $testroot/repo`
1322 # need an up-to-date work tree for 'got merge'
1323 (cd $testroot/wt && got update > /dev/null)
1324 ret=$?
1325 if [ $ret -ne 0 ]; then
1326 echo "got update failed unexpectedly" >&2
1327 test_done "$testroot" "$ret"
1328 return 1
1331 (cd $testroot/wt && got merge newbranch \
1332 > $testroot/stdout 2> $testroot/stderr)
1333 ret=$?
1334 if [ $ret -eq 0 ]; then
1335 echo "got merge succeeded unexpectedly" >&2
1336 test_done "$testroot" "1"
1337 return 1
1340 echo "! alpha" > $testroot/stdout.expected
1341 echo "G gamma/delta" >> $testroot/stdout.expected
1342 echo -n "Files which had incoming changes but could not be found " \
1343 >> $testroot/stdout.expected
1344 echo "in the work tree: 1" >> $testroot/stdout.expected
1345 cmp -s $testroot/stdout.expected $testroot/stdout
1346 ret=$?
1347 if [ $ret -ne 0 ]; then
1348 diff -u $testroot/stdout.expected $testroot/stdout
1349 test_done "$testroot" "$ret"
1350 return 1
1353 echo -n "got: changes destined for some files " \
1354 > $testroot/stderr.expected
1355 echo -n "were not yet merged and should be merged manually if " \
1356 >> $testroot/stderr.expected
1357 echo "required before the merge operation is continued" \
1358 >> $testroot/stderr.expected
1359 cmp -s $testroot/stderr.expected $testroot/stderr
1360 ret=$?
1361 if [ $ret -ne 0 ]; then
1362 diff -u $testroot/stderr.expected $testroot/stderr
1363 test_done "$testroot" "$ret"
1364 return 1
1367 (cd $testroot/wt && got status > $testroot/stdout)
1369 cat > $testroot/stdout.expected <<EOF
1370 M gamma/delta
1371 Work tree is merging refs/heads/newbranch into refs/heads/master
1372 EOF
1373 cmp -s $testroot/stdout.expected $testroot/stdout
1374 ret=$?
1375 if [ $ret -ne 0 ]; then
1376 diff -u $testroot/stdout.expected $testroot/stdout
1377 test_done "$testroot" "$ret"
1378 return 1
1381 test_done "$testroot" "$ret"
1384 test_merge_no_op() {
1385 local testroot=`test_init merge_no_op`
1386 local commit0=`git_show_head $testroot/repo`
1387 local commit0_author_time=`git_show_author_time $testroot/repo`
1389 git -C $testroot/repo checkout -q -b newbranch
1390 echo "modified alpha on branch" > $testroot/repo/alpha
1391 git_commit $testroot/repo -m "committing to alpha on newbranch"
1392 local branch_commit=`git_show_branch_head $testroot/repo newbranch`
1394 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1395 ret=$?
1396 if [ $ret -ne 0 ]; then
1397 echo "got checkout failed unexpectedly" >&2
1398 test_done "$testroot" "$ret"
1399 return 1
1402 # create a conflicting commit
1403 git -C $testroot/repo checkout -q master
1404 echo "modified alpha on master" > $testroot/repo/alpha
1405 git_commit $testroot/repo -m "committing to alpha on master"
1406 local master_commit=`git_show_head $testroot/repo`
1408 # need an up-to-date work tree for 'got merge'
1409 (cd $testroot/wt && got update > /dev/null)
1410 ret=$?
1411 if [ $ret -ne 0 ]; then
1412 echo "got update failed unexpectedly" >&2
1413 test_done "$testroot" "$ret"
1414 return 1
1417 (cd $testroot/wt && got merge newbranch \
1418 > $testroot/stdout 2> $testroot/stderr)
1419 ret=$?
1420 if [ $ret -eq 0 ]; then
1421 echo "got merge succeeded unexpectedly" >&2
1422 test_done "$testroot" "1"
1423 return 1
1426 echo "C alpha" >> $testroot/stdout.expected
1427 echo "Files with new merge conflicts: 1" >> $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 echo "got: conflicts must be resolved before merging can continue" \
1437 > $testroot/stderr.expected
1438 cmp -s $testroot/stderr.expected $testroot/stderr
1439 ret=$?
1440 if [ $ret -ne 0 ]; then
1441 diff -u $testroot/stderr.expected $testroot/stderr
1442 test_done "$testroot" "$ret"
1443 return 1
1446 (cd $testroot/wt && got status > $testroot/stdout)
1448 cat > $testroot/stdout.expected <<EOF
1449 C alpha
1450 Work tree is merging refs/heads/newbranch into refs/heads/master
1451 EOF
1452 cmp -s $testroot/stdout.expected $testroot/stdout
1453 ret=$?
1454 if [ $ret -ne 0 ]; then
1455 diff -u $testroot/stdout.expected $testroot/stdout
1456 test_done "$testroot" "$ret"
1457 return 1
1460 # resolve the conflict by reverting all changes; now it is no-op merge
1461 (cd $testroot/wt && got revert alpha > /dev/null)
1462 ret=$?
1463 if [ $ret -ne 0 ]; then
1464 echo "got revert failed unexpectedly" >&2
1465 test_done "$testroot" "$ret"
1466 return 1
1469 (cd $testroot/wt && got merge -c > $testroot/stdout \
1470 2> $testroot/stderr)
1471 ret=$?
1472 if [ $ret -ne 0 ]; then
1473 echo "got merge failed unexpectedly" >&2
1474 test_done "$testroot" "$ret"
1475 return 1
1478 echo -n '' > $testroot/stderr.expected
1479 cmp -s $testroot/stderr.expected $testroot/stderr
1480 ret=$?
1481 if [ $ret -ne 0 ]; then
1482 diff -u $testroot/stderr.expected $testroot/stderr
1483 test_done "$testroot" "$ret"
1484 return 1
1487 local merge_commit=`git_show_head $testroot/repo`
1488 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1489 > $testroot/stdout.expected
1490 echo $merge_commit >> $testroot/stdout.expected
1492 cmp -s $testroot/stdout.expected $testroot/stdout
1493 ret=$?
1494 if [ $ret -ne 0 ]; then
1495 diff -u $testroot/stdout.expected $testroot/stdout
1496 test_done "$testroot" "$ret"
1497 return 1
1500 (cd $testroot/wt && got status > $testroot/stdout)
1502 echo -n "" > $testroot/stdout.expected
1503 cmp -s $testroot/stdout.expected $testroot/stdout
1504 ret=$?
1505 if [ $ret -ne 0 ]; then
1506 diff -u $testroot/stdout.expected $testroot/stdout
1507 test_done "$testroot" "$ret"
1508 return 1
1511 # We should have created a merge commit with two parents.
1512 got log -r $testroot/repo -l1 -c $merge_commit | grep ^parent \
1513 > $testroot/stdout
1514 echo "parent 1: $master_commit" > $testroot/stdout.expected
1515 echo "parent 2: $branch_commit" >> $testroot/stdout.expected
1516 cmp -s $testroot/stdout.expected $testroot/stdout
1517 ret=$?
1518 if [ $ret -ne 0 ]; then
1519 diff -u $testroot/stdout.expected $testroot/stdout
1521 test_done "$testroot" "$ret"
1524 test_merge_imported_branch() {
1525 local testroot=`test_init merge_import`
1526 local commit0=`git_show_head $testroot/repo`
1527 local commit0_author_time=`git_show_author_time $testroot/repo`
1529 # import a new sub-tree to the 'files' branch such that
1530 # none of the files added here collide with existing ones
1531 mkdir -p $testroot/tree/there
1532 mkdir -p $testroot/tree/be/lots
1533 mkdir -p $testroot/tree/files
1534 echo "there should" > $testroot/tree/there/should
1535 echo "be lots of" > $testroot/tree/be/lots/of
1536 echo "files here" > $testroot/tree/files/here
1537 got import -r $testroot/repo -b files -m 'import files' \
1538 $testroot/tree > /dev/null
1540 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1541 ret=$?
1542 if [ $ret -ne 0 ]; then
1543 echo "got checkout failed unexpectedly" >&2
1544 test_done "$testroot" "$ret"
1545 return 1
1548 (cd $testroot/wt && got merge files > $testroot/stdout)
1549 ret=$?
1550 if [ $ret -ne 0 ]; then
1551 echo "got merge failed unexpectedly" >&2
1552 test_done "$testroot" "$ret"
1553 return 1
1556 local merge_commit0=`git_show_head $testroot/repo`
1557 cat > $testroot/stdout.expected <<EOF
1558 A be/lots/of
1559 A files/here
1560 A there/should
1561 Merged refs/heads/files into refs/heads/master: $merge_commit0
1562 EOF
1563 cmp -s $testroot/stdout.expected $testroot/stdout
1564 ret=$?
1565 if [ $ret -ne 0 ]; then
1566 diff -u $testroot/stdout.expected $testroot/stdout
1567 test_done "$testroot" "$ret"
1568 return 1
1571 # try to merge again while no new changes are available
1572 (cd $testroot/wt && got merge files > $testroot/stdout)
1573 ret=$?
1574 if [ $ret -ne 0 ]; then
1575 echo "got merge failed unexpectedly" >&2
1576 test_done "$testroot" "$ret"
1577 return 1
1579 echo "Already up-to-date" > $testroot/stdout.expected
1580 cmp -s $testroot/stdout.expected $testroot/stdout
1581 ret=$?
1582 if [ $ret -ne 0 ]; then
1583 diff -u $testroot/stdout.expected $testroot/stdout
1584 test_done "$testroot" "$ret"
1585 return 1
1588 # update the 'files' branch
1589 git -C $testroot/repo reset -q --hard master
1590 git -C $testroot/repo checkout -q files
1591 echo "indeed" > $testroot/repo/indeed
1592 git -C $testroot/repo add indeed
1593 git_commit $testroot/repo -m "adding another file indeed"
1594 echo "be lots and lots of" > $testroot/repo/be/lots/of
1595 git_commit $testroot/repo -m "lots of changes"
1597 (cd $testroot/wt && got update > /dev/null)
1598 ret=$?
1599 if [ $ret -ne 0 ]; then
1600 echo "got update failed unexpectedly" >&2
1601 test_done "$testroot" "$ret"
1602 return 1
1605 # we should now be able to merge more changes from files branch
1606 (cd $testroot/wt && got merge files > $testroot/stdout)
1607 ret=$?
1608 if [ $ret -ne 0 ]; then
1609 echo "got merge failed unexpectedly" >&2
1610 test_done "$testroot" "$ret"
1611 return 1
1614 local merge_commit1=`git_show_branch_head $testroot/repo master`
1615 cat > $testroot/stdout.expected <<EOF
1616 G be/lots/of
1617 A indeed
1618 Merged refs/heads/files into refs/heads/master: $merge_commit1
1619 EOF
1621 cmp -s $testroot/stdout.expected $testroot/stdout
1622 ret=$?
1623 if [ $ret -ne 0 ]; then
1624 diff -u $testroot/stdout.expected $testroot/stdout
1626 test_done "$testroot" "$ret"
1629 test_merge_interrupt() {
1630 local testroot=`test_init merge_interrupt`
1631 local commit0=`git_show_head $testroot/repo`
1632 local commit0_author_time=`git_show_author_time $testroot/repo`
1634 git -C $testroot/repo checkout -q -b newbranch
1635 echo "modified alpha on branch" > $testroot/repo/alpha
1636 git_commit $testroot/repo -m "committing to alpha on newbranch"
1637 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1639 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1640 ret=$?
1641 if [ $ret -ne 0 ]; then
1642 echo "got checkout failed unexpectedly" >&2
1643 test_done "$testroot" "$ret"
1644 return 1
1647 # create a non-conflicting commit
1648 git -C $testroot/repo checkout -q master
1649 echo "modified beta on master" > $testroot/repo/beta
1650 git_commit $testroot/repo -m "committing to beta on master"
1651 local master_commit=`git_show_head $testroot/repo`
1653 # need an up-to-date work tree for 'got merge'
1654 (cd $testroot/wt && got update > /dev/null)
1655 ret=$?
1656 if [ $ret -ne 0 ]; then
1657 echo "got update failed unexpectedly" >&2
1658 test_done "$testroot" "$ret"
1659 return 1
1662 (cd $testroot/wt && got merge -n newbranch \
1663 > $testroot/stdout 2> $testroot/stderr)
1664 ret=$?
1665 if [ $ret -ne 0 ]; then
1666 echo "got merge failed unexpectedly" >&2
1667 test_done "$testroot" "1"
1668 return 1
1671 echo "G alpha" > $testroot/stdout.expected
1672 echo "Merge of refs/heads/newbranch interrupted on request" \
1673 >> $testroot/stdout.expected
1674 cmp -s $testroot/stdout.expected $testroot/stdout
1675 ret=$?
1676 if [ $ret -ne 0 ]; then
1677 diff -u $testroot/stdout.expected $testroot/stdout
1678 test_done "$testroot" "$ret"
1679 return 1
1682 (cd $testroot/wt && got status > $testroot/stdout)
1684 cat > $testroot/stdout.expected <<EOF
1685 M alpha
1686 Work tree is merging refs/heads/newbranch into refs/heads/master
1687 EOF
1688 cmp -s $testroot/stdout.expected $testroot/stdout
1689 ret=$?
1690 if [ $ret -ne 0 ]; then
1691 diff -u $testroot/stdout.expected $testroot/stdout
1692 test_done "$testroot" "$ret"
1693 return 1
1696 echo "modified alpha on branch" > $testroot/content.expected
1697 cat $testroot/wt/alpha > $testroot/content
1698 cmp -s $testroot/content.expected $testroot/content
1699 ret=$?
1700 if [ $ret -ne 0 ]; then
1701 diff -u $testroot/content.expected $testroot/content
1702 test_done "$testroot" "$ret"
1703 return 1
1706 # adjust merge result
1707 echo "adjusted merge result" > $testroot/wt/alpha
1709 # continue the merge
1710 (cd $testroot/wt && got merge -c > $testroot/stdout)
1711 ret=$?
1712 if [ $ret -ne 0 ]; then
1713 echo "got merge failed unexpectedly" >&2
1714 test_done "$testroot" "$ret"
1715 return 1
1718 local merge_commit=`git_show_head $testroot/repo`
1720 echo "M alpha" > $testroot/stdout.expected
1721 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1722 >> $testroot/stdout.expected
1723 echo $merge_commit >> $testroot/stdout.expected
1725 cmp -s $testroot/stdout.expected $testroot/stdout
1726 ret=$?
1727 if [ $ret -ne 0 ]; then
1728 diff -u $testroot/stdout.expected $testroot/stdout
1729 test_done "$testroot" "$ret"
1730 return 1
1733 (cd $testroot/wt && got status > $testroot/stdout)
1735 echo -n > $testroot/stdout.expected
1736 cmp -s $testroot/stdout.expected $testroot/stdout
1737 ret=$?
1738 if [ $ret -ne 0 ]; then
1739 diff -u $testroot/stdout.expected $testroot/stdout
1740 test_done "$testroot" "$ret"
1741 return 1
1744 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1745 echo "commit $merge_commit (master)" > $testroot/stdout.expected
1746 echo "commit $master_commit" >> $testroot/stdout.expected
1747 echo "commit $commit0" >> $testroot/stdout.expected
1748 cmp -s $testroot/stdout.expected $testroot/stdout
1749 ret=$?
1750 if [ $ret -ne 0 ]; then
1751 diff -u $testroot/stdout.expected $testroot/stdout
1752 test_done "$testroot" "$ret"
1753 return 1
1756 (cd $testroot/wt && got update > $testroot/stdout)
1758 echo 'Already up-to-date' > $testroot/stdout.expected
1759 cmp -s $testroot/stdout.expected $testroot/stdout
1760 ret=$?
1761 if [ $ret -ne 0 ]; then
1762 diff -u $testroot/stdout.expected $testroot/stdout
1763 test_done "$testroot" "$ret"
1764 return 1
1767 # We should have created a merge commit with two parents.
1768 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
1769 echo "parent 1: $master_commit" > $testroot/stdout.expected
1770 echo "parent 2: $branch_commit0" >> $testroot/stdout.expected
1771 cmp -s $testroot/stdout.expected $testroot/stdout
1772 ret=$?
1773 if [ $ret -ne 0 ]; then
1774 diff -u $testroot/stdout.expected $testroot/stdout
1776 test_done "$testroot" "$ret"
1779 test_merge_umask() {
1780 local testroot=`test_init merge_umask`
1782 git -C $testroot/repo checkout -q -b newbranch
1783 echo "modified alpha on branch" >$testroot/repo/alpha
1784 git_commit "$testroot/repo" -m "committing alpha on newbranch"
1785 echo "modified delta on branch" >$testroot/repo/gamma/delta
1786 git_commit "$testroot/repo" -m "committing delta on newbranch"
1788 # diverge from newbranch
1789 git -C "$testroot/repo" checkout -q master
1790 echo "modified beta on master" >$testroot/repo/beta
1791 git_commit "$testroot/repo" -m "committing zeto no master"
1793 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1795 # using a subshell to avoid clobbering global umask
1796 (umask 077 && cd "$testroot/wt" && got merge newbranch) >/dev/null
1798 for f in alpha gamma/delta; do
1799 ls -l "$testroot/wt/$f" | grep -q ^-rw-------
1800 if [ $? -ne 0 ]; then
1801 echo "$f is not 0600 after merge" >&2
1802 ls -l "$testroot/wt/$f" >&2
1803 test_done "$testroot" 1
1805 done
1807 test_done "$testroot" 0
1810 test_merge_gitconfig_author() {
1811 local testroot=`test_init merge_gitconfig_author`
1813 git -C $testroot/repo config user.name 'Flan Luck'
1814 git -C $testroot/repo config user.email 'flan_luck@openbsd.org'
1816 git -C $testroot/repo checkout -q -b newbranch
1817 echo "modified alpha on branch" >$testroot/repo/alpha
1818 git_commit "$testroot/repo" -m "committing alpha on newbranch"
1819 echo "modified delta on branch" >$testroot/repo/gamma/delta
1820 git_commit "$testroot/repo" -m "committing delta on newbranch"
1822 # diverge from newbranch
1823 git -C "$testroot/repo" checkout -q master
1824 echo "modified beta on master" >$testroot/repo/beta
1825 git_commit "$testroot/repo" -m "committing zeto no master"
1827 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1829 # unset in a subshell to avoid affecting our environment
1830 (unset GOT_IGNORE_GITCONFIG && cd $testroot/wt && \
1831 got merge newbranch > /dev/null)
1833 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
1834 ret=$?
1835 if [ $ret -ne 0 ]; then
1836 test_done "$testroot" "$ret"
1837 return 1
1840 echo "from: Flan Luck <flan_luck@openbsd.org>" \
1841 > $testroot/stdout.expected
1842 cmp -s $testroot/stdout.expected $testroot/stdout
1843 ret=$?
1844 if [ $ret -ne 0 ]; then
1845 diff -u $testroot/stdout.expected $testroot/stdout
1847 test_done "$testroot" "$ret"
1850 test_merge_fetched_branch() {
1851 local testroot=`test_init merge_fetched_branch`
1852 local testurl=ssh://127.0.0.1/$testroot
1853 local commit_id=`git_show_head $testroot/repo`
1855 got clone -q $testurl/repo $testroot/repo-clone
1856 ret=$?
1857 if [ $ret -ne 0 ]; then
1858 echo "got clone command failed unexpectedly" >&2
1859 test_done "$testroot" "$ret"
1860 return 1
1863 echo "modified alpha" > $testroot/repo/alpha
1864 git_commit $testroot/repo -m "modified alpha"
1865 local commit_id2=`git_show_head $testroot/repo`
1867 got fetch -q -r $testroot/repo-clone > $testroot/stdout
1868 ret=$?
1869 if [ $ret -ne 0 ]; then
1870 echo "got fetch command failed unexpectedly" >&2
1871 test_done "$testroot" "$ret"
1872 return 1
1875 echo -n > $testroot/stdout.expected
1877 cmp -s $testroot/stdout $testroot/stdout.expected
1878 ret=$?
1879 if [ $ret -ne 0 ]; then
1880 diff -u $testroot/stdout.expected $testroot/stdout
1881 test_done "$testroot" "$ret"
1882 return 1
1885 got ref -l -r $testroot/repo-clone > $testroot/stdout
1887 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1888 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1889 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1890 >> $testroot/stdout.expected
1891 echo "refs/remotes/origin/master: $commit_id2" \
1892 >> $testroot/stdout.expected
1894 cmp -s $testroot/stdout $testroot/stdout.expected
1895 ret=$?
1896 if [ $ret -ne 0 ]; then
1897 diff -u $testroot/stdout.expected $testroot/stdout
1898 test_done "$testroot" "$ret"
1899 return 1
1902 got checkout $testroot/repo-clone $testroot/wt > /dev/null
1904 echo "modified beta" > $testroot/wt/beta
1905 (cd $testroot/wt && got commit -m "modified beta" > /dev/null)
1906 local commit_id3=`git_show_head $testroot/repo-clone`
1908 (cd $testroot/wt && got update > /dev/null)
1909 (cd $testroot/wt && got merge origin/master > $testroot/stdout)
1910 local merge_commit_id=`git_show_head $testroot/repo-clone`
1912 cat > $testroot/stdout.expected <<EOF
1913 G alpha
1914 Merged refs/remotes/origin/master into refs/heads/master: $merge_commit_id
1915 EOF
1917 cmp -s $testroot/stdout $testroot/stdout.expected
1918 ret=$?
1919 if [ $ret -ne 0 ]; then
1920 diff -u $testroot/stdout.expected $testroot/stdout
1922 test_done "$testroot" "$ret"
1925 test_merge_fetched_branch_remote() {
1926 local testroot=`test_init merge_fetched_branch_remote`
1927 local testurl=ssh://127.0.0.1/$testroot
1928 local commit_id=`git_show_head $testroot/repo`
1930 got clone -q $testurl/repo $testroot/repo-clone
1931 ret=$?
1932 if [ $ret -ne 0 ]; then
1933 echo "got clone command failed unexpectedly" >&2
1934 test_done "$testroot" "$ret"
1935 return 1
1938 echo "modified alpha" > $testroot/repo/alpha
1939 git_commit $testroot/repo -m "modified alpha"
1940 local commit_id2=`git_show_head $testroot/repo`
1942 got fetch -q -r $testroot/repo-clone > $testroot/stdout
1943 ret=$?
1944 if [ $ret -ne 0 ]; then
1945 echo "got fetch command failed unexpectedly" >&2
1946 test_done "$testroot" "$ret"
1947 return 1
1950 echo -n > $testroot/stdout.expected
1952 cmp -s $testroot/stdout $testroot/stdout.expected
1953 ret=$?
1954 if [ $ret -ne 0 ]; then
1955 diff -u $testroot/stdout.expected $testroot/stdout
1956 test_done "$testroot" "$ret"
1957 return 1
1960 got ref -l -r $testroot/repo-clone > $testroot/stdout
1962 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1963 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1964 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1965 >> $testroot/stdout.expected
1966 echo "refs/remotes/origin/master: $commit_id2" \
1967 >> $testroot/stdout.expected
1969 cmp -s $testroot/stdout $testroot/stdout.expected
1970 ret=$?
1971 if [ $ret -ne 0 ]; then
1972 diff -u $testroot/stdout.expected $testroot/stdout
1973 test_done "$testroot" "$ret"
1974 return 1
1977 got checkout $testroot/repo-clone $testroot/wt > /dev/null
1979 echo "modified beta" > $testroot/wt/beta
1980 (cd $testroot/wt && got commit -m "modified beta" > /dev/null)
1981 local commit_id3=`git_show_head $testroot/repo-clone`
1983 (cd $testroot/wt && got update -b origin/master > /dev/null)
1984 (cd $testroot/wt && got merge master > \
1985 $testroot/stdout 2> $testroot/stderr)
1986 local merge_commit_id=`git_show_head $testroot/repo-clone`
1988 echo -n > $testroot/stdout.expected
1990 cmp -s $testroot/stdout $testroot/stdout.expected
1991 ret=$?
1992 if [ $ret -ne 0 ]; then
1993 diff -u $testroot/stdout.expected $testroot/stdout
1994 test_done "$testroot" "$ret"
1995 return 1
1998 echo -n "got: work tree's current branch refs/remotes/origin/master " \
1999 > $testroot/stderr.expected
2000 echo -n 'is outside the "refs/heads/" reference namespace; ' \
2001 >> $testroot/stderr.expected
2002 echo -n "update -b required: will not commit to a branch " \
2003 >> $testroot/stderr.expected
2004 echo 'outside the "refs/heads/" reference namespace' \
2005 >> $testroot/stderr.expected
2007 cmp -s $testroot/stderr $testroot/stderr.expected
2008 ret=$?
2009 if [ $ret -ne 0 ]; then
2010 diff -u $testroot/stderr.expected $testroot/stderr
2012 test_done "$testroot" "$ret"
2015 test_parseargs "$@"
2016 run_test test_merge_basic
2017 run_test test_merge_forward
2018 run_test test_merge_forward_commit
2019 run_test test_merge_forward_interrupt
2020 run_test test_merge_backward
2021 run_test test_merge_continue
2022 run_test test_merge_continue_new_commit
2023 run_test test_merge_abort
2024 run_test test_merge_in_progress
2025 run_test test_merge_path_prefix
2026 run_test test_merge_missing_file
2027 run_test test_merge_no_op
2028 run_test test_merge_imported_branch
2029 run_test test_merge_interrupt
2030 run_test test_merge_umask
2031 run_test test_merge_gitconfig_author
2032 run_test test_merge_fetched_branch
2033 run_test test_merge_fetched_branch_remote