Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 test_merge_basic() {
20 local testroot=`test_init merge_basic`
21 local commit0=`git_show_head $testroot/repo`
22 local commit0_author_time=`git_show_author_time $testroot/repo`
24 (cd $testroot/repo && git checkout -q -b newbranch)
25 echo "modified delta on branch" > $testroot/repo/gamma/delta
26 git_commit $testroot/repo -m "committing to delta on newbranch"
27 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
29 echo "modified alpha on branch" > $testroot/repo/alpha
30 git_commit $testroot/repo -m "committing to alpha on newbranch"
31 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
32 (cd $testroot/repo && git rm -q beta)
33 git_commit $testroot/repo -m "removing beta on newbranch"
34 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
35 echo "new file on branch" > $testroot/repo/epsilon/new
36 (cd $testroot/repo && git add epsilon/new)
37 git_commit $testroot/repo -m "adding new file on newbranch"
38 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
39 (cd $testroot/repo && ln -s alpha symlink && git add symlink)
40 git_commit $testroot/repo -m "adding symlink on newbranch"
41 local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
42 (cd $testroot/repo && ln -sf .got/bar dotgotbar.link)
43 (cd $testroot/repo && git add dotgotbar.link)
44 git_commit $testroot/repo -m "adding a bad symlink on newbranch"
45 local branch_commit5=`git_show_branch_head $testroot/repo newbranch`
47 got checkout -b master $testroot/repo $testroot/wt > /dev/null
48 ret=$?
49 if [ $ret -ne 0 ]; then
50 echo "got checkout failed unexpectedly" >&2
51 test_done "$testroot" "$ret"
52 return 1
53 fi
55 # 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 -eq 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 -ne 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 -eq 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 -ne 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 -ne 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 -ne 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 -eq 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 -ne 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 -ne 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 -ne 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 -eq 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 -ne 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 -ne 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 -eq 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 0 ]; then
286 diff -u $testroot/stdout.expected $testroot/stdout
287 test_done "$testroot" "$ret"
288 return 1
289 fi
291 (cd $testroot/wt && got status > $testroot/stdout)
293 echo -n > $testroot/stdout.expected
294 cmp -s $testroot/stdout.expected $testroot/stdout
295 ret=$?
296 if [ $ret -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -eq 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 0 ]; then
588 diff -u $testroot/stdout.expected $testroot/stdout
589 fi
590 test_done "$testroot" "$ret"
593 test_merge_continue_new_commit() {
594 # "got merge -c" should refuse to run if the current branch tip has
595 # changed since the merge was started, to avoid clobbering the changes.
596 local testroot=`test_init merge_continue_new_commit`
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"
602 (cd $testroot/repo && git checkout -q master)
603 echo "modified alpha on master" > $testroot/repo/alpha
604 git_commit $testroot/repo -m "committing to alpha on master"
606 got checkout -b master $testroot/repo $testroot/wt > /dev/null
607 ret=$?
608 if [ $ret -ne 0 ]; then
609 echo "got checkout failed unexpectedly" >&2
610 test_done "$testroot" "$ret"
611 return 1
612 fi
614 (cd $testroot/wt && got merge -n newbranch >/dev/null)
615 ret=$?
616 if [ $ret -ne 0 ]; then
617 echo "got merge failed unexpectedly" >&2
618 test_done "$testroot" "$ret"
619 return 1
620 fi
622 echo "modified alpha again on master" > $testroot/repo/alpha
623 git_commit $testroot/repo -m "committing to alpha on master again"
625 (cd $testroot/wt && got merge -c > $testroot/stdout 2> $testroot/stderr)
626 ret=$?
627 if [ $ret -eq 0 ]; then
628 echo "got merge succeeded unexpectedly" >&2
629 test_done "$testroot" "1"
630 return 1
631 fi
633 echo -n > $testroot/stdout.expected
634 cmp -s $testroot/stdout.expected $testroot/stdout
635 ret=$?
636 if [ $ret -ne 0 ]; then
637 diff -u $testroot/stdout.expected $testroot/stdout
638 test_done "$testroot" "$ret"
639 return 1
640 fi
642 echo -n "got: merging cannot proceed because the work tree is no " \
643 > $testroot/stderr.expected
644 echo "longer up-to-date; merge must be aborted and retried" \
645 >> $testroot/stderr.expected
646 cmp -s $testroot/stderr.expected $testroot/stderr
647 ret=$?
648 if [ $ret -ne 0 ]; then
649 diff -u $testroot/stderr.expected $testroot/stderr
650 fi
651 test_done "$testroot" "$ret"
654 test_merge_abort() {
655 local testroot=`test_init merge_abort`
656 local commit0=`git_show_head $testroot/repo`
657 local commit0_author_time=`git_show_author_time $testroot/repo`
659 (cd $testroot/repo && git checkout -q -b newbranch)
660 echo "modified delta on branch" > $testroot/repo/gamma/delta
661 git_commit $testroot/repo -m "committing to delta on newbranch"
662 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
664 echo "modified alpha on branch" > $testroot/repo/alpha
665 git_commit $testroot/repo -m "committing to alpha on newbranch"
666 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
667 (cd $testroot/repo && git rm -q beta)
668 git_commit $testroot/repo -m "removing beta on newbranch"
669 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
670 echo "new file on branch" > $testroot/repo/epsilon/new
671 (cd $testroot/repo && git add epsilon/new)
672 git_commit $testroot/repo -m "adding new file on newbranch"
673 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
674 (cd $testroot/repo && ln -s alpha symlink && git add symlink)
675 git_commit $testroot/repo -m "adding symlink on newbranch"
676 local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
678 got checkout -b master $testroot/repo $testroot/wt > /dev/null
679 ret=$?
680 if [ $ret -ne 0 ]; then
681 echo "got checkout failed unexpectedly" >&2
682 test_done "$testroot" "$ret"
683 return 1
684 fi
686 # unrelated unversioned file in work tree
687 touch $testroot/wt/unversioned-file
689 # create a conflicting commit
690 (cd $testroot/repo && git checkout -q master)
691 echo "modified alpha on master" > $testroot/repo/alpha
692 git_commit $testroot/repo -m "committing to alpha on master"
693 local master_commit=`git_show_head $testroot/repo`
695 # need an up-to-date work tree for 'got merge'
696 (cd $testroot/wt && got update > /dev/null)
697 ret=$?
698 if [ $ret -ne 0 ]; then
699 echo "got update failed unexpectedly" >&2
700 test_done "$testroot" "$ret"
701 return 1
702 fi
704 (cd $testroot/wt && got merge newbranch \
705 > $testroot/stdout 2> $testroot/stderr)
706 ret=$?
707 if [ $ret -eq 0 ]; then
708 echo "got merge succeeded unexpectedly" >&2
709 test_done "$testroot" "1"
710 return 1
711 fi
713 echo "C alpha" >> $testroot/stdout.expected
714 echo "D beta" >> $testroot/stdout.expected
715 echo "A epsilon/new" >> $testroot/stdout.expected
716 echo "G gamma/delta" >> $testroot/stdout.expected
717 echo "A symlink" >> $testroot/stdout.expected
718 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
719 cmp -s $testroot/stdout.expected $testroot/stdout
720 ret=$?
721 if [ $ret -ne 0 ]; then
722 diff -u $testroot/stdout.expected $testroot/stdout
723 test_done "$testroot" "$ret"
724 return 1
725 fi
727 echo "got: conflicts must be resolved before merging can continue" \
728 > $testroot/stderr.expected
729 cmp -s $testroot/stderr.expected $testroot/stderr
730 ret=$?
731 if [ $ret -ne 0 ]; then
732 diff -u $testroot/stderr.expected $testroot/stderr
733 test_done "$testroot" "$ret"
734 return 1
735 fi
737 # unrelated added file added during conflict resolution
738 touch $testroot/wt/added-file
739 (cd $testroot/wt && got add added-file > /dev/null)
741 (cd $testroot/wt && got status > $testroot/stdout)
743 echo "A added-file" > $testroot/stdout.expected
744 echo "C alpha" >> $testroot/stdout.expected
745 echo "D beta" >> $testroot/stdout.expected
746 echo "A epsilon/new" >> $testroot/stdout.expected
747 echo "M gamma/delta" >> $testroot/stdout.expected
748 echo "A symlink" >> $testroot/stdout.expected
749 echo "? unversioned-file" >> $testroot/stdout.expected
750 cmp -s $testroot/stdout.expected $testroot/stdout
751 ret=$?
752 if [ $ret -ne 0 ]; then
753 diff -u $testroot/stdout.expected $testroot/stdout
754 test_done "$testroot" "$ret"
755 return 1
756 fi
758 (cd $testroot/wt && got merge -a > $testroot/stdout)
759 ret=$?
760 if [ $ret -ne 0 ]; then
761 echo "got merge failed unexpectedly" >&2
762 test_done "$testroot" "$ret"
763 return 1
764 fi
766 echo "R added-file" > $testroot/stdout.expected
767 echo "R alpha" >> $testroot/stdout.expected
768 echo "R beta" >> $testroot/stdout.expected
769 echo "R epsilon/new" >> $testroot/stdout.expected
770 echo "R gamma/delta" >> $testroot/stdout.expected
771 echo "R symlink" >> $testroot/stdout.expected
772 echo "G added-file" >> $testroot/stdout.expected
773 echo "Merge of refs/heads/newbranch aborted" \
774 >> $testroot/stdout.expected
776 cmp -s $testroot/stdout.expected $testroot/stdout
777 ret=$?
778 if [ $ret -ne 0 ]; then
779 diff -u $testroot/stdout.expected $testroot/stdout
780 test_done "$testroot" "$ret"
781 return 1
782 fi
784 echo "delta" > $testroot/content.expected
785 cat $testroot/wt/gamma/delta > $testroot/content
786 cmp -s $testroot/content.expected $testroot/content
787 ret=$?
788 if [ $ret -ne 0 ]; then
789 diff -u $testroot/content.expected $testroot/content
790 test_done "$testroot" "$ret"
791 return 1
792 fi
794 echo "modified alpha on master" > $testroot/content.expected
795 cat $testroot/wt/alpha > $testroot/content
796 cmp -s $testroot/content.expected $testroot/content
797 ret=$?
798 if [ $ret -ne 0 ]; then
799 diff -u $testroot/content.expected $testroot/content
800 test_done "$testroot" "$ret"
801 return 1
802 fi
804 echo "beta" > $testroot/content.expected
805 cat $testroot/wt/beta > $testroot/content
806 cmp -s $testroot/content.expected $testroot/content
807 ret=$?
808 if [ $ret -ne 0 ]; then
809 diff -u $testroot/content.expected $testroot/content
810 test_done "$testroot" "$ret"
811 return 1
812 fi
814 if [ -e $testroot/wt/epsilon/new ]; then
815 echo "reverted file epsilon/new still exists on disk" >&2
816 test_done "$testroot" "1"
817 return 1
818 fi
820 if [ -e $testroot/wt/symlink ]; then
821 echo "reverted symlink still exists on disk" >&2
822 test_done "$testroot" "1"
823 return 1
824 fi
826 (cd $testroot/wt && got status > $testroot/stdout)
828 echo "? added-file" > $testroot/stdout.expected
829 echo "? unversioned-file" >> $testroot/stdout.expected
830 cmp -s $testroot/stdout.expected $testroot/stdout
831 ret=$?
832 if [ $ret -ne 0 ]; then
833 diff -u $testroot/stdout.expected $testroot/stdout
834 test_done "$testroot" "$ret"
835 return 1
836 fi
838 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
839 echo "commit $master_commit (master)" > $testroot/stdout.expected
840 echo "commit $commit0" >> $testroot/stdout.expected
841 cmp -s $testroot/stdout.expected $testroot/stdout
842 ret=$?
843 if [ $ret -ne 0 ]; then
844 diff -u $testroot/stdout.expected $testroot/stdout
845 test_done "$testroot" "$ret"
846 return 1
847 fi
849 (cd $testroot/wt && got update > $testroot/stdout)
851 echo 'Already up-to-date' > $testroot/stdout.expected
852 cmp -s $testroot/stdout.expected $testroot/stdout
853 ret=$?
854 if [ $ret -ne 0 ]; then
855 diff -u $testroot/stdout.expected $testroot/stdout
856 fi
857 test_done "$testroot" "$ret"
860 test_merge_in_progress() {
861 local testroot=`test_init merge_in_progress`
862 local commit0=`git_show_head $testroot/repo`
863 local commit0_author_time=`git_show_author_time $testroot/repo`
865 (cd $testroot/repo && git checkout -q -b newbranch)
866 echo "modified alpha on branch" > $testroot/repo/alpha
867 git_commit $testroot/repo -m "committing to alpha on newbranch"
868 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
870 got checkout -b master $testroot/repo $testroot/wt > /dev/null
871 ret=$?
872 if [ $ret -ne 0 ]; then
873 echo "got checkout failed unexpectedly" >&2
874 test_done "$testroot" "$ret"
875 return 1
876 fi
878 # create a conflicting commit
879 (cd $testroot/repo && git checkout -q master)
880 echo "modified alpha on master" > $testroot/repo/alpha
881 git_commit $testroot/repo -m "committing to alpha on master"
882 local master_commit=`git_show_head $testroot/repo`
884 # need an up-to-date work tree for 'got merge'
885 (cd $testroot/wt && got update > /dev/null)
886 ret=$?
887 if [ $ret -ne 0 ]; then
888 echo "got update failed unexpectedly" >&2
889 test_done "$testroot" "$ret"
890 return 1
891 fi
893 (cd $testroot/wt && got merge newbranch \
894 > $testroot/stdout 2> $testroot/stderr)
895 ret=$?
896 if [ $ret -eq 0 ]; then
897 echo "got merge succeeded unexpectedly" >&2
898 test_done "$testroot" "1"
899 return 1
900 fi
902 echo "C alpha" >> $testroot/stdout.expected
903 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
904 cmp -s $testroot/stdout.expected $testroot/stdout
905 ret=$?
906 if [ $ret -ne 0 ]; then
907 diff -u $testroot/stdout.expected $testroot/stdout
908 test_done "$testroot" "$ret"
909 return 1
910 fi
912 echo "got: conflicts must be resolved before merging can continue" \
913 > $testroot/stderr.expected
914 cmp -s $testroot/stderr.expected $testroot/stderr
915 ret=$?
916 if [ $ret -ne 0 ]; then
917 diff -u $testroot/stderr.expected $testroot/stderr
918 test_done "$testroot" "$ret"
919 return 1
920 fi
922 (cd $testroot/wt && got status > $testroot/stdout)
924 echo "C alpha" > $testroot/stdout.expected
925 cmp -s $testroot/stdout.expected $testroot/stdout
926 ret=$?
927 if [ $ret -ne 0 ]; then
928 diff -u $testroot/stdout.expected $testroot/stdout
929 test_done "$testroot" "$ret"
930 return 1
931 fi
933 for cmd in update commit histedit "rebase newbranch" \
934 "integrate newbranch" "merge newbranch" "stage alpha"; do
935 (cd $testroot/wt && got $cmd > $testroot/stdout \
936 2> $testroot/stderr)
937 ret=$?
938 if [ $ret -eq 0 ]; then
939 echo "got $cmd succeeded unexpectedly" >&2
940 test_done "$testroot" "1"
941 return 1
942 fi
944 echo -n > $testroot/stdout.expected
945 cmp -s $testroot/stdout.expected $testroot/stdout
946 ret=$?
947 if [ $ret -ne 0 ]; then
948 diff -u $testroot/stdout.expected $testroot/stdout
949 test_done "$testroot" "$ret"
950 return 1
951 fi
953 echo -n "got: a merge operation is in progress in this " \
954 > $testroot/stderr.expected
955 echo "work tree and must be continued or aborted first" \
956 >> $testroot/stderr.expected
957 cmp -s $testroot/stderr.expected $testroot/stderr
958 ret=$?
959 if [ $ret -ne 0 ]; then
960 diff -u $testroot/stderr.expected $testroot/stderr
961 test_done "$testroot" "$ret"
962 return 1
963 fi
964 done
966 test_done "$testroot" "$ret"
969 test_merge_path_prefix() {
970 local testroot=`test_init merge_path_prefix`
971 local commit0=`git_show_head $testroot/repo`
972 local commit0_author_time=`git_show_author_time $testroot/repo`
974 (cd $testroot/repo && git checkout -q -b newbranch)
975 echo "modified alpha on branch" > $testroot/repo/alpha
976 git_commit $testroot/repo -m "committing to alpha on newbranch"
977 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
979 got checkout -p epsilon -b master $testroot/repo $testroot/wt \
980 > /dev/null
981 ret=$?
982 if [ $ret -ne 0 ]; then
983 echo "got checkout failed unexpectedly" >&2
984 test_done "$testroot" "$ret"
985 return 1
986 fi
988 # create a conflicting commit
989 (cd $testroot/repo && git checkout -q master)
990 echo "modified alpha on master" > $testroot/repo/alpha
991 git_commit $testroot/repo -m "committing to alpha on master"
992 local master_commit=`git_show_head $testroot/repo`
994 # need an up-to-date work tree for 'got merge'
995 (cd $testroot/wt && got update > /dev/null)
996 ret=$?
997 if [ $ret -ne 0 ]; then
998 echo "got update failed unexpectedly" >&2
999 test_done "$testroot" "$ret"
1000 return 1
1003 (cd $testroot/wt && got merge newbranch \
1004 > $testroot/stdout 2> $testroot/stderr)
1005 ret=$?
1006 if [ $ret -eq 0 ]; then
1007 echo "got merge succeeded unexpectedly" >&2
1008 test_done "$testroot" "1"
1009 return 1
1012 echo -n "got: cannot merge branch which contains changes outside " \
1013 > $testroot/stderr.expected
1014 echo "of this work tree's path prefix" >> $testroot/stderr.expected
1015 cmp -s $testroot/stderr.expected $testroot/stderr
1016 ret=$?
1017 if [ $ret -ne 0 ]; then
1018 diff -u $testroot/stderr.expected $testroot/stderr
1020 test_done "$testroot" "$ret"
1023 test_merge_missing_file() {
1024 local testroot=`test_init merge_missing_file`
1025 local commit0=`git_show_head $testroot/repo`
1026 local commit0_author_time=`git_show_author_time $testroot/repo`
1028 (cd $testroot/repo && git checkout -q -b newbranch)
1029 echo "modified alpha on branch" > $testroot/repo/alpha
1030 echo "modified delta on branch" > $testroot/repo/gamma/delta
1031 git_commit $testroot/repo -m "committing to alpha and delta"
1032 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1034 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1035 ret=$?
1036 if [ $ret -ne 0 ]; then
1037 echo "got checkout failed unexpectedly" >&2
1038 test_done "$testroot" "$ret"
1039 return 1
1042 # create a conflicting commit which renames alpha
1043 (cd $testroot/repo && git checkout -q master)
1044 (cd $testroot/repo && git mv alpha epsilon/alpha-moved)
1045 git_commit $testroot/repo -m "moving alpha on master"
1046 local master_commit=`git_show_head $testroot/repo`
1048 # need an up-to-date work tree for 'got merge'
1049 (cd $testroot/wt && got update > /dev/null)
1050 ret=$?
1051 if [ $ret -ne 0 ]; then
1052 echo "got update failed unexpectedly" >&2
1053 test_done "$testroot" "$ret"
1054 return 1
1057 (cd $testroot/wt && got merge newbranch \
1058 > $testroot/stdout 2> $testroot/stderr)
1059 ret=$?
1060 if [ $ret -eq 0 ]; then
1061 echo "got merge succeeded unexpectedly" >&2
1062 test_done "$testroot" "1"
1063 return 1
1066 echo "! alpha" > $testroot/stdout.expected
1067 echo "G gamma/delta" >> $testroot/stdout.expected
1068 echo -n "Files which had incoming changes but could not be found " \
1069 >> $testroot/stdout.expected
1070 echo "in the work tree: 1" >> $testroot/stdout.expected
1071 cmp -s $testroot/stdout.expected $testroot/stdout
1072 ret=$?
1073 if [ $ret -ne 0 ]; then
1074 diff -u $testroot/stdout.expected $testroot/stdout
1075 test_done "$testroot" "$ret"
1076 return 1
1079 echo -n "got: changes destined for some files " \
1080 > $testroot/stderr.expected
1081 echo -n "were not yet merged and should be merged manually if " \
1082 >> $testroot/stderr.expected
1083 echo "required before the merge operation is continued" \
1084 >> $testroot/stderr.expected
1085 cmp -s $testroot/stderr.expected $testroot/stderr
1086 ret=$?
1087 if [ $ret -ne 0 ]; then
1088 diff -u $testroot/stderr.expected $testroot/stderr
1089 test_done "$testroot" "$ret"
1090 return 1
1093 (cd $testroot/wt && got status > $testroot/stdout)
1095 echo "M gamma/delta" > $testroot/stdout.expected
1096 cmp -s $testroot/stdout.expected $testroot/stdout
1097 ret=$?
1098 if [ $ret -ne 0 ]; then
1099 diff -u $testroot/stdout.expected $testroot/stdout
1100 test_done "$testroot" "$ret"
1101 return 1
1104 test_done "$testroot" "$ret"
1107 test_merge_no_op() {
1108 local testroot=`test_init merge_no_op`
1109 local commit0=`git_show_head $testroot/repo`
1110 local commit0_author_time=`git_show_author_time $testroot/repo`
1112 (cd $testroot/repo && git checkout -q -b newbranch)
1113 echo "modified alpha on branch" > $testroot/repo/alpha
1114 git_commit $testroot/repo -m "committing to alpha on newbranch"
1115 local branch_commit=`git_show_branch_head $testroot/repo newbranch`
1117 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1118 ret=$?
1119 if [ $ret -ne 0 ]; then
1120 echo "got checkout failed unexpectedly" >&2
1121 test_done "$testroot" "$ret"
1122 return 1
1125 # create a conflicting commit
1126 (cd $testroot/repo && git checkout -q master)
1127 echo "modified alpha on master" > $testroot/repo/alpha
1128 git_commit $testroot/repo -m "committing to alpha on master"
1129 local master_commit=`git_show_head $testroot/repo`
1131 # need an up-to-date work tree for 'got merge'
1132 (cd $testroot/wt && got update > /dev/null)
1133 ret=$?
1134 if [ $ret -ne 0 ]; then
1135 echo "got update failed unexpectedly" >&2
1136 test_done "$testroot" "$ret"
1137 return 1
1140 (cd $testroot/wt && got merge newbranch \
1141 > $testroot/stdout 2> $testroot/stderr)
1142 ret=$?
1143 if [ $ret -eq 0 ]; then
1144 echo "got merge succeeded unexpectedly" >&2
1145 test_done "$testroot" "1"
1146 return 1
1149 echo "C alpha" >> $testroot/stdout.expected
1150 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1151 cmp -s $testroot/stdout.expected $testroot/stdout
1152 ret=$?
1153 if [ $ret -ne 0 ]; then
1154 diff -u $testroot/stdout.expected $testroot/stdout
1155 test_done "$testroot" "$ret"
1156 return 1
1159 echo "got: conflicts must be resolved before merging can continue" \
1160 > $testroot/stderr.expected
1161 cmp -s $testroot/stderr.expected $testroot/stderr
1162 ret=$?
1163 if [ $ret -ne 0 ]; then
1164 diff -u $testroot/stderr.expected $testroot/stderr
1165 test_done "$testroot" "$ret"
1166 return 1
1169 (cd $testroot/wt && got status > $testroot/stdout)
1171 echo "C alpha" > $testroot/stdout.expected
1172 cmp -s $testroot/stdout.expected $testroot/stdout
1173 ret=$?
1174 if [ $ret -ne 0 ]; then
1175 diff -u $testroot/stdout.expected $testroot/stdout
1176 test_done "$testroot" "$ret"
1177 return 1
1180 # resolve the conflict by reverting all changes; now it is no-op merge
1181 (cd $testroot/wt && got revert alpha > /dev/null)
1182 ret=$?
1183 if [ $ret -ne 0 ]; then
1184 echo "got revert failed unexpectedly" >&2
1185 test_done "$testroot" "$ret"
1186 return 1
1189 (cd $testroot/wt && got merge -c > $testroot/stdout \
1190 2> $testroot/stderr)
1191 ret=$?
1192 if [ $ret -ne 0 ]; then
1193 echo "got merge failed unexpectedly" >&2
1194 test_done "$testroot" "$ret"
1195 return 1
1198 echo -n '' > $testroot/stderr.expected
1199 cmp -s $testroot/stderr.expected $testroot/stderr
1200 ret=$?
1201 if [ $ret -ne 0 ]; then
1202 diff -u $testroot/stderr.expected $testroot/stderr
1203 test_done "$testroot" "$ret"
1204 return 1
1207 local merge_commit=`git_show_head $testroot/repo`
1208 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1209 > $testroot/stdout.expected
1210 echo $merge_commit >> $testroot/stdout.expected
1212 cmp -s $testroot/stdout.expected $testroot/stdout
1213 ret=$?
1214 if [ $ret -ne 0 ]; then
1215 diff -u $testroot/stdout.expected $testroot/stdout
1216 test_done "$testroot" "$ret"
1217 return 1
1220 (cd $testroot/wt && got status > $testroot/stdout)
1222 echo -n "" > $testroot/stdout.expected
1223 cmp -s $testroot/stdout.expected $testroot/stdout
1224 ret=$?
1225 if [ $ret -ne 0 ]; then
1226 diff -u $testroot/stdout.expected $testroot/stdout
1227 test_done "$testroot" "$ret"
1228 return 1
1231 # We should have created a merge commit with two parents.
1232 got log -r $testroot/repo -l1 -c $merge_commit | grep ^parent \
1233 > $testroot/stdout
1234 echo "parent 1: $master_commit" > $testroot/stdout.expected
1235 echo "parent 2: $branch_commit" >> $testroot/stdout.expected
1236 cmp -s $testroot/stdout.expected $testroot/stdout
1237 ret=$?
1238 if [ $ret -ne 0 ]; then
1239 diff -u $testroot/stdout.expected $testroot/stdout
1241 test_done "$testroot" "$ret"
1244 test_merge_imported_branch() {
1245 local testroot=`test_init merge_import`
1246 local commit0=`git_show_head $testroot/repo`
1247 local commit0_author_time=`git_show_author_time $testroot/repo`
1249 # import a new sub-tree to the 'files' branch such that
1250 # none of the files added here collide with existing ones
1251 mkdir -p $testroot/tree/there
1252 mkdir -p $testroot/tree/be/lots
1253 mkdir -p $testroot/tree/files
1254 echo "there should" > $testroot/tree/there/should
1255 echo "be lots of" > $testroot/tree/be/lots/of
1256 echo "files here" > $testroot/tree/files/here
1257 got import -r $testroot/repo -b files -m 'import files' \
1258 $testroot/tree > /dev/null
1260 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1261 ret=$?
1262 if [ $ret -ne 0 ]; then
1263 echo "got checkout failed unexpectedly" >&2
1264 test_done "$testroot" "$ret"
1265 return 1
1268 (cd $testroot/wt && got merge files > $testroot/stdout)
1269 ret=$?
1270 if [ $ret -ne 0 ]; then
1271 echo "got merge failed unexpectedly" >&2
1272 test_done "$testroot" "$ret"
1273 return 1
1276 local merge_commit0=`git_show_head $testroot/repo`
1277 cat > $testroot/stdout.expected <<EOF
1278 A be/lots/of
1279 A files/here
1280 A there/should
1281 Merged refs/heads/files into refs/heads/master: $merge_commit0
1282 EOF
1283 cmp -s $testroot/stdout.expected $testroot/stdout
1284 ret=$?
1285 if [ $ret -ne 0 ]; then
1286 diff -u $testroot/stdout.expected $testroot/stdout
1287 test_done "$testroot" "$ret"
1288 return 1
1291 # try to merge again while no new changes are available
1292 (cd $testroot/wt && got merge files > $testroot/stdout)
1293 ret=$?
1294 if [ $ret -ne 0 ]; then
1295 echo "got merge failed unexpectedly" >&2
1296 test_done "$testroot" "$ret"
1297 return 1
1299 echo "Already up-to-date" > $testroot/stdout.expected
1300 cmp -s $testroot/stdout.expected $testroot/stdout
1301 ret=$?
1302 if [ $ret -ne 0 ]; then
1303 diff -u $testroot/stdout.expected $testroot/stdout
1304 test_done "$testroot" "$ret"
1305 return 1
1308 # update the 'files' branch
1309 (cd $testroot/repo && git reset -q --hard master)
1310 (cd $testroot/repo && git checkout -q files)
1311 echo "indeed" > $testroot/repo/indeed
1312 (cd $testroot/repo && git add indeed)
1313 git_commit $testroot/repo -m "adding another file indeed"
1314 echo "be lots and lots of" > $testroot/repo/be/lots/of
1315 git_commit $testroot/repo -m "lots of changes"
1317 (cd $testroot/wt && got update > /dev/null)
1318 ret=$?
1319 if [ $ret -ne 0 ]; then
1320 echo "got update failed unexpectedly" >&2
1321 test_done "$testroot" "$ret"
1322 return 1
1325 # we should now be able to merge more changes from files branch
1326 (cd $testroot/wt && got merge files > $testroot/stdout)
1327 ret=$?
1328 if [ $ret -ne 0 ]; then
1329 echo "got merge failed unexpectedly" >&2
1330 test_done "$testroot" "$ret"
1331 return 1
1334 local merge_commit1=`git_show_branch_head $testroot/repo master`
1335 cat > $testroot/stdout.expected <<EOF
1336 G be/lots/of
1337 A indeed
1338 Merged refs/heads/files into refs/heads/master: $merge_commit1
1339 EOF
1341 cmp -s $testroot/stdout.expected $testroot/stdout
1342 ret=$?
1343 if [ $ret -ne 0 ]; then
1344 diff -u $testroot/stdout.expected $testroot/stdout
1346 test_done "$testroot" "$ret"
1349 test_merge_interrupt() {
1350 local testroot=`test_init merge_interrupt`
1351 local commit0=`git_show_head $testroot/repo`
1352 local commit0_author_time=`git_show_author_time $testroot/repo`
1354 (cd $testroot/repo && git checkout -q -b newbranch)
1355 echo "modified alpha on branch" > $testroot/repo/alpha
1356 git_commit $testroot/repo -m "committing to alpha on newbranch"
1357 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1359 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1360 ret=$?
1361 if [ $ret -ne 0 ]; then
1362 echo "got checkout failed unexpectedly" >&2
1363 test_done "$testroot" "$ret"
1364 return 1
1367 # create a non-conflicting commit
1368 (cd $testroot/repo && git checkout -q master)
1369 echo "modified beta on master" > $testroot/repo/beta
1370 git_commit $testroot/repo -m "committing to beta on master"
1371 local master_commit=`git_show_head $testroot/repo`
1373 # need an up-to-date work tree for 'got merge'
1374 (cd $testroot/wt && got update > /dev/null)
1375 ret=$?
1376 if [ $ret -ne 0 ]; then
1377 echo "got update failed unexpectedly" >&2
1378 test_done "$testroot" "$ret"
1379 return 1
1382 (cd $testroot/wt && got merge -n newbranch \
1383 > $testroot/stdout 2> $testroot/stderr)
1384 ret=$?
1385 if [ $ret -ne 0 ]; then
1386 echo "got merge failed unexpectedly" >&2
1387 test_done "$testroot" "1"
1388 return 1
1391 echo "G alpha" > $testroot/stdout.expected
1392 echo "Merge of refs/heads/newbranch interrupted on request" \
1393 >> $testroot/stdout.expected
1394 cmp -s $testroot/stdout.expected $testroot/stdout
1395 ret=$?
1396 if [ $ret -ne 0 ]; then
1397 diff -u $testroot/stdout.expected $testroot/stdout
1398 test_done "$testroot" "$ret"
1399 return 1
1402 (cd $testroot/wt && got status > $testroot/stdout)
1404 echo "M alpha" > $testroot/stdout.expected
1405 cmp -s $testroot/stdout.expected $testroot/stdout
1406 ret=$?
1407 if [ $ret -ne 0 ]; then
1408 diff -u $testroot/stdout.expected $testroot/stdout
1409 test_done "$testroot" "$ret"
1410 return 1
1413 echo "modified alpha on branch" > $testroot/content.expected
1414 cat $testroot/wt/alpha > $testroot/content
1415 cmp -s $testroot/content.expected $testroot/content
1416 ret=$?
1417 if [ $ret -ne 0 ]; then
1418 diff -u $testroot/content.expected $testroot/content
1419 test_done "$testroot" "$ret"
1420 return 1
1423 # adjust merge result
1424 echo "adjusted merge result" > $testroot/wt/alpha
1426 # continue the merge
1427 (cd $testroot/wt && got merge -c > $testroot/stdout)
1428 ret=$?
1429 if [ $ret -ne 0 ]; then
1430 echo "got merge failed unexpectedly" >&2
1431 test_done "$testroot" "$ret"
1432 return 1
1435 local merge_commit=`git_show_head $testroot/repo`
1437 echo "M alpha" > $testroot/stdout.expected
1438 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1439 >> $testroot/stdout.expected
1440 echo $merge_commit >> $testroot/stdout.expected
1442 cmp -s $testroot/stdout.expected $testroot/stdout
1443 ret=$?
1444 if [ $ret -ne 0 ]; then
1445 diff -u $testroot/stdout.expected $testroot/stdout
1446 test_done "$testroot" "$ret"
1447 return 1
1450 (cd $testroot/wt && got status > $testroot/stdout)
1452 echo -n > $testroot/stdout.expected
1453 cmp -s $testroot/stdout.expected $testroot/stdout
1454 ret=$?
1455 if [ $ret -ne 0 ]; then
1456 diff -u $testroot/stdout.expected $testroot/stdout
1457 test_done "$testroot" "$ret"
1458 return 1
1461 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1462 echo "commit $merge_commit (master)" > $testroot/stdout.expected
1463 echo "commit $master_commit" >> $testroot/stdout.expected
1464 echo "commit $commit0" >> $testroot/stdout.expected
1465 cmp -s $testroot/stdout.expected $testroot/stdout
1466 ret=$?
1467 if [ $ret -ne 0 ]; then
1468 diff -u $testroot/stdout.expected $testroot/stdout
1469 test_done "$testroot" "$ret"
1470 return 1
1473 (cd $testroot/wt && got update > $testroot/stdout)
1475 echo 'Already up-to-date' > $testroot/stdout.expected
1476 cmp -s $testroot/stdout.expected $testroot/stdout
1477 ret=$?
1478 if [ $ret -ne 0 ]; then
1479 diff -u $testroot/stdout.expected $testroot/stdout
1480 test_done "$testroot" "$ret"
1481 return 1
1484 # We should have created a merge commit with two parents.
1485 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
1486 echo "parent 1: $master_commit" > $testroot/stdout.expected
1487 echo "parent 2: $branch_commit0" >> $testroot/stdout.expected
1488 cmp -s $testroot/stdout.expected $testroot/stdout
1489 ret=$?
1490 if [ $ret -ne 0 ]; then
1491 diff -u $testroot/stdout.expected $testroot/stdout
1493 test_done "$testroot" "$ret"
1496 test_merge_umask() {
1497 local testroot=`test_init merge_umask`
1499 (cd $testroot/repo && git checkout -q -b newbranch)
1500 echo "modified alpha on branch" >$testroot/repo/alpha
1501 git_commit "$testroot/repo" -m "committing alpha on newbranch"
1502 echo "modified delta on branch" >$testroot/repo/gamma/delta
1503 git_commit "$testroot/repo" -m "committing delta on newbranch"
1505 # diverge from newbranch
1506 (cd "$testroot/repo" && git checkout -q master)
1507 echo "modified beta on master" >$testroot/repo/beta
1508 git_commit "$testroot/repo" -m "committing zeto no master"
1510 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1512 # using a subshell to avoid clobbering global umask
1513 (umask 077 && cd "$testroot/wt" && got merge newbranch) >/dev/null
1515 for f in alpha gamma/delta; do
1516 ls -l "$testroot/wt/$f" | grep -q ^-rw-------
1517 if [ $? -ne 0 ]; then
1518 echo "$f is not 0600 after merge" >&2
1519 ls -l "$testroot/wt/$f" >&2
1520 test_done "$testroot" 1
1522 done
1524 test_done "$testroot" 0
1527 test_merge_gitconfig_author() {
1528 local testroot=`test_init merge_gitconfig_author`
1530 (cd $testroot/repo && git config user.name 'Flan Luck')
1531 (cd $testroot/repo && git config user.email 'flan_luck@openbsd.org')
1533 (cd $testroot/repo && git checkout -q -b newbranch)
1534 echo "modified alpha on branch" >$testroot/repo/alpha
1535 git_commit "$testroot/repo" -m "committing alpha on newbranch"
1536 echo "modified delta on branch" >$testroot/repo/gamma/delta
1537 git_commit "$testroot/repo" -m "committing delta on newbranch"
1539 # diverge from newbranch
1540 (cd "$testroot/repo" && git checkout -q master)
1541 echo "modified beta on master" >$testroot/repo/beta
1542 git_commit "$testroot/repo" -m "committing zeto no master"
1544 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1546 # unset in a subshell to avoid affecting our environment
1547 (unset GOT_IGNORE_GITCONFIG && cd $testroot/wt && \
1548 got merge newbranch > /dev/null)
1550 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
1551 ret=$?
1552 if [ $ret -ne 0 ]; then
1553 test_done "$testroot" "$ret"
1554 return 1
1557 echo "from: Flan Luck <flan_luck@openbsd.org>" \
1558 > $testroot/stdout.expected
1559 cmp -s $testroot/stdout.expected $testroot/stdout
1560 ret=$?
1561 if [ $ret -ne 0 ]; then
1562 diff -u $testroot/stdout.expected $testroot/stdout
1564 test_done "$testroot" "$ret"
1567 test_parseargs "$@"
1568 run_test test_merge_basic
1569 run_test test_merge_continue
1570 run_test test_merge_continue_new_commit
1571 run_test test_merge_abort
1572 run_test test_merge_in_progress
1573 run_test test_merge_path_prefix
1574 run_test test_merge_missing_file
1575 run_test test_merge_no_op
1576 run_test test_merge_imported_branch
1577 run_test test_merge_interrupt
1578 run_test test_merge_umask
1579 run_test test_merge_gitconfig_author