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" != "0" ]; then
50 echo "got checkout failed unexpectedly" >&2
51 test_done "$testroot" "$ret"
52 return 1
53 fi
55 # need a divergant commit on the main branch for 'got merge'
56 (cd $testroot/wt && got merge newbranch \
57 > $testroot/stdout 2> $testroot/stderr)
58 ret="$?"
59 if [ "$ret" == "0" ]; then
60 echo "got merge succeeded unexpectedly" >&2
61 test_done "$testroot" "1"
62 return 1
63 fi
64 echo -n "got: cannot create a merge commit because " \
65 > $testroot/stderr.expected
66 echo -n "refs/heads/newbranch is based on refs/heads/master; " \
67 >> $testroot/stderr.expected
68 echo -n "refs/heads/newbranch can be integrated with " \
69 >> $testroot/stderr.expected
70 echo "'got integrate' instead" >> $testroot/stderr.expected
71 cmp -s $testroot/stderr.expected $testroot/stderr
72 ret="$?"
73 if [ "$ret" != "0" ]; then
74 diff -u $testroot/stderr.expected $testroot/stderr
75 test_done "$testroot" "$ret"
76 return 1
77 fi
79 # create the required dirvergant commit
80 (cd $testroot/repo && git checkout -q master)
81 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
82 git_commit $testroot/repo -m "committing to zeta on master"
83 local master_commit=`git_show_head $testroot/repo`
85 # need an up-to-date work tree for 'got merge'
86 (cd $testroot/wt && got merge newbranch \
87 > $testroot/stdout 2> $testroot/stderr)
88 ret="$?"
89 if [ "$ret" == "0" ]; then
90 echo "got merge succeeded unexpectedly" >&2
91 test_done "$testroot" "$ret"
92 return 1
93 fi
94 echo -n "got: work tree must be updated before it can be used " \
95 > $testroot/stderr.expected
96 echo "to merge a branch" >> $testroot/stderr.expected
97 cmp -s $testroot/stderr.expected $testroot/stderr
98 ret="$?"
99 if [ "$ret" != "0" ]; then
100 diff -u $testroot/stderr.expected $testroot/stderr
101 test_done "$testroot" "$ret"
102 return 1
103 fi
105 (cd $testroot/wt && got update > /dev/null)
106 ret="$?"
107 if [ "$ret" != "0" ]; then
108 echo "got update failed unexpectedly" >&2
109 test_done "$testroot" "$ret"
110 return 1
111 fi
113 # must not use a mixed-commit work tree with 'got merge'
114 (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
115 ret="$?"
116 if [ "$ret" != "0" ]; then
117 echo "got update failed unexpectedly" >&2
118 test_done "$testroot" "$ret"
119 return 1
120 fi
121 (cd $testroot/wt && got merge newbranch \
122 > $testroot/stdout 2> $testroot/stderr)
123 ret="$?"
124 if [ "$ret" == "0" ]; then
125 echo "got merge succeeded unexpectedly" >&2
126 test_done "$testroot" "$ret"
127 return 1
128 fi
129 echo -n "got: work tree contains files from multiple base commits; " \
130 > $testroot/stderr.expected
131 echo "the entire work tree must be updated first" \
132 >> $testroot/stderr.expected
133 cmp -s $testroot/stderr.expected $testroot/stderr
134 ret="$?"
135 if [ "$ret" != "0" ]; then
136 diff -u $testroot/stderr.expected $testroot/stderr
137 test_done "$testroot" "$ret"
138 return 1
139 fi
141 (cd $testroot/wt && got update > /dev/null)
142 ret="$?"
143 if [ "$ret" != "0" ]; then
144 echo "got update failed unexpectedly" >&2
145 test_done "$testroot" "$ret"
146 return 1
147 fi
149 # must not have staged files with 'got merge'
150 echo "modified file alpha" > $testroot/wt/alpha
151 (cd $testroot/wt && got stage alpha > /dev/null)
152 ret="$?"
153 if [ "$ret" != "0" ]; then
154 echo "got stage failed unexpectedly" >&2
155 test_done "$testroot" "$ret"
156 return 1
157 fi
158 (cd $testroot/wt && got merge newbranch \
159 > $testroot/stdout 2> $testroot/stderr)
160 ret="$?"
161 if [ "$ret" == "0" ]; then
162 echo "got merge succeeded unexpectedly" >&2
163 test_done "$testroot" "$ret"
164 return 1
165 fi
166 echo "got: alpha: file is staged" > $testroot/stderr.expected
167 cmp -s $testroot/stderr.expected $testroot/stderr
168 ret="$?"
169 if [ "$ret" != "0" ]; then
170 diff -u $testroot/stderr.expected $testroot/stderr
171 test_done "$testroot" "$ret"
172 return 1
173 fi
174 (cd $testroot/wt && got unstage alpha > /dev/null)
175 ret="$?"
176 if [ "$ret" != "0" ]; then
177 echo "got unstage failed unexpectedly" >&2
178 test_done "$testroot" "$ret"
179 return 1
180 fi
182 # must not have local changes with 'got merge'
183 (cd $testroot/wt && got merge newbranch \
184 > $testroot/stdout 2> $testroot/stderr)
185 ret="$?"
186 if [ "$ret" == "0" ]; then
187 echo "got merge succeeded unexpectedly" >&2
188 test_done "$testroot" "$ret"
189 return 1
190 fi
191 echo -n "got: work tree contains local changes; " \
192 > $testroot/stderr.expected
193 echo "these changes must be committed or reverted first" \
194 >> $testroot/stderr.expected
195 cmp -s $testroot/stderr.expected $testroot/stderr
196 ret="$?"
197 if [ "$ret" != "0" ]; then
198 diff -u $testroot/stderr.expected $testroot/stderr
199 test_done "$testroot" "$ret"
200 return 1
201 fi
203 (cd $testroot/wt && got revert alpha > /dev/null)
204 ret="$?"
205 if [ "$ret" != "0" ]; then
206 echo "got revert failed unexpectedly" >&2
207 test_done "$testroot" "$ret"
208 return 1
209 fi
211 (cd $testroot/wt && got merge newbranch > $testroot/stdout)
212 ret="$?"
213 if [ "$ret" != "0" ]; then
214 echo "got merge failed unexpectedly" >&2
215 test_done "$testroot" "$ret"
216 return 1
217 fi
219 local merge_commit=`git_show_head $testroot/repo`
221 echo "G alpha" >> $testroot/stdout.expected
222 echo "D beta" >> $testroot/stdout.expected
223 echo "A dotgotbar.link" >> $testroot/stdout.expected
224 echo "A epsilon/new" >> $testroot/stdout.expected
225 echo "G gamma/delta" >> $testroot/stdout.expected
226 echo "A symlink" >> $testroot/stdout.expected
227 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
228 >> $testroot/stdout.expected
229 echo $merge_commit >> $testroot/stdout.expected
231 cmp -s $testroot/stdout.expected $testroot/stdout
232 ret="$?"
233 if [ "$ret" != "0" ]; then
234 diff -u $testroot/stdout.expected $testroot/stdout
235 test_done "$testroot" "$ret"
236 return 1
237 fi
239 echo "modified delta on branch" > $testroot/content.expected
240 cat $testroot/wt/gamma/delta > $testroot/content
241 cmp -s $testroot/content.expected $testroot/content
242 ret="$?"
243 if [ "$ret" != "0" ]; then
244 diff -u $testroot/content.expected $testroot/content
245 test_done "$testroot" "$ret"
246 return 1
247 fi
249 echo "modified alpha on branch" > $testroot/content.expected
250 cat $testroot/wt/alpha > $testroot/content
251 cmp -s $testroot/content.expected $testroot/content
252 ret="$?"
253 if [ "$ret" != "0" ]; then
254 diff -u $testroot/content.expected $testroot/content
255 test_done "$testroot" "$ret"
256 return 1
257 fi
259 if [ -e $testroot/wt/beta ]; then
260 echo "removed file beta still exists on disk" >&2
261 test_done "$testroot" "1"
262 return 1
263 fi
265 echo "new file on branch" > $testroot/content.expected
266 cat $testroot/wt/epsilon/new > $testroot/content
267 cmp -s $testroot/content.expected $testroot/content
268 ret="$?"
269 if [ "$ret" != "0" ]; then
270 diff -u $testroot/content.expected $testroot/content
271 test_done "$testroot" "$ret"
272 return 1
273 fi
275 if [ ! -h $testroot/wt/dotgotbar.link ]; then
276 echo "dotgotbar.link is not a symlink"
277 test_done "$testroot" "1"
278 return 1
279 fi
281 readlink $testroot/wt/symlink > $testroot/stdout
282 echo "alpha" > $testroot/stdout.expected
283 cmp -s $testroot/stdout.expected $testroot/stdout
284 ret="$?"
285 if [ "$ret" != "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 status > $testroot/stdout)
293 echo -n > $testroot/stdout.expected
294 cmp -s $testroot/stdout.expected $testroot/stdout
295 ret="$?"
296 if [ "$ret" != "0" ]; then
297 diff -u $testroot/stdout.expected $testroot/stdout
298 test_done "$testroot" "$ret"
299 return 1
300 fi
302 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
303 echo "commit $merge_commit (master)" > $testroot/stdout.expected
304 echo "commit $master_commit" >> $testroot/stdout.expected
305 echo "commit $commit0" >> $testroot/stdout.expected
306 cmp -s $testroot/stdout.expected $testroot/stdout
307 ret="$?"
308 if [ "$ret" != "0" ]; then
309 diff -u $testroot/stdout.expected $testroot/stdout
310 test_done "$testroot" "$ret"
311 return 1
312 fi
314 (cd $testroot/wt && got update > $testroot/stdout)
316 echo 'U dotgotbar.link' > $testroot/stdout.expected
317 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
318 git_show_head $testroot/repo >> $testroot/stdout.expected
319 echo >> $testroot/stdout.expected
320 cmp -s $testroot/stdout.expected $testroot/stdout
321 ret="$?"
322 if [ "$ret" != "0" ]; then
323 diff -u $testroot/stdout.expected $testroot/stdout
324 test_done "$testroot" "$ret"
325 return 1
326 fi
328 # update has changed the bad symlink into a regular file
329 if [ -h $testroot/wt/dotgotbar.link ]; then
330 echo "dotgotbar.link is a symlink"
331 test_done "$testroot" "1"
332 return 1
333 fi
335 # We should have created a merge commit with two parents.
336 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
337 echo "parent 1: $master_commit" > $testroot/stdout.expected
338 echo "parent 2: $branch_commit5" >> $testroot/stdout.expected
339 cmp -s $testroot/stdout.expected $testroot/stdout
340 ret="$?"
341 if [ "$ret" != "0" ]; then
342 diff -u $testroot/stdout.expected $testroot/stdout
343 test_done "$testroot" "$ret"
344 return 1
345 fi
347 got tree -r $testroot/repo -c $merge_commit -R > $testroot/stdout
348 ret="$?"
349 if [ "$ret" != "0" ]; then
350 echo "got tree failed unexpectedly" >&2
351 test_done "$testroot" "$ret"
352 return 1
353 fi
355 # bad symlink dotgotbar.link appears as a symlink in the merge commit:
356 cat > $testroot/stdout.expected <<EOF
357 alpha
358 dotgotbar.link@ -> .got/bar
359 epsilon/
360 epsilon/new
361 epsilon/zeta
362 gamma/
363 gamma/delta
364 symlink@ -> alpha
365 EOF
366 cmp -s $testroot/stdout.expected $testroot/stdout
367 ret="$?"
368 if [ "$ret" != "0" ]; then
369 diff -u $testroot/stdout.expected $testroot/stdout
370 fi
371 test_done "$testroot" "$ret"
374 test_merge_continue() {
375 local testroot=`test_init merge_continue`
376 local commit0=`git_show_head $testroot/repo`
377 local commit0_author_time=`git_show_author_time $testroot/repo`
379 (cd $testroot/repo && git checkout -q -b newbranch)
380 echo "modified delta on branch" > $testroot/repo/gamma/delta
381 git_commit $testroot/repo -m "committing to delta on newbranch"
382 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
384 echo "modified alpha on branch" > $testroot/repo/alpha
385 git_commit $testroot/repo -m "committing to alpha on newbranch"
386 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
387 (cd $testroot/repo && git rm -q beta)
388 git_commit $testroot/repo -m "removing beta on newbranch"
389 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
390 echo "new file on branch" > $testroot/repo/epsilon/new
391 (cd $testroot/repo && git add epsilon/new)
392 git_commit $testroot/repo -m "adding new file on newbranch"
393 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
395 got checkout -b master $testroot/repo $testroot/wt > /dev/null
396 ret="$?"
397 if [ "$ret" != "0" ]; then
398 echo "got checkout failed unexpectedly" >&2
399 test_done "$testroot" "$ret"
400 return 1
401 fi
403 # create a conflicting commit
404 (cd $testroot/repo && git checkout -q master)
405 echo "modified alpha on master" > $testroot/repo/alpha
406 git_commit $testroot/repo -m "committing to alpha on master"
407 local master_commit=`git_show_head $testroot/repo`
409 # need an up-to-date work tree for 'got merge'
410 (cd $testroot/wt && got update > /dev/null)
411 ret="$?"
412 if [ "$ret" != "0" ]; then
413 echo "got update failed unexpectedly" >&2
414 test_done "$testroot" "$ret"
415 return 1
416 fi
418 (cd $testroot/wt && got merge newbranch \
419 > $testroot/stdout 2> $testroot/stderr)
420 ret="$?"
421 if [ "$ret" == "0" ]; then
422 echo "got merge succeeded unexpectedly" >&2
423 test_done "$testroot" "1"
424 return 1
425 fi
427 echo "C alpha" >> $testroot/stdout.expected
428 echo "D beta" >> $testroot/stdout.expected
429 echo "A epsilon/new" >> $testroot/stdout.expected
430 echo "G gamma/delta" >> $testroot/stdout.expected
431 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
432 cmp -s $testroot/stdout.expected $testroot/stdout
433 ret="$?"
434 if [ "$ret" != "0" ]; then
435 diff -u $testroot/stdout.expected $testroot/stdout
436 test_done "$testroot" "$ret"
437 return 1
438 fi
440 echo "got: conflicts must be resolved before merging can continue" \
441 > $testroot/stderr.expected
442 cmp -s $testroot/stderr.expected $testroot/stderr
443 ret="$?"
444 if [ "$ret" != "0" ]; then
445 diff -u $testroot/stderr.expected $testroot/stderr
446 test_done "$testroot" "$ret"
447 return 1
448 fi
450 (cd $testroot/wt && got status > $testroot/stdout)
452 echo "C alpha" > $testroot/stdout.expected
453 echo "D beta" >> $testroot/stdout.expected
454 echo "A epsilon/new" >> $testroot/stdout.expected
455 echo "M gamma/delta" >> $testroot/stdout.expected
456 cmp -s $testroot/stdout.expected $testroot/stdout
457 ret="$?"
458 if [ "$ret" != "0" ]; then
459 diff -u $testroot/stdout.expected $testroot/stdout
460 test_done "$testroot" "$ret"
461 return 1
462 fi
464 echo '<<<<<<<' > $testroot/content.expected
465 echo "modified alpha on master" >> $testroot/content.expected
466 echo "||||||| 3-way merge base: commit $commit0" \
467 >> $testroot/content.expected
468 echo "alpha" >> $testroot/content.expected
469 echo "=======" >> $testroot/content.expected
470 echo "modified alpha on branch" >> $testroot/content.expected
471 echo ">>>>>>> merged change: commit $branch_commit3" \
472 >> $testroot/content.expected
473 cat $testroot/wt/alpha > $testroot/content
474 cmp -s $testroot/content.expected $testroot/content
475 ret="$?"
476 if [ "$ret" != "0" ]; then
477 diff -u $testroot/content.expected $testroot/content
478 test_done "$testroot" "$ret"
479 return 1
480 fi
482 # resolve the conflict
483 echo "modified alpha by both branches" > $testroot/wt/alpha
485 (cd $testroot/wt && got merge -c > $testroot/stdout)
486 ret="$?"
487 if [ "$ret" != "0" ]; then
488 echo "got merge failed unexpectedly" >&2
489 test_done "$testroot" "$ret"
490 return 1
491 fi
493 local merge_commit=`git_show_head $testroot/repo`
495 echo "M alpha" > $testroot/stdout.expected
496 echo "D beta" >> $testroot/stdout.expected
497 echo "A epsilon/new" >> $testroot/stdout.expected
498 echo "M gamma/delta" >> $testroot/stdout.expected
499 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
500 >> $testroot/stdout.expected
501 echo $merge_commit >> $testroot/stdout.expected
503 cmp -s $testroot/stdout.expected $testroot/stdout
504 ret="$?"
505 if [ "$ret" != "0" ]; then
506 diff -u $testroot/stdout.expected $testroot/stdout
507 test_done "$testroot" "$ret"
508 return 1
509 fi
511 echo "modified delta on branch" > $testroot/content.expected
512 cat $testroot/wt/gamma/delta > $testroot/content
513 cmp -s $testroot/content.expected $testroot/content
514 ret="$?"
515 if [ "$ret" != "0" ]; then
516 diff -u $testroot/content.expected $testroot/content
517 test_done "$testroot" "$ret"
518 return 1
519 fi
521 echo "modified alpha by both branches" > $testroot/content.expected
522 cat $testroot/wt/alpha > $testroot/content
523 cmp -s $testroot/content.expected $testroot/content
524 ret="$?"
525 if [ "$ret" != "0" ]; then
526 diff -u $testroot/content.expected $testroot/content
527 test_done "$testroot" "$ret"
528 return 1
529 fi
531 if [ -e $testroot/wt/beta ]; then
532 echo "removed file beta still exists on disk" >&2
533 test_done "$testroot" "1"
534 return 1
535 fi
537 echo "new file on branch" > $testroot/content.expected
538 cat $testroot/wt/epsilon/new > $testroot/content
539 cmp -s $testroot/content.expected $testroot/content
540 ret="$?"
541 if [ "$ret" != "0" ]; then
542 diff -u $testroot/content.expected $testroot/content
543 test_done "$testroot" "$ret"
544 return 1
545 fi
547 (cd $testroot/wt && got status > $testroot/stdout)
549 echo -n > $testroot/stdout.expected
550 cmp -s $testroot/stdout.expected $testroot/stdout
551 ret="$?"
552 if [ "$ret" != "0" ]; then
553 diff -u $testroot/stdout.expected $testroot/stdout
554 test_done "$testroot" "$ret"
555 return 1
556 fi
558 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
559 echo "commit $merge_commit (master)" > $testroot/stdout.expected
560 echo "commit $master_commit" >> $testroot/stdout.expected
561 echo "commit $commit0" >> $testroot/stdout.expected
562 cmp -s $testroot/stdout.expected $testroot/stdout
563 ret="$?"
564 if [ "$ret" != "0" ]; then
565 diff -u $testroot/stdout.expected $testroot/stdout
566 test_done "$testroot" "$ret"
567 return 1
568 fi
570 (cd $testroot/wt && got update > $testroot/stdout)
572 echo 'Already up-to-date' > $testroot/stdout.expected
573 cmp -s $testroot/stdout.expected $testroot/stdout
574 ret="$?"
575 if [ "$ret" != "0" ]; then
576 diff -u $testroot/stdout.expected $testroot/stdout
577 test_done "$testroot" "$ret"
578 return 1
579 fi
581 # We should have created a merge commit with two parents.
582 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
583 echo "parent 1: $master_commit" > $testroot/stdout.expected
584 echo "parent 2: $branch_commit3" >> $testroot/stdout.expected
585 cmp -s $testroot/stdout.expected $testroot/stdout
586 ret="$?"
587 if [ "$ret" != "0" ]; then
588 diff -u $testroot/stdout.expected $testroot/stdout
589 fi
590 test_done "$testroot" "$ret"
593 test_merge_abort() {
594 local testroot=`test_init merge_abort`
595 local commit0=`git_show_head $testroot/repo`
596 local commit0_author_time=`git_show_author_time $testroot/repo`
598 (cd $testroot/repo && git checkout -q -b newbranch)
599 echo "modified delta on branch" > $testroot/repo/gamma/delta
600 git_commit $testroot/repo -m "committing to delta on newbranch"
601 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
603 echo "modified alpha on branch" > $testroot/repo/alpha
604 git_commit $testroot/repo -m "committing to alpha on newbranch"
605 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
606 (cd $testroot/repo && git rm -q beta)
607 git_commit $testroot/repo -m "removing beta on newbranch"
608 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
609 echo "new file on branch" > $testroot/repo/epsilon/new
610 (cd $testroot/repo && git add epsilon/new)
611 git_commit $testroot/repo -m "adding new file on newbranch"
612 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
613 (cd $testroot/repo && ln -s alpha symlink && git add symlink)
614 git_commit $testroot/repo -m "adding symlink on newbranch"
615 local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
617 got checkout -b master $testroot/repo $testroot/wt > /dev/null
618 ret="$?"
619 if [ "$ret" != "0" ]; then
620 echo "got checkout failed unexpectedly" >&2
621 test_done "$testroot" "$ret"
622 return 1
623 fi
625 # create a conflicting commit
626 (cd $testroot/repo && git checkout -q master)
627 echo "modified alpha on master" > $testroot/repo/alpha
628 git_commit $testroot/repo -m "committing to alpha on master"
629 local master_commit=`git_show_head $testroot/repo`
631 # need an up-to-date work tree for 'got merge'
632 (cd $testroot/wt && got update > /dev/null)
633 ret="$?"
634 if [ "$ret" != "0" ]; then
635 echo "got update failed unexpectedly" >&2
636 test_done "$testroot" "$ret"
637 return 1
638 fi
640 (cd $testroot/wt && got merge newbranch \
641 > $testroot/stdout 2> $testroot/stderr)
642 ret="$?"
643 if [ "$ret" == "0" ]; then
644 echo "got merge succeeded unexpectedly" >&2
645 test_done "$testroot" "1"
646 return 1
647 fi
649 echo "C alpha" >> $testroot/stdout.expected
650 echo "D beta" >> $testroot/stdout.expected
651 echo "A epsilon/new" >> $testroot/stdout.expected
652 echo "G gamma/delta" >> $testroot/stdout.expected
653 echo "A symlink" >> $testroot/stdout.expected
654 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
655 cmp -s $testroot/stdout.expected $testroot/stdout
656 ret="$?"
657 if [ "$ret" != "0" ]; then
658 diff -u $testroot/stdout.expected $testroot/stdout
659 test_done "$testroot" "$ret"
660 return 1
661 fi
663 echo "got: conflicts must be resolved before merging can continue" \
664 > $testroot/stderr.expected
665 cmp -s $testroot/stderr.expected $testroot/stderr
666 ret="$?"
667 if [ "$ret" != "0" ]; then
668 diff -u $testroot/stderr.expected $testroot/stderr
669 test_done "$testroot" "$ret"
670 return 1
671 fi
673 (cd $testroot/wt && got status > $testroot/stdout)
675 echo "C alpha" > $testroot/stdout.expected
676 echo "D beta" >> $testroot/stdout.expected
677 echo "A epsilon/new" >> $testroot/stdout.expected
678 echo "M gamma/delta" >> $testroot/stdout.expected
679 echo "A symlink" >> $testroot/stdout.expected
680 cmp -s $testroot/stdout.expected $testroot/stdout
681 ret="$?"
682 if [ "$ret" != "0" ]; then
683 diff -u $testroot/stdout.expected $testroot/stdout
684 test_done "$testroot" "$ret"
685 return 1
686 fi
688 (cd $testroot/wt && got merge -a > $testroot/stdout)
689 ret="$?"
690 if [ "$ret" != "0" ]; then
691 echo "got merge failed unexpectedly" >&2
692 test_done "$testroot" "$ret"
693 return 1
694 fi
696 echo "R alpha" > $testroot/stdout.expected
697 echo "R beta" >> $testroot/stdout.expected
698 echo "R epsilon/new" >> $testroot/stdout.expected
699 echo "R gamma/delta" >> $testroot/stdout.expected
700 echo "R symlink" >> $testroot/stdout.expected
701 echo "Merge of refs/heads/newbranch aborted" \
702 >> $testroot/stdout.expected
704 cmp -s $testroot/stdout.expected $testroot/stdout
705 ret="$?"
706 if [ "$ret" != "0" ]; then
707 diff -u $testroot/stdout.expected $testroot/stdout
708 test_done "$testroot" "$ret"
709 return 1
710 fi
712 echo "delta" > $testroot/content.expected
713 cat $testroot/wt/gamma/delta > $testroot/content
714 cmp -s $testroot/content.expected $testroot/content
715 ret="$?"
716 if [ "$ret" != "0" ]; then
717 diff -u $testroot/content.expected $testroot/content
718 test_done "$testroot" "$ret"
719 return 1
720 fi
722 echo "modified alpha on master" > $testroot/content.expected
723 cat $testroot/wt/alpha > $testroot/content
724 cmp -s $testroot/content.expected $testroot/content
725 ret="$?"
726 if [ "$ret" != "0" ]; then
727 diff -u $testroot/content.expected $testroot/content
728 test_done "$testroot" "$ret"
729 return 1
730 fi
732 echo "beta" > $testroot/content.expected
733 cat $testroot/wt/beta > $testroot/content
734 cmp -s $testroot/content.expected $testroot/content
735 ret="$?"
736 if [ "$ret" != "0" ]; then
737 diff -u $testroot/content.expected $testroot/content
738 test_done "$testroot" "$ret"
739 return 1
740 fi
742 if [ -e $testroot/wt/epsilon/new ]; then
743 echo "reverted file epsilon/new still exists on disk" >&2
744 test_done "$testroot" "1"
745 return 1
746 fi
748 if [ -e $testroot/wt/symlink ]; then
749 echo "reverted symlink still exists on disk" >&2
750 test_done "$testroot" "1"
751 return 1
752 fi
754 (cd $testroot/wt && got status > $testroot/stdout)
756 echo -n "" > $testroot/stdout.expected
757 cmp -s $testroot/stdout.expected $testroot/stdout
758 ret="$?"
759 if [ "$ret" != "0" ]; then
760 diff -u $testroot/stdout.expected $testroot/stdout
761 test_done "$testroot" "$ret"
762 return 1
763 fi
765 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
766 echo "commit $master_commit (master)" > $testroot/stdout.expected
767 echo "commit $commit0" >> $testroot/stdout.expected
768 cmp -s $testroot/stdout.expected $testroot/stdout
769 ret="$?"
770 if [ "$ret" != "0" ]; then
771 diff -u $testroot/stdout.expected $testroot/stdout
772 test_done "$testroot" "$ret"
773 return 1
774 fi
776 (cd $testroot/wt && got update > $testroot/stdout)
778 echo 'Already up-to-date' > $testroot/stdout.expected
779 cmp -s $testroot/stdout.expected $testroot/stdout
780 ret="$?"
781 if [ "$ret" != "0" ]; then
782 diff -u $testroot/stdout.expected $testroot/stdout
783 fi
784 test_done "$testroot" "$ret"
787 test_merge_in_progress() {
788 local testroot=`test_init merge_in_progress`
789 local commit0=`git_show_head $testroot/repo`
790 local commit0_author_time=`git_show_author_time $testroot/repo`
792 (cd $testroot/repo && git checkout -q -b newbranch)
793 echo "modified alpha on branch" > $testroot/repo/alpha
794 git_commit $testroot/repo -m "committing to alpha on newbranch"
795 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
797 got checkout -b master $testroot/repo $testroot/wt > /dev/null
798 ret="$?"
799 if [ "$ret" != "0" ]; then
800 echo "got checkout failed unexpectedly" >&2
801 test_done "$testroot" "$ret"
802 return 1
803 fi
805 # create a conflicting commit
806 (cd $testroot/repo && git checkout -q master)
807 echo "modified alpha on master" > $testroot/repo/alpha
808 git_commit $testroot/repo -m "committing to alpha on master"
809 local master_commit=`git_show_head $testroot/repo`
811 # need an up-to-date work tree for 'got merge'
812 (cd $testroot/wt && got update > /dev/null)
813 ret="$?"
814 if [ "$ret" != "0" ]; then
815 echo "got update failed unexpectedly" >&2
816 test_done "$testroot" "$ret"
817 return 1
818 fi
820 (cd $testroot/wt && got merge newbranch \
821 > $testroot/stdout 2> $testroot/stderr)
822 ret="$?"
823 if [ "$ret" == "0" ]; then
824 echo "got merge succeeded unexpectedly" >&2
825 test_done "$testroot" "1"
826 return 1
827 fi
829 echo "C alpha" >> $testroot/stdout.expected
830 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
831 cmp -s $testroot/stdout.expected $testroot/stdout
832 ret="$?"
833 if [ "$ret" != "0" ]; then
834 diff -u $testroot/stdout.expected $testroot/stdout
835 test_done "$testroot" "$ret"
836 return 1
837 fi
839 echo "got: conflicts must be resolved before merging can continue" \
840 > $testroot/stderr.expected
841 cmp -s $testroot/stderr.expected $testroot/stderr
842 ret="$?"
843 if [ "$ret" != "0" ]; then
844 diff -u $testroot/stderr.expected $testroot/stderr
845 test_done "$testroot" "$ret"
846 return 1
847 fi
849 (cd $testroot/wt && got status > $testroot/stdout)
851 echo "C alpha" > $testroot/stdout.expected
852 cmp -s $testroot/stdout.expected $testroot/stdout
853 ret="$?"
854 if [ "$ret" != "0" ]; then
855 diff -u $testroot/stdout.expected $testroot/stdout
856 test_done "$testroot" "$ret"
857 return 1
858 fi
860 for cmd in update commit histedit "rebase newbranch" \
861 "integrate newbranch" "stage alpha"; do
862 (cd $testroot/wt && got $cmd > $testroot/stdout \
863 2> $testroot/stderr)
865 echo -n > $testroot/stdout.expected
866 cmp -s $testroot/stdout.expected $testroot/stdout
867 ret="$?"
868 if [ "$ret" != "0" ]; then
869 diff -u $testroot/stdout.expected $testroot/stdout
870 test_done "$testroot" "$ret"
871 return 1
872 fi
874 echo -n "got: a merge operation is in progress in this " \
875 > $testroot/stderr.expected
876 echo "work tree and must be continued or aborted first" \
877 >> $testroot/stderr.expected
878 cmp -s $testroot/stderr.expected $testroot/stderr
879 ret="$?"
880 if [ "$ret" != "0" ]; then
881 diff -u $testroot/stderr.expected $testroot/stderr
882 test_done "$testroot" "$ret"
883 return 1
884 fi
885 done
887 test_done "$testroot" "$ret"
890 test_merge_path_prefix() {
891 local testroot=`test_init merge_path_prefix`
892 local commit0=`git_show_head $testroot/repo`
893 local commit0_author_time=`git_show_author_time $testroot/repo`
895 (cd $testroot/repo && git checkout -q -b newbranch)
896 echo "modified alpha on branch" > $testroot/repo/alpha
897 git_commit $testroot/repo -m "committing to alpha on newbranch"
898 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
900 got checkout -p epsilon -b master $testroot/repo $testroot/wt \
901 > /dev/null
902 ret="$?"
903 if [ "$ret" != "0" ]; then
904 echo "got checkout failed unexpectedly" >&2
905 test_done "$testroot" "$ret"
906 return 1
907 fi
909 # create a conflicting commit
910 (cd $testroot/repo && git checkout -q master)
911 echo "modified alpha on master" > $testroot/repo/alpha
912 git_commit $testroot/repo -m "committing to alpha on master"
913 local master_commit=`git_show_head $testroot/repo`
915 # need an up-to-date work tree for 'got merge'
916 (cd $testroot/wt && got update > /dev/null)
917 ret="$?"
918 if [ "$ret" != "0" ]; then
919 echo "got update failed unexpectedly" >&2
920 test_done "$testroot" "$ret"
921 return 1
922 fi
924 (cd $testroot/wt && got merge newbranch \
925 > $testroot/stdout 2> $testroot/stderr)
926 ret="$?"
927 if [ "$ret" == "0" ]; then
928 echo "got merge succeeded unexpectedly" >&2
929 test_done "$testroot" "1"
930 return 1
931 fi
933 echo -n "got: cannot merge branch which contains changes outside " \
934 > $testroot/stderr.expected
935 echo "of this work tree's path prefix" >> $testroot/stderr.expected
936 cmp -s $testroot/stderr.expected $testroot/stderr
937 ret="$?"
938 if [ "$ret" != "0" ]; then
939 diff -u $testroot/stderr.expected $testroot/stderr
940 fi
941 test_done "$testroot" "$ret"
944 test_merge_missing_file() {
945 local testroot=`test_init merge_missing_file`
946 local commit0=`git_show_head $testroot/repo`
947 local commit0_author_time=`git_show_author_time $testroot/repo`
949 (cd $testroot/repo && git checkout -q -b newbranch)
950 echo "modified alpha on branch" > $testroot/repo/alpha
951 echo "modified delta on branch" > $testroot/repo/gamma/delta
952 git_commit $testroot/repo -m "committing to alpha and delta"
953 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
955 got checkout -b master $testroot/repo $testroot/wt > /dev/null
956 ret="$?"
957 if [ "$ret" != "0" ]; then
958 echo "got checkout failed unexpectedly" >&2
959 test_done "$testroot" "$ret"
960 return 1
961 fi
963 # create a conflicting commit which renames alpha
964 (cd $testroot/repo && git checkout -q master)
965 (cd $testroot/repo && git mv alpha epsilon/alpha-moved)
966 git_commit $testroot/repo -m "moving alpha on master"
967 local master_commit=`git_show_head $testroot/repo`
969 # need an up-to-date work tree for 'got merge'
970 (cd $testroot/wt && got update > /dev/null)
971 ret="$?"
972 if [ "$ret" != "0" ]; then
973 echo "got update failed unexpectedly" >&2
974 test_done "$testroot" "$ret"
975 return 1
976 fi
978 (cd $testroot/wt && got merge newbranch \
979 > $testroot/stdout 2> $testroot/stderr)
980 ret="$?"
981 if [ "$ret" == "0" ]; then
982 echo "got merge succeeded unexpectedly" >&2
983 test_done "$testroot" "1"
984 return 1
985 fi
987 echo "! alpha" > $testroot/stdout.expected
988 echo "G gamma/delta" >> $testroot/stdout.expected
989 echo -n "Files which had incoming changes but could not be found " \
990 >> $testroot/stdout.expected
991 echo "in the work tree: 1" >> $testroot/stdout.expected
992 cmp -s $testroot/stdout.expected $testroot/stdout
993 ret="$?"
994 if [ "$ret" != "0" ]; then
995 diff -u $testroot/stdout.expected $testroot/stdout
996 test_done "$testroot" "$ret"
997 return 1
998 fi
1000 echo -n "got: changes destined for some files " \
1001 > $testroot/stderr.expected
1002 echo -n "were not yet merged and should be merged manually if " \
1003 >> $testroot/stderr.expected
1004 echo "required before the merge operation is continued" \
1005 >> $testroot/stderr.expected
1006 cmp -s $testroot/stderr.expected $testroot/stderr
1007 ret="$?"
1008 if [ "$ret" != "0" ]; then
1009 diff -u $testroot/stderr.expected $testroot/stderr
1010 test_done "$testroot" "$ret"
1011 return 1
1014 (cd $testroot/wt && got status > $testroot/stdout)
1016 echo "M gamma/delta" > $testroot/stdout.expected
1017 cmp -s $testroot/stdout.expected $testroot/stdout
1018 ret="$?"
1019 if [ "$ret" != "0" ]; then
1020 diff -u $testroot/stdout.expected $testroot/stdout
1021 test_done "$testroot" "$ret"
1022 return 1
1025 test_done "$testroot" "$ret"
1028 test_merge_no_op() {
1029 local testroot=`test_init merge_no_op`
1030 local commit0=`git_show_head $testroot/repo`
1031 local commit0_author_time=`git_show_author_time $testroot/repo`
1033 (cd $testroot/repo && git checkout -q -b newbranch)
1034 echo "modified alpha on branch" > $testroot/repo/alpha
1035 git_commit $testroot/repo -m "committing to alpha on newbranch"
1036 local branch_commitk=`git_show_branch_head $testroot/repo newbranch`
1038 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1039 ret="$?"
1040 if [ "$ret" != "0" ]; then
1041 echo "got checkout failed unexpectedly" >&2
1042 test_done "$testroot" "$ret"
1043 return 1
1046 # create a conflicting commit
1047 (cd $testroot/repo && git checkout -q master)
1048 echo "modified alpha on master" > $testroot/repo/alpha
1049 git_commit $testroot/repo -m "committing to alpha on master"
1050 local master_commit=`git_show_head $testroot/repo`
1052 # need an up-to-date work tree for 'got merge'
1053 (cd $testroot/wt && got update > /dev/null)
1054 ret="$?"
1055 if [ "$ret" != "0" ]; then
1056 echo "got update failed unexpectedly" >&2
1057 test_done "$testroot" "$ret"
1058 return 1
1061 (cd $testroot/wt && got merge newbranch \
1062 > $testroot/stdout 2> $testroot/stderr)
1063 ret="$?"
1064 if [ "$ret" == "0" ]; then
1065 echo "got merge succeeded unexpectedly" >&2
1066 test_done "$testroot" "1"
1067 return 1
1070 echo "C alpha" >> $testroot/stdout.expected
1071 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1072 cmp -s $testroot/stdout.expected $testroot/stdout
1073 ret="$?"
1074 if [ "$ret" != "0" ]; then
1075 diff -u $testroot/stdout.expected $testroot/stdout
1076 test_done "$testroot" "$ret"
1077 return 1
1080 echo "got: conflicts must be resolved before merging can continue" \
1081 > $testroot/stderr.expected
1082 cmp -s $testroot/stderr.expected $testroot/stderr
1083 ret="$?"
1084 if [ "$ret" != "0" ]; then
1085 diff -u $testroot/stderr.expected $testroot/stderr
1086 test_done "$testroot" "$ret"
1087 return 1
1090 (cd $testroot/wt && got status > $testroot/stdout)
1092 echo "C alpha" > $testroot/stdout.expected
1093 cmp -s $testroot/stdout.expected $testroot/stdout
1094 ret="$?"
1095 if [ "$ret" != "0" ]; then
1096 diff -u $testroot/stdout.expected $testroot/stdout
1097 test_done "$testroot" "$ret"
1098 return 1
1101 # resolve the conflict by reverting all changes; now it is no-op merge
1102 (cd $testroot/wt && got revert alpha > /dev/null)
1103 ret="$?"
1104 if [ "$ret" != "0" ]; then
1105 echo "got revert failed unexpectedly" >&2
1106 test_done "$testroot" "$ret"
1107 return 1
1110 (cd $testroot/wt && got merge -c > $testroot/stdout \
1111 2> $testroot/stderr)
1112 ret="$?"
1113 if [ "$ret" == "0" ]; then
1114 echo "got merge succeeded unexpectedly" >&2
1115 test_done "$testroot" "$ret"
1116 return 1
1119 echo -n "got: merge of refs/heads/newbranch cannot proceed: " \
1120 > $testroot/stderr.expected
1121 echo "no changes to commit" >> $testroot/stderr.expected
1122 cmp -s $testroot/stderr.expected $testroot/stderr
1123 ret="$?"
1124 if [ "$ret" != "0" ]; then
1125 diff -u $testroot/stderr.expected $testroot/stderr
1126 test_done "$testroot" "$ret"
1127 return 1
1130 (cd $testroot/wt && got status > $testroot/stdout)
1132 echo -n "" > $testroot/stdout.expected
1133 cmp -s $testroot/stdout.expected $testroot/stdout
1134 ret="$?"
1135 if [ "$ret" != "0" ]; then
1136 diff -u $testroot/stdout.expected $testroot/stdout
1138 test_done "$testroot" "$ret"
1141 test_merge_imported_branch() {
1142 local testroot=`test_init merge_import`
1143 local commit0=`git_show_head $testroot/repo`
1144 local commit0_author_time=`git_show_author_time $testroot/repo`
1146 # import a new sub-tree to the 'files' branch such that
1147 # none of the files added here collide with existing ones
1148 mkdir -p $testroot/tree/there
1149 mkdir -p $testroot/tree/be/lots
1150 mkdir -p $testroot/tree/files
1151 echo "there should" > $testroot/tree/there/should
1152 echo "be lots of" > $testroot/tree/be/lots/of
1153 echo "files here" > $testroot/tree/files/here
1154 got import -r $testroot/repo -b files -m 'import files' \
1155 $testroot/tree > /dev/null
1157 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1158 ret="$?"
1159 if [ "$ret" != "0" ]; then
1160 echo "got checkout failed unexpectedly" >&2
1161 test_done "$testroot" "$ret"
1162 return 1
1165 (cd $testroot/wt && got merge files > $testroot/stdout)
1166 ret="$?"
1167 if [ "$ret" != "0" ]; then
1168 echo "got merge failed unexpectedly" >&2
1169 test_done "$testroot" "$ret"
1170 return 1
1173 local merge_commit0=`git_show_head $testroot/repo`
1174 cat > $testroot/stdout.expected <<EOF
1175 A be/lots/of
1176 A files/here
1177 A there/should
1178 Merged refs/heads/files into refs/heads/master: $merge_commit0
1179 EOF
1180 cmp -s $testroot/stdout.expected $testroot/stdout
1181 ret="$?"
1182 if [ "$ret" != "0" ]; then
1183 diff -u $testroot/stdout.expected $testroot/stdout
1184 test_done "$testroot" "$ret"
1185 return 1
1188 # try to merge again while no new changes are available
1189 (cd $testroot/wt && got merge files > $testroot/stdout)
1190 ret="$?"
1191 if [ "$ret" != "0" ]; then
1192 echo "got merge failed unexpectedly" >&2
1193 test_done "$testroot" "$ret"
1194 return 1
1196 echo "Already up-to-date" > $testroot/stdout.expected
1197 cmp -s $testroot/stdout.expected $testroot/stdout
1198 ret="$?"
1199 if [ "$ret" != "0" ]; then
1200 diff -u $testroot/stdout.expected $testroot/stdout
1201 test_done "$testroot" "$ret"
1202 return 1
1205 # update the 'files' branch
1206 (cd $testroot/repo && git reset -q --hard master)
1207 (cd $testroot/repo && git checkout -q files)
1208 echo "indeed" > $testroot/repo/indeed
1209 (cd $testroot/repo && git add indeed)
1210 git_commit $testroot/repo -m "adding another file indeed"
1211 echo "be lots and lots of" > $testroot/repo/be/lots/of
1212 git_commit $testroot/repo -m "lots of changes"
1214 (cd $testroot/wt && got update > /dev/null)
1215 ret="$?"
1216 if [ "$ret" != "0" ]; then
1217 echo "got update failed unexpectedly" >&2
1218 test_done "$testroot" "$ret"
1219 return 1
1222 # we should now be able to merge more changes from files branch
1223 (cd $testroot/wt && got merge files > $testroot/stdout)
1224 ret="$?"
1225 if [ "$ret" != "0" ]; then
1226 echo "got merge failed unexpectedly" >&2
1227 test_done "$testroot" "$ret"
1228 return 1
1231 local merge_commit1=`git_show_branch_head $testroot/repo master`
1232 cat > $testroot/stdout.expected <<EOF
1233 G be/lots/of
1234 A indeed
1235 Merged refs/heads/files into refs/heads/master: $merge_commit1
1236 EOF
1238 cmp -s $testroot/stdout.expected $testroot/stdout
1239 ret="$?"
1240 if [ "$ret" != "0" ]; then
1241 diff -u $testroot/stdout.expected $testroot/stdout
1243 test_done "$testroot" "$ret"
1246 test_merge_interrupt() {
1247 local testroot=`test_init merge_interrupt`
1248 local commit0=`git_show_head $testroot/repo`
1249 local commit0_author_time=`git_show_author_time $testroot/repo`
1251 (cd $testroot/repo && git checkout -q -b newbranch)
1252 echo "modified alpha on branch" > $testroot/repo/alpha
1253 git_commit $testroot/repo -m "committing to alpha on newbranch"
1254 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1256 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1257 ret="$?"
1258 if [ "$ret" != "0" ]; then
1259 echo "got checkout failed unexpectedly" >&2
1260 test_done "$testroot" "$ret"
1261 return 1
1264 # create a non-conflicting commit
1265 (cd $testroot/repo && git checkout -q master)
1266 echo "modified beta on master" > $testroot/repo/beta
1267 git_commit $testroot/repo -m "committing to beta on master"
1268 local master_commit=`git_show_head $testroot/repo`
1270 # need an up-to-date work tree for 'got merge'
1271 (cd $testroot/wt && got update > /dev/null)
1272 ret="$?"
1273 if [ "$ret" != "0" ]; then
1274 echo "got update failed unexpectedly" >&2
1275 test_done "$testroot" "$ret"
1276 return 1
1279 (cd $testroot/wt && got merge -n newbranch \
1280 > $testroot/stdout 2> $testroot/stderr)
1281 ret="$?"
1282 if [ "$ret" != "0" ]; then
1283 echo "got merge failed unexpectedly" >&2
1284 test_done "$testroot" "1"
1285 return 1
1288 echo "G alpha" > $testroot/stdout.expected
1289 echo "Merge of refs/heads/newbranch interrupted on request" \
1290 >> $testroot/stdout.expected
1291 cmp -s $testroot/stdout.expected $testroot/stdout
1292 ret="$?"
1293 if [ "$ret" != "0" ]; then
1294 diff -u $testroot/stdout.expected $testroot/stdout
1295 test_done "$testroot" "$ret"
1296 return 1
1299 (cd $testroot/wt && got status > $testroot/stdout)
1301 echo "M alpha" > $testroot/stdout.expected
1302 cmp -s $testroot/stdout.expected $testroot/stdout
1303 ret="$?"
1304 if [ "$ret" != "0" ]; then
1305 diff -u $testroot/stdout.expected $testroot/stdout
1306 test_done "$testroot" "$ret"
1307 return 1
1310 echo "modified alpha on branch" > $testroot/content.expected
1311 cat $testroot/wt/alpha > $testroot/content
1312 cmp -s $testroot/content.expected $testroot/content
1313 ret="$?"
1314 if [ "$ret" != "0" ]; then
1315 diff -u $testroot/content.expected $testroot/content
1316 test_done "$testroot" "$ret"
1317 return 1
1320 # adjust merge result
1321 echo "adjusted merge result" > $testroot/wt/alpha
1323 # continue the merge
1324 (cd $testroot/wt && got merge -c > $testroot/stdout)
1325 ret="$?"
1326 if [ "$ret" != "0" ]; then
1327 echo "got merge failed unexpectedly" >&2
1328 test_done "$testroot" "$ret"
1329 return 1
1332 local merge_commit=`git_show_head $testroot/repo`
1334 echo "M alpha" > $testroot/stdout.expected
1335 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1336 >> $testroot/stdout.expected
1337 echo $merge_commit >> $testroot/stdout.expected
1339 cmp -s $testroot/stdout.expected $testroot/stdout
1340 ret="$?"
1341 if [ "$ret" != "0" ]; then
1342 diff -u $testroot/stdout.expected $testroot/stdout
1343 test_done "$testroot" "$ret"
1344 return 1
1347 (cd $testroot/wt && got status > $testroot/stdout)
1349 echo -n > $testroot/stdout.expected
1350 cmp -s $testroot/stdout.expected $testroot/stdout
1351 ret="$?"
1352 if [ "$ret" != "0" ]; then
1353 diff -u $testroot/stdout.expected $testroot/stdout
1354 test_done "$testroot" "$ret"
1355 return 1
1358 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1359 echo "commit $merge_commit (master)" > $testroot/stdout.expected
1360 echo "commit $master_commit" >> $testroot/stdout.expected
1361 echo "commit $commit0" >> $testroot/stdout.expected
1362 cmp -s $testroot/stdout.expected $testroot/stdout
1363 ret="$?"
1364 if [ "$ret" != "0" ]; then
1365 diff -u $testroot/stdout.expected $testroot/stdout
1366 test_done "$testroot" "$ret"
1367 return 1
1370 (cd $testroot/wt && got update > $testroot/stdout)
1372 echo 'Already up-to-date' > $testroot/stdout.expected
1373 cmp -s $testroot/stdout.expected $testroot/stdout
1374 ret="$?"
1375 if [ "$ret" != "0" ]; then
1376 diff -u $testroot/stdout.expected $testroot/stdout
1377 test_done "$testroot" "$ret"
1378 return 1
1381 # We should have created a merge commit with two parents.
1382 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
1383 echo "parent 1: $master_commit" > $testroot/stdout.expected
1384 echo "parent 2: $branch_commit0" >> $testroot/stdout.expected
1385 cmp -s $testroot/stdout.expected $testroot/stdout
1386 ret="$?"
1387 if [ "$ret" != "0" ]; then
1388 diff -u $testroot/stdout.expected $testroot/stdout
1390 test_done "$testroot" "$ret"
1393 test_parseargs "$@"
1394 run_test test_merge_basic
1395 run_test test_merge_continue
1396 run_test test_merge_abort
1397 run_test test_merge_in_progress
1398 run_test test_merge_path_prefix
1399 run_test test_merge_missing_file
1400 run_test test_merge_no_op
1401 run_test test_merge_imported_branch
1402 run_test test_merge_interrupt