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 -n "Merged refs/heads/newbranch into refs/heads/master: " \
496 > $testroot/stdout.expected
497 echo $merge_commit >> $testroot/stdout.expected
499 cmp -s $testroot/stdout.expected $testroot/stdout
500 ret="$?"
501 if [ "$ret" != "0" ]; then
502 diff -u $testroot/stdout.expected $testroot/stdout
503 test_done "$testroot" "$ret"
504 return 1
505 fi
507 echo "modified delta on branch" > $testroot/content.expected
508 cat $testroot/wt/gamma/delta > $testroot/content
509 cmp -s $testroot/content.expected $testroot/content
510 ret="$?"
511 if [ "$ret" != "0" ]; then
512 diff -u $testroot/content.expected $testroot/content
513 test_done "$testroot" "$ret"
514 return 1
515 fi
517 echo "modified alpha by both branches" > $testroot/content.expected
518 cat $testroot/wt/alpha > $testroot/content
519 cmp -s $testroot/content.expected $testroot/content
520 ret="$?"
521 if [ "$ret" != "0" ]; then
522 diff -u $testroot/content.expected $testroot/content
523 test_done "$testroot" "$ret"
524 return 1
525 fi
527 if [ -e $testroot/wt/beta ]; then
528 echo "removed file beta still exists on disk" >&2
529 test_done "$testroot" "1"
530 return 1
531 fi
533 echo "new file on branch" > $testroot/content.expected
534 cat $testroot/wt/epsilon/new > $testroot/content
535 cmp -s $testroot/content.expected $testroot/content
536 ret="$?"
537 if [ "$ret" != "0" ]; then
538 diff -u $testroot/content.expected $testroot/content
539 test_done "$testroot" "$ret"
540 return 1
541 fi
543 (cd $testroot/wt && got status > $testroot/stdout)
545 echo -n > $testroot/stdout.expected
546 cmp -s $testroot/stdout.expected $testroot/stdout
547 ret="$?"
548 if [ "$ret" != "0" ]; then
549 diff -u $testroot/stdout.expected $testroot/stdout
550 test_done "$testroot" "$ret"
551 return 1
552 fi
554 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
555 echo "commit $merge_commit (master)" > $testroot/stdout.expected
556 echo "commit $master_commit" >> $testroot/stdout.expected
557 echo "commit $commit0" >> $testroot/stdout.expected
558 cmp -s $testroot/stdout.expected $testroot/stdout
559 ret="$?"
560 if [ "$ret" != "0" ]; then
561 diff -u $testroot/stdout.expected $testroot/stdout
562 test_done "$testroot" "$ret"
563 return 1
564 fi
566 (cd $testroot/wt && got update > $testroot/stdout)
568 echo 'Already up-to-date' > $testroot/stdout.expected
569 cmp -s $testroot/stdout.expected $testroot/stdout
570 ret="$?"
571 if [ "$ret" != "0" ]; then
572 diff -u $testroot/stdout.expected $testroot/stdout
573 test_done "$testroot" "$ret"
574 return 1
575 fi
577 # We should have created a merge commit with two parents.
578 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
579 echo "parent 1: $master_commit" > $testroot/stdout.expected
580 echo "parent 2: $branch_commit3" >> $testroot/stdout.expected
581 cmp -s $testroot/stdout.expected $testroot/stdout
582 ret="$?"
583 if [ "$ret" != "0" ]; then
584 diff -u $testroot/stdout.expected $testroot/stdout
585 fi
586 test_done "$testroot" "$ret"
589 test_merge_abort() {
590 local testroot=`test_init merge_abort`
591 local commit0=`git_show_head $testroot/repo`
592 local commit0_author_time=`git_show_author_time $testroot/repo`
594 (cd $testroot/repo && git checkout -q -b newbranch)
595 echo "modified delta on branch" > $testroot/repo/gamma/delta
596 git_commit $testroot/repo -m "committing to delta on newbranch"
597 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
599 echo "modified alpha on branch" > $testroot/repo/alpha
600 git_commit $testroot/repo -m "committing to alpha on newbranch"
601 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
602 (cd $testroot/repo && git rm -q beta)
603 git_commit $testroot/repo -m "removing beta on newbranch"
604 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
605 echo "new file on branch" > $testroot/repo/epsilon/new
606 (cd $testroot/repo && git add epsilon/new)
607 git_commit $testroot/repo -m "adding new file on newbranch"
608 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
609 (cd $testroot/repo && ln -s alpha symlink && git add symlink)
610 git_commit $testroot/repo -m "adding symlink on newbranch"
611 local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
613 got checkout -b master $testroot/repo $testroot/wt > /dev/null
614 ret="$?"
615 if [ "$ret" != "0" ]; then
616 echo "got checkout failed unexpectedly" >&2
617 test_done "$testroot" "$ret"
618 return 1
619 fi
621 # create a conflicting commit
622 (cd $testroot/repo && git checkout -q master)
623 echo "modified alpha on master" > $testroot/repo/alpha
624 git_commit $testroot/repo -m "committing to alpha on master"
625 local master_commit=`git_show_head $testroot/repo`
627 # need an up-to-date work tree for 'got merge'
628 (cd $testroot/wt && got update > /dev/null)
629 ret="$?"
630 if [ "$ret" != "0" ]; then
631 echo "got update failed unexpectedly" >&2
632 test_done "$testroot" "$ret"
633 return 1
634 fi
636 (cd $testroot/wt && got merge newbranch \
637 > $testroot/stdout 2> $testroot/stderr)
638 ret="$?"
639 if [ "$ret" == "0" ]; then
640 echo "got merge succeeded unexpectedly" >&2
641 test_done "$testroot" "1"
642 return 1
643 fi
645 echo "C alpha" >> $testroot/stdout.expected
646 echo "D beta" >> $testroot/stdout.expected
647 echo "A epsilon/new" >> $testroot/stdout.expected
648 echo "G gamma/delta" >> $testroot/stdout.expected
649 echo "A symlink" >> $testroot/stdout.expected
650 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
651 cmp -s $testroot/stdout.expected $testroot/stdout
652 ret="$?"
653 if [ "$ret" != "0" ]; then
654 diff -u $testroot/stdout.expected $testroot/stdout
655 test_done "$testroot" "$ret"
656 return 1
657 fi
659 echo "got: conflicts must be resolved before merging can continue" \
660 > $testroot/stderr.expected
661 cmp -s $testroot/stderr.expected $testroot/stderr
662 ret="$?"
663 if [ "$ret" != "0" ]; then
664 diff -u $testroot/stderr.expected $testroot/stderr
665 test_done "$testroot" "$ret"
666 return 1
667 fi
669 (cd $testroot/wt && got status > $testroot/stdout)
671 echo "C alpha" > $testroot/stdout.expected
672 echo "D beta" >> $testroot/stdout.expected
673 echo "A epsilon/new" >> $testroot/stdout.expected
674 echo "M gamma/delta" >> $testroot/stdout.expected
675 echo "A symlink" >> $testroot/stdout.expected
676 cmp -s $testroot/stdout.expected $testroot/stdout
677 ret="$?"
678 if [ "$ret" != "0" ]; then
679 diff -u $testroot/stdout.expected $testroot/stdout
680 test_done "$testroot" "$ret"
681 return 1
682 fi
684 (cd $testroot/wt && got merge -a > $testroot/stdout)
685 ret="$?"
686 if [ "$ret" != "0" ]; then
687 echo "got merge failed unexpectedly" >&2
688 test_done "$testroot" "$ret"
689 return 1
690 fi
692 echo "R alpha" > $testroot/stdout.expected
693 echo "R beta" >> $testroot/stdout.expected
694 echo "R epsilon/new" >> $testroot/stdout.expected
695 echo "R gamma/delta" >> $testroot/stdout.expected
696 echo "R symlink" >> $testroot/stdout.expected
697 echo "Merge of refs/heads/newbranch aborted" \
698 >> $testroot/stdout.expected
700 cmp -s $testroot/stdout.expected $testroot/stdout
701 ret="$?"
702 if [ "$ret" != "0" ]; then
703 diff -u $testroot/stdout.expected $testroot/stdout
704 test_done "$testroot" "$ret"
705 return 1
706 fi
708 echo "delta" > $testroot/content.expected
709 cat $testroot/wt/gamma/delta > $testroot/content
710 cmp -s $testroot/content.expected $testroot/content
711 ret="$?"
712 if [ "$ret" != "0" ]; then
713 diff -u $testroot/content.expected $testroot/content
714 test_done "$testroot" "$ret"
715 return 1
716 fi
718 echo "modified alpha on master" > $testroot/content.expected
719 cat $testroot/wt/alpha > $testroot/content
720 cmp -s $testroot/content.expected $testroot/content
721 ret="$?"
722 if [ "$ret" != "0" ]; then
723 diff -u $testroot/content.expected $testroot/content
724 test_done "$testroot" "$ret"
725 return 1
726 fi
728 echo "beta" > $testroot/content.expected
729 cat $testroot/wt/beta > $testroot/content
730 cmp -s $testroot/content.expected $testroot/content
731 ret="$?"
732 if [ "$ret" != "0" ]; then
733 diff -u $testroot/content.expected $testroot/content
734 test_done "$testroot" "$ret"
735 return 1
736 fi
738 if [ -e $testroot/wt/epsilon/new ]; then
739 echo "reverted file epsilon/new still exists on disk" >&2
740 test_done "$testroot" "1"
741 return 1
742 fi
744 if [ -e $testroot/wt/symlink ]; then
745 echo "reverted symlink still exists on disk" >&2
746 test_done "$testroot" "1"
747 return 1
748 fi
750 (cd $testroot/wt && got status > $testroot/stdout)
752 echo -n "" > $testroot/stdout.expected
753 cmp -s $testroot/stdout.expected $testroot/stdout
754 ret="$?"
755 if [ "$ret" != "0" ]; then
756 diff -u $testroot/stdout.expected $testroot/stdout
757 test_done "$testroot" "$ret"
758 return 1
759 fi
761 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
762 echo "commit $master_commit (master)" > $testroot/stdout.expected
763 echo "commit $commit0" >> $testroot/stdout.expected
764 cmp -s $testroot/stdout.expected $testroot/stdout
765 ret="$?"
766 if [ "$ret" != "0" ]; then
767 diff -u $testroot/stdout.expected $testroot/stdout
768 test_done "$testroot" "$ret"
769 return 1
770 fi
772 (cd $testroot/wt && got update > $testroot/stdout)
774 echo 'Already up-to-date' > $testroot/stdout.expected
775 cmp -s $testroot/stdout.expected $testroot/stdout
776 ret="$?"
777 if [ "$ret" != "0" ]; then
778 diff -u $testroot/stdout.expected $testroot/stdout
779 fi
780 test_done "$testroot" "$ret"
783 test_merge_in_progress() {
784 local testroot=`test_init merge_in_progress`
785 local commit0=`git_show_head $testroot/repo`
786 local commit0_author_time=`git_show_author_time $testroot/repo`
788 (cd $testroot/repo && git checkout -q -b newbranch)
789 echo "modified alpha on branch" > $testroot/repo/alpha
790 git_commit $testroot/repo -m "committing to alpha on newbranch"
791 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
793 got checkout -b master $testroot/repo $testroot/wt > /dev/null
794 ret="$?"
795 if [ "$ret" != "0" ]; then
796 echo "got checkout failed unexpectedly" >&2
797 test_done "$testroot" "$ret"
798 return 1
799 fi
801 # create a conflicting commit
802 (cd $testroot/repo && git checkout -q master)
803 echo "modified alpha on master" > $testroot/repo/alpha
804 git_commit $testroot/repo -m "committing to alpha on master"
805 local master_commit=`git_show_head $testroot/repo`
807 # need an up-to-date work tree for 'got merge'
808 (cd $testroot/wt && got update > /dev/null)
809 ret="$?"
810 if [ "$ret" != "0" ]; then
811 echo "got update failed unexpectedly" >&2
812 test_done "$testroot" "$ret"
813 return 1
814 fi
816 (cd $testroot/wt && got merge newbranch \
817 > $testroot/stdout 2> $testroot/stderr)
818 ret="$?"
819 if [ "$ret" == "0" ]; then
820 echo "got merge succeeded unexpectedly" >&2
821 test_done "$testroot" "1"
822 return 1
823 fi
825 echo "C alpha" >> $testroot/stdout.expected
826 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
827 cmp -s $testroot/stdout.expected $testroot/stdout
828 ret="$?"
829 if [ "$ret" != "0" ]; then
830 diff -u $testroot/stdout.expected $testroot/stdout
831 test_done "$testroot" "$ret"
832 return 1
833 fi
835 echo "got: conflicts must be resolved before merging can continue" \
836 > $testroot/stderr.expected
837 cmp -s $testroot/stderr.expected $testroot/stderr
838 ret="$?"
839 if [ "$ret" != "0" ]; then
840 diff -u $testroot/stderr.expected $testroot/stderr
841 test_done "$testroot" "$ret"
842 return 1
843 fi
845 (cd $testroot/wt && got status > $testroot/stdout)
847 echo "C alpha" > $testroot/stdout.expected
848 cmp -s $testroot/stdout.expected $testroot/stdout
849 ret="$?"
850 if [ "$ret" != "0" ]; then
851 diff -u $testroot/stdout.expected $testroot/stdout
852 test_done "$testroot" "$ret"
853 return 1
854 fi
856 for cmd in update commit histedit "rebase newbranch" \
857 "integrate newbranch" "stage alpha"; do
858 (cd $testroot/wt && got $cmd > $testroot/stdout \
859 2> $testroot/stderr)
861 echo -n > $testroot/stdout.expected
862 cmp -s $testroot/stdout.expected $testroot/stdout
863 ret="$?"
864 if [ "$ret" != "0" ]; then
865 diff -u $testroot/stdout.expected $testroot/stdout
866 test_done "$testroot" "$ret"
867 return 1
868 fi
870 echo -n "got: a merge operation is in progress in this " \
871 > $testroot/stderr.expected
872 echo "work tree and must be continued or aborted first" \
873 >> $testroot/stderr.expected
874 cmp -s $testroot/stderr.expected $testroot/stderr
875 ret="$?"
876 if [ "$ret" != "0" ]; then
877 diff -u $testroot/stderr.expected $testroot/stderr
878 test_done "$testroot" "$ret"
879 return 1
880 fi
881 done
883 test_done "$testroot" "$ret"
886 test_merge_path_prefix() {
887 local testroot=`test_init merge_path_prefix`
888 local commit0=`git_show_head $testroot/repo`
889 local commit0_author_time=`git_show_author_time $testroot/repo`
891 (cd $testroot/repo && git checkout -q -b newbranch)
892 echo "modified alpha on branch" > $testroot/repo/alpha
893 git_commit $testroot/repo -m "committing to alpha on newbranch"
894 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
896 got checkout -p epsilon -b master $testroot/repo $testroot/wt \
897 > /dev/null
898 ret="$?"
899 if [ "$ret" != "0" ]; then
900 echo "got checkout failed unexpectedly" >&2
901 test_done "$testroot" "$ret"
902 return 1
903 fi
905 # create a conflicting commit
906 (cd $testroot/repo && git checkout -q master)
907 echo "modified alpha on master" > $testroot/repo/alpha
908 git_commit $testroot/repo -m "committing to alpha on master"
909 local master_commit=`git_show_head $testroot/repo`
911 # need an up-to-date work tree for 'got merge'
912 (cd $testroot/wt && got update > /dev/null)
913 ret="$?"
914 if [ "$ret" != "0" ]; then
915 echo "got update failed unexpectedly" >&2
916 test_done "$testroot" "$ret"
917 return 1
918 fi
920 (cd $testroot/wt && got merge newbranch \
921 > $testroot/stdout 2> $testroot/stderr)
922 ret="$?"
923 if [ "$ret" == "0" ]; then
924 echo "got merge succeeded unexpectedly" >&2
925 test_done "$testroot" "1"
926 return 1
927 fi
929 echo -n "got: cannot merge branch which contains changes outside " \
930 > $testroot/stderr.expected
931 echo "of this work tree's path prefix" >> $testroot/stderr.expected
932 cmp -s $testroot/stderr.expected $testroot/stderr
933 ret="$?"
934 if [ "$ret" != "0" ]; then
935 diff -u $testroot/stderr.expected $testroot/stderr
936 fi
937 test_done "$testroot" "$ret"
940 test_merge_missing_file() {
941 local testroot=`test_init merge_missing_file`
942 local commit0=`git_show_head $testroot/repo`
943 local commit0_author_time=`git_show_author_time $testroot/repo`
945 (cd $testroot/repo && git checkout -q -b newbranch)
946 echo "modified alpha on branch" > $testroot/repo/alpha
947 echo "modified delta on branch" > $testroot/repo/gamma/delta
948 git_commit $testroot/repo -m "committing to alpha and delta"
949 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
951 got checkout -b master $testroot/repo $testroot/wt > /dev/null
952 ret="$?"
953 if [ "$ret" != "0" ]; then
954 echo "got checkout failed unexpectedly" >&2
955 test_done "$testroot" "$ret"
956 return 1
957 fi
959 # create a conflicting commit which renames alpha
960 (cd $testroot/repo && git checkout -q master)
961 (cd $testroot/repo && git mv alpha epsilon/alpha-moved)
962 git_commit $testroot/repo -m "moving alpha on master"
963 local master_commit=`git_show_head $testroot/repo`
965 # need an up-to-date work tree for 'got merge'
966 (cd $testroot/wt && got update > /dev/null)
967 ret="$?"
968 if [ "$ret" != "0" ]; then
969 echo "got update failed unexpectedly" >&2
970 test_done "$testroot" "$ret"
971 return 1
972 fi
974 (cd $testroot/wt && got merge newbranch \
975 > $testroot/stdout 2> $testroot/stderr)
976 ret="$?"
977 if [ "$ret" == "0" ]; then
978 echo "got merge succeeded unexpectedly" >&2
979 test_done "$testroot" "1"
980 return 1
981 fi
983 echo "! alpha" > $testroot/stdout.expected
984 echo "G gamma/delta" >> $testroot/stdout.expected
985 cmp -s $testroot/stdout.expected $testroot/stdout
986 ret="$?"
987 if [ "$ret" != "0" ]; then
988 diff -u $testroot/stdout.expected $testroot/stdout
989 test_done "$testroot" "$ret"
990 return 1
991 fi
993 echo -n "got: changes destined for missing files " \
994 > $testroot/stderr.expected
995 echo -n "were not yet merged and should be merged manually if " \
996 >> $testroot/stderr.expected
997 echo "required before the merge operation is continued" \
998 >> $testroot/stderr.expected
999 cmp -s $testroot/stderr.expected $testroot/stderr
1000 ret="$?"
1001 if [ "$ret" != "0" ]; then
1002 diff -u $testroot/stderr.expected $testroot/stderr
1003 test_done "$testroot" "$ret"
1004 return 1
1007 (cd $testroot/wt && got status > $testroot/stdout)
1009 echo "M gamma/delta" > $testroot/stdout.expected
1010 cmp -s $testroot/stdout.expected $testroot/stdout
1011 ret="$?"
1012 if [ "$ret" != "0" ]; then
1013 diff -u $testroot/stdout.expected $testroot/stdout
1014 test_done "$testroot" "$ret"
1015 return 1
1018 test_done "$testroot" "$ret"
1021 test_merge_no_op() {
1022 local testroot=`test_init merge_no_op`
1023 local commit0=`git_show_head $testroot/repo`
1024 local commit0_author_time=`git_show_author_time $testroot/repo`
1026 (cd $testroot/repo && git checkout -q -b newbranch)
1027 echo "modified alpha on branch" > $testroot/repo/alpha
1028 git_commit $testroot/repo -m "committing to alpha on newbranch"
1029 local branch_commitk=`git_show_branch_head $testroot/repo newbranch`
1031 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1032 ret="$?"
1033 if [ "$ret" != "0" ]; then
1034 echo "got checkout failed unexpectedly" >&2
1035 test_done "$testroot" "$ret"
1036 return 1
1039 # create a conflicting commit
1040 (cd $testroot/repo && git checkout -q master)
1041 echo "modified alpha on master" > $testroot/repo/alpha
1042 git_commit $testroot/repo -m "committing to alpha on master"
1043 local master_commit=`git_show_head $testroot/repo`
1045 # need an up-to-date work tree for 'got merge'
1046 (cd $testroot/wt && got update > /dev/null)
1047 ret="$?"
1048 if [ "$ret" != "0" ]; then
1049 echo "got update failed unexpectedly" >&2
1050 test_done "$testroot" "$ret"
1051 return 1
1054 (cd $testroot/wt && got merge newbranch \
1055 > $testroot/stdout 2> $testroot/stderr)
1056 ret="$?"
1057 if [ "$ret" == "0" ]; then
1058 echo "got merge succeeded unexpectedly" >&2
1059 test_done "$testroot" "1"
1060 return 1
1063 echo "C alpha" >> $testroot/stdout.expected
1064 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1065 cmp -s $testroot/stdout.expected $testroot/stdout
1066 ret="$?"
1067 if [ "$ret" != "0" ]; then
1068 diff -u $testroot/stdout.expected $testroot/stdout
1069 test_done "$testroot" "$ret"
1070 return 1
1073 echo "got: conflicts must be resolved before merging can continue" \
1074 > $testroot/stderr.expected
1075 cmp -s $testroot/stderr.expected $testroot/stderr
1076 ret="$?"
1077 if [ "$ret" != "0" ]; then
1078 diff -u $testroot/stderr.expected $testroot/stderr
1079 test_done "$testroot" "$ret"
1080 return 1
1083 (cd $testroot/wt && got status > $testroot/stdout)
1085 echo "C alpha" > $testroot/stdout.expected
1086 cmp -s $testroot/stdout.expected $testroot/stdout
1087 ret="$?"
1088 if [ "$ret" != "0" ]; then
1089 diff -u $testroot/stdout.expected $testroot/stdout
1090 test_done "$testroot" "$ret"
1091 return 1
1094 # resolve the conflict by reverting all changes; now it is no-op merge
1095 (cd $testroot/wt && got revert alpha > /dev/null)
1096 ret="$?"
1097 if [ "$ret" != "0" ]; then
1098 echo "got revert failed unexpectedly" >&2
1099 test_done "$testroot" "$ret"
1100 return 1
1103 (cd $testroot/wt && got merge -c > $testroot/stdout \
1104 2> $testroot/stderr)
1105 ret="$?"
1106 if [ "$ret" == "0" ]; then
1107 echo "got merge succeeded unexpectedly" >&2
1108 test_done "$testroot" "$ret"
1109 return 1
1112 echo -n "got: merge of refs/heads/newbranch cannot proceed: " \
1113 > $testroot/stderr.expected
1114 echo "no changes to commit" >> $testroot/stderr.expected
1115 cmp -s $testroot/stderr.expected $testroot/stderr
1116 ret="$?"
1117 if [ "$ret" != "0" ]; then
1118 diff -u $testroot/stderr.expected $testroot/stderr
1119 test_done "$testroot" "$ret"
1120 return 1
1123 (cd $testroot/wt && got status > $testroot/stdout)
1125 echo -n "" > $testroot/stdout.expected
1126 cmp -s $testroot/stdout.expected $testroot/stdout
1127 ret="$?"
1128 if [ "$ret" != "0" ]; then
1129 diff -u $testroot/stdout.expected $testroot/stdout
1131 test_done "$testroot" "$ret"
1134 test_merge_imported_branch() {
1135 local testroot=`test_init merge_import`
1136 local commit0=`git_show_head $testroot/repo`
1137 local commit0_author_time=`git_show_author_time $testroot/repo`
1139 # import a new sub-tree to the 'files' branch such that
1140 # none of the files added here collide with existing ones
1141 mkdir -p $testroot/tree/there
1142 mkdir -p $testroot/tree/be/lots
1143 mkdir -p $testroot/tree/files
1144 echo "there should" > $testroot/tree/there/should
1145 echo "be lots of" > $testroot/tree/be/lots/of
1146 echo "files here" > $testroot/tree/files/here
1147 got import -r $testroot/repo -b files -m 'import files' \
1148 $testroot/tree > /dev/null
1150 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1151 ret="$?"
1152 if [ "$ret" != "0" ]; then
1153 echo "got checkout failed unexpectedly" >&2
1154 test_done "$testroot" "$ret"
1155 return 1
1158 (cd $testroot/wt && got merge files > $testroot/stdout)
1159 ret="$?"
1160 if [ "$ret" != "0" ]; then
1161 echo "got merge failed unexpectedly" >&2
1162 test_done "$testroot" "$ret"
1163 return 1
1166 local merge_commit0=`git_show_head $testroot/repo`
1167 cat > $testroot/stdout.expected <<EOF
1168 A be/lots/of
1169 A files/here
1170 A there/should
1171 Merged refs/heads/files into refs/heads/master: $merge_commit0
1172 EOF
1173 cmp -s $testroot/stdout.expected $testroot/stdout
1174 ret="$?"
1175 if [ "$ret" != "0" ]; then
1176 diff -u $testroot/stdout.expected $testroot/stdout
1177 test_done "$testroot" "$ret"
1178 return 1
1181 # try to merge again while no new changes are available
1182 (cd $testroot/wt && got merge files > $testroot/stdout)
1183 ret="$?"
1184 if [ "$ret" != "0" ]; then
1185 echo "got merge failed unexpectedly" >&2
1186 test_done "$testroot" "$ret"
1187 return 1
1189 echo "Already up-to-date" > $testroot/stdout.expected
1190 cmp -s $testroot/stdout.expected $testroot/stdout
1191 ret="$?"
1192 if [ "$ret" != "0" ]; then
1193 diff -u $testroot/stdout.expected $testroot/stdout
1194 test_done "$testroot" "$ret"
1195 return 1
1198 # update the 'files' branch
1199 (cd $testroot/repo && git reset -q --hard master)
1200 (cd $testroot/repo && git checkout -q files)
1201 echo "indeed" > $testroot/repo/indeed
1202 (cd $testroot/repo && git add indeed)
1203 git_commit $testroot/repo -m "adding another file indeed"
1204 echo "be lots and lots of" > $testroot/repo/be/lots/of
1205 git_commit $testroot/repo -m "lots of changes"
1207 (cd $testroot/wt && got update > /dev/null)
1208 ret="$?"
1209 if [ "$ret" != "0" ]; then
1210 echo "got update failed unexpectedly" >&2
1211 test_done "$testroot" "$ret"
1212 return 1
1215 # we should now be able to merge more changes from files branch
1216 (cd $testroot/wt && got merge files > $testroot/stdout)
1217 ret="$?"
1218 if [ "$ret" != "0" ]; then
1219 echo "got merge failed unexpectedly" >&2
1220 test_done "$testroot" "$ret"
1221 return 1
1224 local merge_commit1=`git_show_branch_head $testroot/repo master`
1225 cat > $testroot/stdout.expected <<EOF
1226 G be/lots/of
1227 A indeed
1228 Merged refs/heads/files into refs/heads/master: $merge_commit1
1229 EOF
1231 cmp -s $testroot/stdout.expected $testroot/stdout
1232 ret="$?"
1233 if [ "$ret" != "0" ]; then
1234 diff -u $testroot/stdout.expected $testroot/stdout
1236 test_done "$testroot" "$ret"
1239 test_parseargs "$@"
1240 run_test test_merge_basic
1241 run_test test_merge_continue
1242 run_test test_merge_abort
1243 run_test test_merge_in_progress
1244 run_test test_merge_path_prefix
1245 run_test test_merge_missing_file
1246 run_test test_merge_no_op
1247 run_test test_merge_imported_branch