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`
43 got checkout -b master $testroot/repo $testroot/wt > /dev/null
44 ret="$?"
45 if [ "$ret" != "0" ]; then
46 echo "got checkout failed unexpectedly" >&2
47 test_done "$testroot" "$ret"
48 return 1
49 fi
51 # need a divergant commit on the main branch for 'got merge'
52 (cd $testroot/wt && got merge newbranch \
53 > $testroot/stdout 2> $testroot/stderr)
54 ret="$?"
55 if [ "$ret" == "0" ]; then
56 echo "got merge succeeded unexpectedly" >&2
57 test_done "$testroot" "1"
58 return 1
59 fi
60 echo -n "got: cannot create a merge commit because " \
61 > $testroot/stderr.expected
62 echo -n "refs/heads/newbranch is based on refs/heads/master; " \
63 >> $testroot/stderr.expected
64 echo -n "refs/heads/newbranch can be integrated with " \
65 >> $testroot/stderr.expected
66 echo "'got integrate' instead" >> $testroot/stderr.expected
67 cmp -s $testroot/stderr.expected $testroot/stderr
68 ret="$?"
69 if [ "$ret" != "0" ]; then
70 diff -u $testroot/stderr.expected $testroot/stderr
71 test_done "$testroot" "$ret"
72 return 1
73 fi
75 # create the required dirvergant commit
76 (cd $testroot/repo && git checkout -q master)
77 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
78 git_commit $testroot/repo -m "committing to zeta on master"
79 local master_commit=`git_show_head $testroot/repo`
81 # need an up-to-date work tree for 'got merge'
82 (cd $testroot/wt && got merge newbranch \
83 > $testroot/stdout 2> $testroot/stderr)
84 ret="$?"
85 if [ "$ret" == "0" ]; then
86 echo "got merge succeeded unexpectedly" >&2
87 test_done "$testroot" "$ret"
88 return 1
89 fi
90 echo -n "got: work tree must be updated before it can be used " \
91 > $testroot/stderr.expected
92 echo "to merge a branch" >> $testroot/stderr.expected
93 cmp -s $testroot/stderr.expected $testroot/stderr
94 ret="$?"
95 if [ "$ret" != "0" ]; then
96 diff -u $testroot/stderr.expected $testroot/stderr
97 test_done "$testroot" "$ret"
98 return 1
99 fi
101 (cd $testroot/wt && got update > /dev/null)
102 ret="$?"
103 if [ "$ret" != "0" ]; then
104 echo "got update failed unexpectedly" >&2
105 test_done "$testroot" "$ret"
106 return 1
107 fi
109 # must not use a mixed-commit work tree with 'got merge'
110 (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
111 ret="$?"
112 if [ "$ret" != "0" ]; then
113 echo "got update failed unexpectedly" >&2
114 test_done "$testroot" "$ret"
115 return 1
116 fi
117 (cd $testroot/wt && got merge newbranch \
118 > $testroot/stdout 2> $testroot/stderr)
119 ret="$?"
120 if [ "$ret" == "0" ]; then
121 echo "got merge succeeded unexpectedly" >&2
122 test_done "$testroot" "$ret"
123 return 1
124 fi
125 echo -n "got: work tree contains files from multiple base commits; " \
126 > $testroot/stderr.expected
127 echo "the entire work tree must be updated first" \
128 >> $testroot/stderr.expected
129 cmp -s $testroot/stderr.expected $testroot/stderr
130 ret="$?"
131 if [ "$ret" != "0" ]; then
132 diff -u $testroot/stderr.expected $testroot/stderr
133 test_done "$testroot" "$ret"
134 return 1
135 fi
137 (cd $testroot/wt && got update > /dev/null)
138 ret="$?"
139 if [ "$ret" != "0" ]; then
140 echo "got update failed unexpectedly" >&2
141 test_done "$testroot" "$ret"
142 return 1
143 fi
145 # must not have staged files with 'got merge'
146 echo "modified file alpha" > $testroot/wt/alpha
147 (cd $testroot/wt && got stage alpha > /dev/null)
148 ret="$?"
149 if [ "$ret" != "0" ]; then
150 echo "got stage failed unexpectedly" >&2
151 test_done "$testroot" "$ret"
152 return 1
153 fi
154 (cd $testroot/wt && got merge newbranch \
155 > $testroot/stdout 2> $testroot/stderr)
156 ret="$?"
157 if [ "$ret" == "0" ]; then
158 echo "got merge succeeded unexpectedly" >&2
159 test_done "$testroot" "$ret"
160 return 1
161 fi
162 echo "got: alpha: file is staged" > $testroot/stderr.expected
163 cmp -s $testroot/stderr.expected $testroot/stderr
164 ret="$?"
165 if [ "$ret" != "0" ]; then
166 diff -u $testroot/stderr.expected $testroot/stderr
167 test_done "$testroot" "$ret"
168 return 1
169 fi
170 (cd $testroot/wt && got unstage alpha > /dev/null)
171 ret="$?"
172 if [ "$ret" != "0" ]; then
173 echo "got unstage failed unexpectedly" >&2
174 test_done "$testroot" "$ret"
175 return 1
176 fi
178 # must not have local changes with 'got merge'
179 (cd $testroot/wt && got merge newbranch \
180 > $testroot/stdout 2> $testroot/stderr)
181 ret="$?"
182 if [ "$ret" == "0" ]; then
183 echo "got merge succeeded unexpectedly" >&2
184 test_done "$testroot" "$ret"
185 return 1
186 fi
187 echo -n "got: work tree contains local changes; " \
188 > $testroot/stderr.expected
189 echo "these changes must be committed or reverted first" \
190 >> $testroot/stderr.expected
191 cmp -s $testroot/stderr.expected $testroot/stderr
192 ret="$?"
193 if [ "$ret" != "0" ]; then
194 diff -u $testroot/stderr.expected $testroot/stderr
195 test_done "$testroot" "$ret"
196 return 1
197 fi
199 (cd $testroot/wt && got revert alpha > /dev/null)
200 ret="$?"
201 if [ "$ret" != "0" ]; then
202 echo "got revert failed unexpectedly" >&2
203 test_done "$testroot" "$ret"
204 return 1
205 fi
207 (cd $testroot/wt && got merge newbranch > $testroot/stdout)
208 ret="$?"
209 if [ "$ret" != "0" ]; then
210 echo "got merge failed unexpectedly" >&2
211 test_done "$testroot" "$ret"
212 return 1
213 fi
215 local merge_commit=`git_show_head $testroot/repo`
217 echo "G alpha" >> $testroot/stdout.expected
218 echo "D beta" >> $testroot/stdout.expected
219 echo "A epsilon/new" >> $testroot/stdout.expected
220 echo "G gamma/delta" >> $testroot/stdout.expected
221 echo "A symlink" >> $testroot/stdout.expected
222 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
223 >> $testroot/stdout.expected
224 echo $merge_commit >> $testroot/stdout.expected
226 cmp -s $testroot/stdout.expected $testroot/stdout
227 ret="$?"
228 if [ "$ret" != "0" ]; then
229 diff -u $testroot/stdout.expected $testroot/stdout
230 test_done "$testroot" "$ret"
231 return 1
232 fi
234 echo "modified delta on branch" > $testroot/content.expected
235 cat $testroot/wt/gamma/delta > $testroot/content
236 cmp -s $testroot/content.expected $testroot/content
237 ret="$?"
238 if [ "$ret" != "0" ]; then
239 diff -u $testroot/content.expected $testroot/content
240 test_done "$testroot" "$ret"
241 return 1
242 fi
244 echo "modified alpha on branch" > $testroot/content.expected
245 cat $testroot/wt/alpha > $testroot/content
246 cmp -s $testroot/content.expected $testroot/content
247 ret="$?"
248 if [ "$ret" != "0" ]; then
249 diff -u $testroot/content.expected $testroot/content
250 test_done "$testroot" "$ret"
251 return 1
252 fi
254 if [ -e $testroot/wt/beta ]; then
255 echo "removed file beta still exists on disk" >&2
256 test_done "$testroot" "1"
257 return 1
258 fi
260 echo "new file on branch" > $testroot/content.expected
261 cat $testroot/wt/epsilon/new > $testroot/content
262 cmp -s $testroot/content.expected $testroot/content
263 ret="$?"
264 if [ "$ret" != "0" ]; then
265 diff -u $testroot/content.expected $testroot/content
266 test_done "$testroot" "$ret"
267 return 1
268 fi
270 readlink $testroot/wt/symlink > $testroot/stdout
271 echo "alpha" > $testroot/stdout.expected
272 cmp -s $testroot/stdout.expected $testroot/stdout
273 ret="$?"
274 if [ "$ret" != "0" ]; then
275 diff -u $testroot/stdout.expected $testroot/stdout
276 test_done "$testroot" "$ret"
277 return 1
278 fi
280 (cd $testroot/wt && got status > $testroot/stdout)
282 echo -n > $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 log -l3 | grep ^commit > $testroot/stdout)
292 echo "commit $merge_commit (master)" > $testroot/stdout.expected
293 echo "commit $master_commit" >> $testroot/stdout.expected
294 echo "commit $commit0" >> $testroot/stdout.expected
295 cmp -s $testroot/stdout.expected $testroot/stdout
296 ret="$?"
297 if [ "$ret" != "0" ]; then
298 diff -u $testroot/stdout.expected $testroot/stdout
299 test_done "$testroot" "$ret"
300 return 1
301 fi
303 (cd $testroot/wt && got update > $testroot/stdout)
305 echo 'Already up-to-date' > $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 # We should have created a merge commit with two parents.
315 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
316 echo "parent 1: $master_commit" > $testroot/stdout.expected
317 echo "parent 2: $branch_commit4" >> $testroot/stdout.expected
318 cmp -s $testroot/stdout.expected $testroot/stdout
319 ret="$?"
320 if [ "$ret" != "0" ]; then
321 diff -u $testroot/stdout.expected $testroot/stdout
322 fi
323 test_done "$testroot" "$ret"
326 test_merge_continue() {
327 local testroot=`test_init merge_continue`
328 local commit0=`git_show_head $testroot/repo`
329 local commit0_author_time=`git_show_author_time $testroot/repo`
331 (cd $testroot/repo && git checkout -q -b newbranch)
332 echo "modified delta on branch" > $testroot/repo/gamma/delta
333 git_commit $testroot/repo -m "committing to delta on newbranch"
334 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
336 echo "modified alpha on branch" > $testroot/repo/alpha
337 git_commit $testroot/repo -m "committing to alpha on newbranch"
338 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
339 (cd $testroot/repo && git rm -q beta)
340 git_commit $testroot/repo -m "removing beta on newbranch"
341 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
342 echo "new file on branch" > $testroot/repo/epsilon/new
343 (cd $testroot/repo && git add epsilon/new)
344 git_commit $testroot/repo -m "adding new file on newbranch"
345 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
347 got checkout -b master $testroot/repo $testroot/wt > /dev/null
348 ret="$?"
349 if [ "$ret" != "0" ]; then
350 echo "got checkout failed unexpectedly" >&2
351 test_done "$testroot" "$ret"
352 return 1
353 fi
355 # create a conflicting commit
356 (cd $testroot/repo && git checkout -q master)
357 echo "modified alpha on master" > $testroot/repo/alpha
358 git_commit $testroot/repo -m "committing to alpha on master"
359 local master_commit=`git_show_head $testroot/repo`
361 # need an up-to-date work tree for 'got merge'
362 (cd $testroot/wt && got update > /dev/null)
363 ret="$?"
364 if [ "$ret" != "0" ]; then
365 echo "got update failed unexpectedly" >&2
366 test_done "$testroot" "$ret"
367 return 1
368 fi
370 (cd $testroot/wt && got merge newbranch \
371 > $testroot/stdout 2> $testroot/stderr)
372 ret="$?"
373 if [ "$ret" == "0" ]; then
374 echo "got merge succeeded unexpectedly" >&2
375 test_done "$testroot" "1"
376 return 1
377 fi
379 echo "C alpha" >> $testroot/stdout.expected
380 echo "D beta" >> $testroot/stdout.expected
381 echo "A epsilon/new" >> $testroot/stdout.expected
382 echo "G gamma/delta" >> $testroot/stdout.expected
383 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
384 cmp -s $testroot/stdout.expected $testroot/stdout
385 ret="$?"
386 if [ "$ret" != "0" ]; then
387 diff -u $testroot/stdout.expected $testroot/stdout
388 test_done "$testroot" "$ret"
389 return 1
390 fi
392 echo "got: conflicts must be resolved before merging can continue" \
393 > $testroot/stderr.expected
394 cmp -s $testroot/stderr.expected $testroot/stderr
395 ret="$?"
396 if [ "$ret" != "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 status > $testroot/stdout)
404 echo "C alpha" > $testroot/stdout.expected
405 echo "D beta" >> $testroot/stdout.expected
406 echo "A epsilon/new" >> $testroot/stdout.expected
407 echo "M gamma/delta" >> $testroot/stdout.expected
408 cmp -s $testroot/stdout.expected $testroot/stdout
409 ret="$?"
410 if [ "$ret" != "0" ]; then
411 diff -u $testroot/stdout.expected $testroot/stdout
412 test_done "$testroot" "$ret"
413 return 1
414 fi
416 echo '<<<<<<<' > $testroot/content.expected
417 echo "modified alpha on master" >> $testroot/content.expected
418 echo "||||||| 3-way merge base: commit $commit0" \
419 >> $testroot/content.expected
420 echo "alpha" >> $testroot/content.expected
421 echo "=======" >> $testroot/content.expected
422 echo "modified alpha on branch" >> $testroot/content.expected
423 echo ">>>>>>> merged change: commit $branch_commit3" \
424 >> $testroot/content.expected
425 cat $testroot/wt/alpha > $testroot/content
426 cmp -s $testroot/content.expected $testroot/content
427 ret="$?"
428 if [ "$ret" != "0" ]; then
429 diff -u $testroot/content.expected $testroot/content
430 test_done "$testroot" "$ret"
431 return 1
432 fi
434 # resolve the conflict
435 echo "modified alpha by both branches" > $testroot/wt/alpha
437 (cd $testroot/wt && got merge -c > $testroot/stdout)
438 ret="$?"
439 if [ "$ret" != "0" ]; then
440 echo "got merge failed unexpectedly" >&2
441 test_done "$testroot" "$ret"
442 return 1
443 fi
445 local merge_commit=`git_show_head $testroot/repo`
447 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
448 > $testroot/stdout.expected
449 echo $merge_commit >> $testroot/stdout.expected
451 cmp -s $testroot/stdout.expected $testroot/stdout
452 ret="$?"
453 if [ "$ret" != "0" ]; then
454 diff -u $testroot/stdout.expected $testroot/stdout
455 test_done "$testroot" "$ret"
456 return 1
457 fi
459 echo "modified delta on branch" > $testroot/content.expected
460 cat $testroot/wt/gamma/delta > $testroot/content
461 cmp -s $testroot/content.expected $testroot/content
462 ret="$?"
463 if [ "$ret" != "0" ]; then
464 diff -u $testroot/content.expected $testroot/content
465 test_done "$testroot" "$ret"
466 return 1
467 fi
469 echo "modified alpha by both branches" > $testroot/content.expected
470 cat $testroot/wt/alpha > $testroot/content
471 cmp -s $testroot/content.expected $testroot/content
472 ret="$?"
473 if [ "$ret" != "0" ]; then
474 diff -u $testroot/content.expected $testroot/content
475 test_done "$testroot" "$ret"
476 return 1
477 fi
479 if [ -e $testroot/wt/beta ]; then
480 echo "removed file beta still exists on disk" >&2
481 test_done "$testroot" "1"
482 return 1
483 fi
485 echo "new file on branch" > $testroot/content.expected
486 cat $testroot/wt/epsilon/new > $testroot/content
487 cmp -s $testroot/content.expected $testroot/content
488 ret="$?"
489 if [ "$ret" != "0" ]; then
490 diff -u $testroot/content.expected $testroot/content
491 test_done "$testroot" "$ret"
492 return 1
493 fi
495 (cd $testroot/wt && got status > $testroot/stdout)
497 echo -n > $testroot/stdout.expected
498 cmp -s $testroot/stdout.expected $testroot/stdout
499 ret="$?"
500 if [ "$ret" != "0" ]; then
501 diff -u $testroot/stdout.expected $testroot/stdout
502 test_done "$testroot" "$ret"
503 return 1
504 fi
506 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
507 echo "commit $merge_commit (master)" > $testroot/stdout.expected
508 echo "commit $master_commit" >> $testroot/stdout.expected
509 echo "commit $commit0" >> $testroot/stdout.expected
510 cmp -s $testroot/stdout.expected $testroot/stdout
511 ret="$?"
512 if [ "$ret" != "0" ]; then
513 diff -u $testroot/stdout.expected $testroot/stdout
514 test_done "$testroot" "$ret"
515 return 1
516 fi
518 (cd $testroot/wt && got update > $testroot/stdout)
520 echo 'Already up-to-date' > $testroot/stdout.expected
521 cmp -s $testroot/stdout.expected $testroot/stdout
522 ret="$?"
523 if [ "$ret" != "0" ]; then
524 diff -u $testroot/stdout.expected $testroot/stdout
525 test_done "$testroot" "$ret"
526 return 1
527 fi
529 # We should have created a merge commit with two parents.
530 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
531 echo "parent 1: $master_commit" > $testroot/stdout.expected
532 echo "parent 2: $branch_commit3" >> $testroot/stdout.expected
533 cmp -s $testroot/stdout.expected $testroot/stdout
534 ret="$?"
535 if [ "$ret" != "0" ]; then
536 diff -u $testroot/stdout.expected $testroot/stdout
537 fi
538 test_done "$testroot" "$ret"
541 test_merge_abort() {
542 local testroot=`test_init merge_abort`
543 local commit0=`git_show_head $testroot/repo`
544 local commit0_author_time=`git_show_author_time $testroot/repo`
546 (cd $testroot/repo && git checkout -q -b newbranch)
547 echo "modified delta on branch" > $testroot/repo/gamma/delta
548 git_commit $testroot/repo -m "committing to delta on newbranch"
549 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
551 echo "modified alpha on branch" > $testroot/repo/alpha
552 git_commit $testroot/repo -m "committing to alpha on newbranch"
553 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
554 (cd $testroot/repo && git rm -q beta)
555 git_commit $testroot/repo -m "removing beta on newbranch"
556 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
557 echo "new file on branch" > $testroot/repo/epsilon/new
558 (cd $testroot/repo && git add epsilon/new)
559 git_commit $testroot/repo -m "adding new file on newbranch"
560 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
561 (cd $testroot/repo && ln -s alpha symlink && git add symlink)
562 git_commit $testroot/repo -m "adding symlink on newbranch"
563 local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
565 got checkout -b master $testroot/repo $testroot/wt > /dev/null
566 ret="$?"
567 if [ "$ret" != "0" ]; then
568 echo "got checkout failed unexpectedly" >&2
569 test_done "$testroot" "$ret"
570 return 1
571 fi
573 # create a conflicting commit
574 (cd $testroot/repo && git checkout -q master)
575 echo "modified alpha on master" > $testroot/repo/alpha
576 git_commit $testroot/repo -m "committing to alpha on master"
577 local master_commit=`git_show_head $testroot/repo`
579 # need an up-to-date work tree for 'got merge'
580 (cd $testroot/wt && got update > /dev/null)
581 ret="$?"
582 if [ "$ret" != "0" ]; then
583 echo "got update failed unexpectedly" >&2
584 test_done "$testroot" "$ret"
585 return 1
586 fi
588 (cd $testroot/wt && got merge newbranch \
589 > $testroot/stdout 2> $testroot/stderr)
590 ret="$?"
591 if [ "$ret" == "0" ]; then
592 echo "got merge succeeded unexpectedly" >&2
593 test_done "$testroot" "1"
594 return 1
595 fi
597 echo "C alpha" >> $testroot/stdout.expected
598 echo "D beta" >> $testroot/stdout.expected
599 echo "A epsilon/new" >> $testroot/stdout.expected
600 echo "G gamma/delta" >> $testroot/stdout.expected
601 echo "A symlink" >> $testroot/stdout.expected
602 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
603 cmp -s $testroot/stdout.expected $testroot/stdout
604 ret="$?"
605 if [ "$ret" != "0" ]; then
606 diff -u $testroot/stdout.expected $testroot/stdout
607 test_done "$testroot" "$ret"
608 return 1
609 fi
611 echo "got: conflicts must be resolved before merging can continue" \
612 > $testroot/stderr.expected
613 cmp -s $testroot/stderr.expected $testroot/stderr
614 ret="$?"
615 if [ "$ret" != "0" ]; then
616 diff -u $testroot/stderr.expected $testroot/stderr
617 test_done "$testroot" "$ret"
618 return 1
619 fi
621 (cd $testroot/wt && got status > $testroot/stdout)
623 echo "C alpha" > $testroot/stdout.expected
624 echo "D beta" >> $testroot/stdout.expected
625 echo "A epsilon/new" >> $testroot/stdout.expected
626 echo "M gamma/delta" >> $testroot/stdout.expected
627 echo "A symlink" >> $testroot/stdout.expected
628 cmp -s $testroot/stdout.expected $testroot/stdout
629 ret="$?"
630 if [ "$ret" != "0" ]; then
631 diff -u $testroot/stdout.expected $testroot/stdout
632 test_done "$testroot" "$ret"
633 return 1
634 fi
636 (cd $testroot/wt && got merge -a > $testroot/stdout)
637 ret="$?"
638 if [ "$ret" != "0" ]; then
639 echo "got merge failed unexpectedly" >&2
640 test_done "$testroot" "$ret"
641 return 1
642 fi
644 echo "R alpha" > $testroot/stdout.expected
645 echo "R beta" >> $testroot/stdout.expected
646 echo "R epsilon/new" >> $testroot/stdout.expected
647 echo "R gamma/delta" >> $testroot/stdout.expected
648 echo "R symlink" >> $testroot/stdout.expected
649 echo "Merge of refs/heads/newbranch aborted" \
650 >> $testroot/stdout.expected
652 cmp -s $testroot/stdout.expected $testroot/stdout
653 ret="$?"
654 if [ "$ret" != "0" ]; then
655 diff -u $testroot/stdout.expected $testroot/stdout
656 test_done "$testroot" "$ret"
657 return 1
658 fi
660 echo "delta" > $testroot/content.expected
661 cat $testroot/wt/gamma/delta > $testroot/content
662 cmp -s $testroot/content.expected $testroot/content
663 ret="$?"
664 if [ "$ret" != "0" ]; then
665 diff -u $testroot/content.expected $testroot/content
666 test_done "$testroot" "$ret"
667 return 1
668 fi
670 echo "modified alpha on master" > $testroot/content.expected
671 cat $testroot/wt/alpha > $testroot/content
672 cmp -s $testroot/content.expected $testroot/content
673 ret="$?"
674 if [ "$ret" != "0" ]; then
675 diff -u $testroot/content.expected $testroot/content
676 test_done "$testroot" "$ret"
677 return 1
678 fi
680 echo "beta" > $testroot/content.expected
681 cat $testroot/wt/beta > $testroot/content
682 cmp -s $testroot/content.expected $testroot/content
683 ret="$?"
684 if [ "$ret" != "0" ]; then
685 diff -u $testroot/content.expected $testroot/content
686 test_done "$testroot" "$ret"
687 return 1
688 fi
690 if [ -e $testroot/wt/epsilon/new ]; then
691 echo "reverted file epsilon/new still exists on disk" >&2
692 test_done "$testroot" "1"
693 return 1
694 fi
696 if [ -e $testroot/wt/symlink ]; then
697 echo "reverted symlink still exists on disk" >&2
698 test_done "$testroot" "1"
699 return 1
700 fi
702 (cd $testroot/wt && got status > $testroot/stdout)
704 echo -n "" > $testroot/stdout.expected
705 cmp -s $testroot/stdout.expected $testroot/stdout
706 ret="$?"
707 if [ "$ret" != "0" ]; then
708 diff -u $testroot/stdout.expected $testroot/stdout
709 test_done "$testroot" "$ret"
710 return 1
711 fi
713 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
714 echo "commit $master_commit (master)" > $testroot/stdout.expected
715 echo "commit $commit0" >> $testroot/stdout.expected
716 cmp -s $testroot/stdout.expected $testroot/stdout
717 ret="$?"
718 if [ "$ret" != "0" ]; then
719 diff -u $testroot/stdout.expected $testroot/stdout
720 test_done "$testroot" "$ret"
721 return 1
722 fi
724 (cd $testroot/wt && got update > $testroot/stdout)
726 echo 'Already up-to-date' > $testroot/stdout.expected
727 cmp -s $testroot/stdout.expected $testroot/stdout
728 ret="$?"
729 if [ "$ret" != "0" ]; then
730 diff -u $testroot/stdout.expected $testroot/stdout
731 fi
732 test_done "$testroot" "$ret"
735 test_merge_in_progress() {
736 local testroot=`test_init merge_in_progress`
737 local commit0=`git_show_head $testroot/repo`
738 local commit0_author_time=`git_show_author_time $testroot/repo`
740 (cd $testroot/repo && git checkout -q -b newbranch)
741 echo "modified alpha on branch" > $testroot/repo/alpha
742 git_commit $testroot/repo -m "committing to alpha on newbranch"
743 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
745 got checkout -b master $testroot/repo $testroot/wt > /dev/null
746 ret="$?"
747 if [ "$ret" != "0" ]; then
748 echo "got checkout failed unexpectedly" >&2
749 test_done "$testroot" "$ret"
750 return 1
751 fi
753 # create a conflicting commit
754 (cd $testroot/repo && git checkout -q master)
755 echo "modified alpha on master" > $testroot/repo/alpha
756 git_commit $testroot/repo -m "committing to alpha on master"
757 local master_commit=`git_show_head $testroot/repo`
759 # need an up-to-date work tree for 'got merge'
760 (cd $testroot/wt && got update > /dev/null)
761 ret="$?"
762 if [ "$ret" != "0" ]; then
763 echo "got update failed unexpectedly" >&2
764 test_done "$testroot" "$ret"
765 return 1
766 fi
768 (cd $testroot/wt && got merge newbranch \
769 > $testroot/stdout 2> $testroot/stderr)
770 ret="$?"
771 if [ "$ret" == "0" ]; then
772 echo "got merge succeeded unexpectedly" >&2
773 test_done "$testroot" "1"
774 return 1
775 fi
777 echo "C alpha" >> $testroot/stdout.expected
778 echo "Files with new merge conflicts: 1" >> $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 test_done "$testroot" "$ret"
784 return 1
785 fi
787 echo "got: conflicts must be resolved before merging can continue" \
788 > $testroot/stderr.expected
789 cmp -s $testroot/stderr.expected $testroot/stderr
790 ret="$?"
791 if [ "$ret" != "0" ]; then
792 diff -u $testroot/stderr.expected $testroot/stderr
793 test_done "$testroot" "$ret"
794 return 1
795 fi
797 (cd $testroot/wt && got status > $testroot/stdout)
799 echo "C alpha" > $testroot/stdout.expected
800 cmp -s $testroot/stdout.expected $testroot/stdout
801 ret="$?"
802 if [ "$ret" != "0" ]; then
803 diff -u $testroot/stdout.expected $testroot/stdout
804 test_done "$testroot" "$ret"
805 return 1
806 fi
808 for cmd in update commit histedit "rebase newbranch" \
809 "integrate newbranch" "stage alpha"; do
810 (cd $testroot/wt && got $cmd > $testroot/stdout \
811 2> $testroot/stderr)
813 echo -n > $testroot/stdout.expected
814 cmp -s $testroot/stdout.expected $testroot/stdout
815 ret="$?"
816 if [ "$ret" != "0" ]; then
817 diff -u $testroot/stdout.expected $testroot/stdout
818 test_done "$testroot" "$ret"
819 return 1
820 fi
822 echo -n "got: a merge operation is in progress in this " \
823 > $testroot/stderr.expected
824 echo "work tree and must be continued or aborted first" \
825 >> $testroot/stderr.expected
826 cmp -s $testroot/stderr.expected $testroot/stderr
827 ret="$?"
828 if [ "$ret" != "0" ]; then
829 diff -u $testroot/stderr.expected $testroot/stderr
830 test_done "$testroot" "$ret"
831 return 1
832 fi
833 done
835 test_done "$testroot" "$ret"
838 test_merge_path_prefix() {
839 local testroot=`test_init merge_path_prefix`
840 local commit0=`git_show_head $testroot/repo`
841 local commit0_author_time=`git_show_author_time $testroot/repo`
843 (cd $testroot/repo && git checkout -q -b newbranch)
844 echo "modified alpha on branch" > $testroot/repo/alpha
845 git_commit $testroot/repo -m "committing to alpha on newbranch"
846 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
848 got checkout -p epsilon -b master $testroot/repo $testroot/wt \
849 > /dev/null
850 ret="$?"
851 if [ "$ret" != "0" ]; then
852 echo "got checkout failed unexpectedly" >&2
853 test_done "$testroot" "$ret"
854 return 1
855 fi
857 # create a conflicting commit
858 (cd $testroot/repo && git checkout -q master)
859 echo "modified alpha on master" > $testroot/repo/alpha
860 git_commit $testroot/repo -m "committing to alpha on master"
861 local master_commit=`git_show_head $testroot/repo`
863 # need an up-to-date work tree for 'got merge'
864 (cd $testroot/wt && got update > /dev/null)
865 ret="$?"
866 if [ "$ret" != "0" ]; then
867 echo "got update failed unexpectedly" >&2
868 test_done "$testroot" "$ret"
869 return 1
870 fi
872 (cd $testroot/wt && got merge newbranch \
873 > $testroot/stdout 2> $testroot/stderr)
874 ret="$?"
875 if [ "$ret" == "0" ]; then
876 echo "got merge succeeded unexpectedly" >&2
877 test_done "$testroot" "1"
878 return 1
879 fi
881 echo -n "got: cannot merge branch which contains changes outside " \
882 > $testroot/stderr.expected
883 echo "of this work tree's path prefix" >> $testroot/stderr.expected
884 cmp -s $testroot/stderr.expected $testroot/stderr
885 ret="$?"
886 if [ "$ret" != "0" ]; then
887 diff -u $testroot/stderr.expected $testroot/stderr
888 fi
889 test_done "$testroot" "$ret"
892 test_merge_missing_file() {
893 local testroot=`test_init merge_missing_file`
894 local commit0=`git_show_head $testroot/repo`
895 local commit0_author_time=`git_show_author_time $testroot/repo`
897 (cd $testroot/repo && git checkout -q -b newbranch)
898 echo "modified alpha on branch" > $testroot/repo/alpha
899 echo "modified delta on branch" > $testroot/repo/gamma/delta
900 git_commit $testroot/repo -m "committing to alpha and delta"
901 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
903 got checkout -b master $testroot/repo $testroot/wt > /dev/null
904 ret="$?"
905 if [ "$ret" != "0" ]; then
906 echo "got checkout failed unexpectedly" >&2
907 test_done "$testroot" "$ret"
908 return 1
909 fi
911 # create a conflicting commit which renames alpha
912 (cd $testroot/repo && git checkout -q master)
913 (cd $testroot/repo && git mv alpha epsilon/alpha-moved)
914 git_commit $testroot/repo -m "moving alpha on master"
915 local master_commit=`git_show_head $testroot/repo`
917 # need an up-to-date work tree for 'got merge'
918 (cd $testroot/wt && got update > /dev/null)
919 ret="$?"
920 if [ "$ret" != "0" ]; then
921 echo "got update failed unexpectedly" >&2
922 test_done "$testroot" "$ret"
923 return 1
924 fi
926 (cd $testroot/wt && got merge newbranch \
927 > $testroot/stdout 2> $testroot/stderr)
928 ret="$?"
929 if [ "$ret" == "0" ]; then
930 echo "got merge succeeded unexpectedly" >&2
931 test_done "$testroot" "1"
932 return 1
933 fi
935 echo "! alpha" > $testroot/stdout.expected
936 echo "G gamma/delta" >> $testroot/stdout.expected
937 cmp -s $testroot/stdout.expected $testroot/stdout
938 ret="$?"
939 if [ "$ret" != "0" ]; then
940 diff -u $testroot/stdout.expected $testroot/stdout
941 test_done "$testroot" "$ret"
942 return 1
943 fi
945 echo -n "got: changes destined for missing files " \
946 > $testroot/stderr.expected
947 echo -n "were not yet merged and should be merged manually if " \
948 >> $testroot/stderr.expected
949 echo "required before the merge operation is continued" \
950 >> $testroot/stderr.expected
951 cmp -s $testroot/stderr.expected $testroot/stderr
952 ret="$?"
953 if [ "$ret" != "0" ]; then
954 diff -u $testroot/stderr.expected $testroot/stderr
955 test_done "$testroot" "$ret"
956 return 1
957 fi
959 (cd $testroot/wt && got status > $testroot/stdout)
961 echo "M gamma/delta" > $testroot/stdout.expected
962 cmp -s $testroot/stdout.expected $testroot/stdout
963 ret="$?"
964 if [ "$ret" != "0" ]; then
965 diff -u $testroot/stdout.expected $testroot/stdout
966 test_done "$testroot" "$ret"
967 return 1
968 fi
970 test_done "$testroot" "$ret"
973 test_merge_no_op() {
974 local testroot=`test_init merge_no_op`
975 local commit0=`git_show_head $testroot/repo`
976 local commit0_author_time=`git_show_author_time $testroot/repo`
978 (cd $testroot/repo && git checkout -q -b newbranch)
979 echo "modified alpha on branch" > $testroot/repo/alpha
980 git_commit $testroot/repo -m "committing to alpha on newbranch"
981 local branch_commitk=`git_show_branch_head $testroot/repo newbranch`
983 got checkout -b master $testroot/repo $testroot/wt > /dev/null
984 ret="$?"
985 if [ "$ret" != "0" ]; then
986 echo "got checkout failed unexpectedly" >&2
987 test_done "$testroot" "$ret"
988 return 1
989 fi
991 # create a conflicting commit
992 (cd $testroot/repo && git checkout -q master)
993 echo "modified alpha on master" > $testroot/repo/alpha
994 git_commit $testroot/repo -m "committing to alpha on master"
995 local master_commit=`git_show_head $testroot/repo`
997 # need an up-to-date work tree for 'got merge'
998 (cd $testroot/wt && got update > /dev/null)
999 ret="$?"
1000 if [ "$ret" != "0" ]; then
1001 echo "got update failed unexpectedly" >&2
1002 test_done "$testroot" "$ret"
1003 return 1
1006 (cd $testroot/wt && got merge newbranch \
1007 > $testroot/stdout 2> $testroot/stderr)
1008 ret="$?"
1009 if [ "$ret" == "0" ]; then
1010 echo "got merge succeeded unexpectedly" >&2
1011 test_done "$testroot" "1"
1012 return 1
1015 echo "C alpha" >> $testroot/stdout.expected
1016 echo "Files with new merge conflicts: 1" >> $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 echo "got: conflicts must be resolved before merging can continue" \
1026 > $testroot/stderr.expected
1027 cmp -s $testroot/stderr.expected $testroot/stderr
1028 ret="$?"
1029 if [ "$ret" != "0" ]; then
1030 diff -u $testroot/stderr.expected $testroot/stderr
1031 test_done "$testroot" "$ret"
1032 return 1
1035 (cd $testroot/wt && got status > $testroot/stdout)
1037 echo "C alpha" > $testroot/stdout.expected
1038 cmp -s $testroot/stdout.expected $testroot/stdout
1039 ret="$?"
1040 if [ "$ret" != "0" ]; then
1041 diff -u $testroot/stdout.expected $testroot/stdout
1042 test_done "$testroot" "$ret"
1043 return 1
1046 # resolve the conflict by reverting all changes; now it is no-op merge
1047 (cd $testroot/wt && got revert alpha > /dev/null)
1048 ret="$?"
1049 if [ "$ret" != "0" ]; then
1050 echo "got revert failed unexpectedly" >&2
1051 test_done "$testroot" "$ret"
1052 return 1
1055 (cd $testroot/wt && got merge -c > $testroot/stdout \
1056 2> $testroot/stderr)
1057 ret="$?"
1058 if [ "$ret" == "0" ]; then
1059 echo "got merge succeeded unexpectedly" >&2
1060 test_done "$testroot" "$ret"
1061 return 1
1064 echo -n "got: merge of refs/heads/newbranch cannot proceed: " \
1065 > $testroot/stderr.expected
1066 echo "no changes to commit" >> $testroot/stderr.expected
1067 cmp -s $testroot/stderr.expected $testroot/stderr
1068 ret="$?"
1069 if [ "$ret" != "0" ]; then
1070 diff -u $testroot/stderr.expected $testroot/stderr
1071 test_done "$testroot" "$ret"
1072 return 1
1075 (cd $testroot/wt && got status > $testroot/stdout)
1077 echo -n "" > $testroot/stdout.expected
1078 cmp -s $testroot/stdout.expected $testroot/stdout
1079 ret="$?"
1080 if [ "$ret" != "0" ]; then
1081 diff -u $testroot/stdout.expected $testroot/stdout
1083 test_done "$testroot" "$ret"
1086 test_parseargs "$@"
1087 run_test test_merge_basic
1088 run_test test_merge_continue
1089 run_test test_merge_abort
1090 run_test test_merge_in_progress
1091 run_test test_merge_path_prefix
1092 run_test test_merge_missing_file
1093 run_test test_merge_no_op