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_abort() {
594 local testroot=`test_init merge_abort`
595 local commit0=`git_show_head $testroot/repo`
596 local commit0_author_time=`git_show_author_time $testroot/repo`
598 (cd $testroot/repo && git checkout -q -b newbranch)
599 echo "modified delta on branch" > $testroot/repo/gamma/delta
600 git_commit $testroot/repo -m "committing to delta on newbranch"
601 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
603 echo "modified alpha on branch" > $testroot/repo/alpha
604 git_commit $testroot/repo -m "committing to alpha on newbranch"
605 local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
606 (cd $testroot/repo && git rm -q beta)
607 git_commit $testroot/repo -m "removing beta on newbranch"
608 local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
609 echo "new file on branch" > $testroot/repo/epsilon/new
610 (cd $testroot/repo && git add epsilon/new)
611 git_commit $testroot/repo -m "adding new file on newbranch"
612 local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
613 (cd $testroot/repo && ln -s alpha symlink && git add symlink)
614 git_commit $testroot/repo -m "adding symlink on newbranch"
615 local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
617 got checkout -b master $testroot/repo $testroot/wt > /dev/null
618 ret=$?
619 if [ $ret -ne 0 ]; then
620 echo "got checkout failed unexpectedly" >&2
621 test_done "$testroot" "$ret"
622 return 1
623 fi
625 # unrelated unversioned file in work tree
626 touch $testroot/wt/unversioned-file
628 # create a conflicting commit
629 (cd $testroot/repo && git checkout -q master)
630 echo "modified alpha on master" > $testroot/repo/alpha
631 git_commit $testroot/repo -m "committing to alpha on master"
632 local master_commit=`git_show_head $testroot/repo`
634 # need an up-to-date work tree for 'got merge'
635 (cd $testroot/wt && got update > /dev/null)
636 ret=$?
637 if [ $ret -ne 0 ]; then
638 echo "got update failed unexpectedly" >&2
639 test_done "$testroot" "$ret"
640 return 1
641 fi
643 (cd $testroot/wt && got merge newbranch \
644 > $testroot/stdout 2> $testroot/stderr)
645 ret=$?
646 if [ $ret -eq 0 ]; then
647 echo "got merge succeeded unexpectedly" >&2
648 test_done "$testroot" "1"
649 return 1
650 fi
652 echo "C alpha" >> $testroot/stdout.expected
653 echo "D beta" >> $testroot/stdout.expected
654 echo "A epsilon/new" >> $testroot/stdout.expected
655 echo "G gamma/delta" >> $testroot/stdout.expected
656 echo "A symlink" >> $testroot/stdout.expected
657 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
658 cmp -s $testroot/stdout.expected $testroot/stdout
659 ret=$?
660 if [ $ret -ne 0 ]; then
661 diff -u $testroot/stdout.expected $testroot/stdout
662 test_done "$testroot" "$ret"
663 return 1
664 fi
666 echo "got: conflicts must be resolved before merging can continue" \
667 > $testroot/stderr.expected
668 cmp -s $testroot/stderr.expected $testroot/stderr
669 ret=$?
670 if [ $ret -ne 0 ]; then
671 diff -u $testroot/stderr.expected $testroot/stderr
672 test_done "$testroot" "$ret"
673 return 1
674 fi
676 # unrelated added file added during conflict resolution
677 touch $testroot/wt/added-file
678 (cd $testroot/wt && got add added-file > /dev/null)
680 (cd $testroot/wt && got status > $testroot/stdout)
682 echo "A added-file" > $testroot/stdout.expected
683 echo "C alpha" >> $testroot/stdout.expected
684 echo "D beta" >> $testroot/stdout.expected
685 echo "A epsilon/new" >> $testroot/stdout.expected
686 echo "M gamma/delta" >> $testroot/stdout.expected
687 echo "A symlink" >> $testroot/stdout.expected
688 echo "? unversioned-file" >> $testroot/stdout.expected
689 cmp -s $testroot/stdout.expected $testroot/stdout
690 ret=$?
691 if [ $ret -ne 0 ]; then
692 diff -u $testroot/stdout.expected $testroot/stdout
693 test_done "$testroot" "$ret"
694 return 1
695 fi
697 (cd $testroot/wt && got merge -a > $testroot/stdout)
698 ret=$?
699 if [ $ret -ne 0 ]; then
700 echo "got merge failed unexpectedly" >&2
701 test_done "$testroot" "$ret"
702 return 1
703 fi
705 echo "R added-file" > $testroot/stdout.expected
706 echo "R alpha" >> $testroot/stdout.expected
707 echo "R beta" >> $testroot/stdout.expected
708 echo "R epsilon/new" >> $testroot/stdout.expected
709 echo "R gamma/delta" >> $testroot/stdout.expected
710 echo "R symlink" >> $testroot/stdout.expected
711 echo "G added-file" >> $testroot/stdout.expected
712 echo "Merge of refs/heads/newbranch aborted" \
713 >> $testroot/stdout.expected
715 cmp -s $testroot/stdout.expected $testroot/stdout
716 ret=$?
717 if [ $ret -ne 0 ]; then
718 diff -u $testroot/stdout.expected $testroot/stdout
719 test_done "$testroot" "$ret"
720 return 1
721 fi
723 echo "delta" > $testroot/content.expected
724 cat $testroot/wt/gamma/delta > $testroot/content
725 cmp -s $testroot/content.expected $testroot/content
726 ret=$?
727 if [ $ret -ne 0 ]; then
728 diff -u $testroot/content.expected $testroot/content
729 test_done "$testroot" "$ret"
730 return 1
731 fi
733 echo "modified alpha on master" > $testroot/content.expected
734 cat $testroot/wt/alpha > $testroot/content
735 cmp -s $testroot/content.expected $testroot/content
736 ret=$?
737 if [ $ret -ne 0 ]; then
738 diff -u $testroot/content.expected $testroot/content
739 test_done "$testroot" "$ret"
740 return 1
741 fi
743 echo "beta" > $testroot/content.expected
744 cat $testroot/wt/beta > $testroot/content
745 cmp -s $testroot/content.expected $testroot/content
746 ret=$?
747 if [ $ret -ne 0 ]; then
748 diff -u $testroot/content.expected $testroot/content
749 test_done "$testroot" "$ret"
750 return 1
751 fi
753 if [ -e $testroot/wt/epsilon/new ]; then
754 echo "reverted file epsilon/new still exists on disk" >&2
755 test_done "$testroot" "1"
756 return 1
757 fi
759 if [ -e $testroot/wt/symlink ]; then
760 echo "reverted symlink still exists on disk" >&2
761 test_done "$testroot" "1"
762 return 1
763 fi
765 (cd $testroot/wt && got status > $testroot/stdout)
767 echo "? added-file" > $testroot/stdout.expected
768 echo "? unversioned-file" >> $testroot/stdout.expected
769 cmp -s $testroot/stdout.expected $testroot/stdout
770 ret=$?
771 if [ $ret -ne 0 ]; then
772 diff -u $testroot/stdout.expected $testroot/stdout
773 test_done "$testroot" "$ret"
774 return 1
775 fi
777 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
778 echo "commit $master_commit (master)" > $testroot/stdout.expected
779 echo "commit $commit0" >> $testroot/stdout.expected
780 cmp -s $testroot/stdout.expected $testroot/stdout
781 ret=$?
782 if [ $ret -ne 0 ]; then
783 diff -u $testroot/stdout.expected $testroot/stdout
784 test_done "$testroot" "$ret"
785 return 1
786 fi
788 (cd $testroot/wt && got update > $testroot/stdout)
790 echo 'Already up-to-date' > $testroot/stdout.expected
791 cmp -s $testroot/stdout.expected $testroot/stdout
792 ret=$?
793 if [ $ret -ne 0 ]; then
794 diff -u $testroot/stdout.expected $testroot/stdout
795 fi
796 test_done "$testroot" "$ret"
799 test_merge_in_progress() {
800 local testroot=`test_init merge_in_progress`
801 local commit0=`git_show_head $testroot/repo`
802 local commit0_author_time=`git_show_author_time $testroot/repo`
804 (cd $testroot/repo && git checkout -q -b newbranch)
805 echo "modified alpha on branch" > $testroot/repo/alpha
806 git_commit $testroot/repo -m "committing to alpha on newbranch"
807 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
809 got checkout -b master $testroot/repo $testroot/wt > /dev/null
810 ret=$?
811 if [ $ret -ne 0 ]; then
812 echo "got checkout failed unexpectedly" >&2
813 test_done "$testroot" "$ret"
814 return 1
815 fi
817 # create a conflicting commit
818 (cd $testroot/repo && git checkout -q master)
819 echo "modified alpha on master" > $testroot/repo/alpha
820 git_commit $testroot/repo -m "committing to alpha on master"
821 local master_commit=`git_show_head $testroot/repo`
823 # need an up-to-date work tree for 'got merge'
824 (cd $testroot/wt && got update > /dev/null)
825 ret=$?
826 if [ $ret -ne 0 ]; then
827 echo "got update failed unexpectedly" >&2
828 test_done "$testroot" "$ret"
829 return 1
830 fi
832 (cd $testroot/wt && got merge newbranch \
833 > $testroot/stdout 2> $testroot/stderr)
834 ret=$?
835 if [ $ret -eq 0 ]; then
836 echo "got merge succeeded unexpectedly" >&2
837 test_done "$testroot" "1"
838 return 1
839 fi
841 echo "C alpha" >> $testroot/stdout.expected
842 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
843 cmp -s $testroot/stdout.expected $testroot/stdout
844 ret=$?
845 if [ $ret -ne 0 ]; then
846 diff -u $testroot/stdout.expected $testroot/stdout
847 test_done "$testroot" "$ret"
848 return 1
849 fi
851 echo "got: conflicts must be resolved before merging can continue" \
852 > $testroot/stderr.expected
853 cmp -s $testroot/stderr.expected $testroot/stderr
854 ret=$?
855 if [ $ret -ne 0 ]; then
856 diff -u $testroot/stderr.expected $testroot/stderr
857 test_done "$testroot" "$ret"
858 return 1
859 fi
861 (cd $testroot/wt && got status > $testroot/stdout)
863 echo "C alpha" > $testroot/stdout.expected
864 cmp -s $testroot/stdout.expected $testroot/stdout
865 ret=$?
866 if [ $ret -ne 0 ]; then
867 diff -u $testroot/stdout.expected $testroot/stdout
868 test_done "$testroot" "$ret"
869 return 1
870 fi
872 for cmd in update commit histedit "rebase newbranch" \
873 "integrate newbranch" "merge newbranch" "stage alpha"; do
874 (cd $testroot/wt && got $cmd > $testroot/stdout \
875 2> $testroot/stderr)
876 ret=$?
877 if [ $ret -eq 0 ]; then
878 echo "got $cmd succeeded unexpectedly" >&2
879 test_done "$testroot" "1"
880 return 1
881 fi
883 echo -n > $testroot/stdout.expected
884 cmp -s $testroot/stdout.expected $testroot/stdout
885 ret=$?
886 if [ $ret -ne 0 ]; then
887 diff -u $testroot/stdout.expected $testroot/stdout
888 test_done "$testroot" "$ret"
889 return 1
890 fi
892 echo -n "got: a merge operation is in progress in this " \
893 > $testroot/stderr.expected
894 echo "work tree and must be continued or aborted first" \
895 >> $testroot/stderr.expected
896 cmp -s $testroot/stderr.expected $testroot/stderr
897 ret=$?
898 if [ $ret -ne 0 ]; then
899 diff -u $testroot/stderr.expected $testroot/stderr
900 test_done "$testroot" "$ret"
901 return 1
902 fi
903 done
905 test_done "$testroot" "$ret"
908 test_merge_path_prefix() {
909 local testroot=`test_init merge_path_prefix`
910 local commit0=`git_show_head $testroot/repo`
911 local commit0_author_time=`git_show_author_time $testroot/repo`
913 (cd $testroot/repo && git checkout -q -b newbranch)
914 echo "modified alpha on branch" > $testroot/repo/alpha
915 git_commit $testroot/repo -m "committing to alpha on newbranch"
916 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
918 got checkout -p epsilon -b master $testroot/repo $testroot/wt \
919 > /dev/null
920 ret=$?
921 if [ $ret -ne 0 ]; then
922 echo "got checkout failed unexpectedly" >&2
923 test_done "$testroot" "$ret"
924 return 1
925 fi
927 # create a conflicting commit
928 (cd $testroot/repo && git checkout -q master)
929 echo "modified alpha on master" > $testroot/repo/alpha
930 git_commit $testroot/repo -m "committing to alpha on master"
931 local master_commit=`git_show_head $testroot/repo`
933 # need an up-to-date work tree for 'got merge'
934 (cd $testroot/wt && got update > /dev/null)
935 ret=$?
936 if [ $ret -ne 0 ]; then
937 echo "got update failed unexpectedly" >&2
938 test_done "$testroot" "$ret"
939 return 1
940 fi
942 (cd $testroot/wt && got merge newbranch \
943 > $testroot/stdout 2> $testroot/stderr)
944 ret=$?
945 if [ $ret -eq 0 ]; then
946 echo "got merge succeeded unexpectedly" >&2
947 test_done "$testroot" "1"
948 return 1
949 fi
951 echo -n "got: cannot merge branch which contains changes outside " \
952 > $testroot/stderr.expected
953 echo "of this work tree's path prefix" >> $testroot/stderr.expected
954 cmp -s $testroot/stderr.expected $testroot/stderr
955 ret=$?
956 if [ $ret -ne 0 ]; then
957 diff -u $testroot/stderr.expected $testroot/stderr
958 fi
959 test_done "$testroot" "$ret"
962 test_merge_missing_file() {
963 local testroot=`test_init merge_missing_file`
964 local commit0=`git_show_head $testroot/repo`
965 local commit0_author_time=`git_show_author_time $testroot/repo`
967 (cd $testroot/repo && git checkout -q -b newbranch)
968 echo "modified alpha on branch" > $testroot/repo/alpha
969 echo "modified delta on branch" > $testroot/repo/gamma/delta
970 git_commit $testroot/repo -m "committing to alpha and delta"
971 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
973 got checkout -b master $testroot/repo $testroot/wt > /dev/null
974 ret=$?
975 if [ $ret -ne 0 ]; then
976 echo "got checkout failed unexpectedly" >&2
977 test_done "$testroot" "$ret"
978 return 1
979 fi
981 # create a conflicting commit which renames alpha
982 (cd $testroot/repo && git checkout -q master)
983 (cd $testroot/repo && git mv alpha epsilon/alpha-moved)
984 git_commit $testroot/repo -m "moving alpha on master"
985 local master_commit=`git_show_head $testroot/repo`
987 # need an up-to-date work tree for 'got merge'
988 (cd $testroot/wt && got update > /dev/null)
989 ret=$?
990 if [ $ret -ne 0 ]; then
991 echo "got update failed unexpectedly" >&2
992 test_done "$testroot" "$ret"
993 return 1
994 fi
996 (cd $testroot/wt && got merge newbranch \
997 > $testroot/stdout 2> $testroot/stderr)
998 ret=$?
999 if [ $ret -eq 0 ]; then
1000 echo "got merge succeeded unexpectedly" >&2
1001 test_done "$testroot" "1"
1002 return 1
1005 echo "! alpha" > $testroot/stdout.expected
1006 echo "G gamma/delta" >> $testroot/stdout.expected
1007 echo -n "Files which had incoming changes but could not be found " \
1008 >> $testroot/stdout.expected
1009 echo "in the work tree: 1" >> $testroot/stdout.expected
1010 cmp -s $testroot/stdout.expected $testroot/stdout
1011 ret=$?
1012 if [ $ret -ne 0 ]; then
1013 diff -u $testroot/stdout.expected $testroot/stdout
1014 test_done "$testroot" "$ret"
1015 return 1
1018 echo -n "got: changes destined for some files " \
1019 > $testroot/stderr.expected
1020 echo -n "were not yet merged and should be merged manually if " \
1021 >> $testroot/stderr.expected
1022 echo "required before the merge operation is continued" \
1023 >> $testroot/stderr.expected
1024 cmp -s $testroot/stderr.expected $testroot/stderr
1025 ret=$?
1026 if [ $ret -ne 0 ]; then
1027 diff -u $testroot/stderr.expected $testroot/stderr
1028 test_done "$testroot" "$ret"
1029 return 1
1032 (cd $testroot/wt && got status > $testroot/stdout)
1034 echo "M gamma/delta" > $testroot/stdout.expected
1035 cmp -s $testroot/stdout.expected $testroot/stdout
1036 ret=$?
1037 if [ $ret -ne 0 ]; then
1038 diff -u $testroot/stdout.expected $testroot/stdout
1039 test_done "$testroot" "$ret"
1040 return 1
1043 test_done "$testroot" "$ret"
1046 test_merge_no_op() {
1047 local testroot=`test_init merge_no_op`
1048 local commit0=`git_show_head $testroot/repo`
1049 local commit0_author_time=`git_show_author_time $testroot/repo`
1051 (cd $testroot/repo && git checkout -q -b newbranch)
1052 echo "modified alpha on branch" > $testroot/repo/alpha
1053 git_commit $testroot/repo -m "committing to alpha on newbranch"
1054 local branch_commit=`git_show_branch_head $testroot/repo newbranch`
1056 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1057 ret=$?
1058 if [ $ret -ne 0 ]; then
1059 echo "got checkout failed unexpectedly" >&2
1060 test_done "$testroot" "$ret"
1061 return 1
1064 # create a conflicting commit
1065 (cd $testroot/repo && git checkout -q master)
1066 echo "modified alpha on master" > $testroot/repo/alpha
1067 git_commit $testroot/repo -m "committing to alpha on master"
1068 local master_commit=`git_show_head $testroot/repo`
1070 # need an up-to-date work tree for 'got merge'
1071 (cd $testroot/wt && got update > /dev/null)
1072 ret=$?
1073 if [ $ret -ne 0 ]; then
1074 echo "got update failed unexpectedly" >&2
1075 test_done "$testroot" "$ret"
1076 return 1
1079 (cd $testroot/wt && got merge newbranch \
1080 > $testroot/stdout 2> $testroot/stderr)
1081 ret=$?
1082 if [ $ret -eq 0 ]; then
1083 echo "got merge succeeded unexpectedly" >&2
1084 test_done "$testroot" "1"
1085 return 1
1088 echo "C alpha" >> $testroot/stdout.expected
1089 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1090 cmp -s $testroot/stdout.expected $testroot/stdout
1091 ret=$?
1092 if [ $ret -ne 0 ]; then
1093 diff -u $testroot/stdout.expected $testroot/stdout
1094 test_done "$testroot" "$ret"
1095 return 1
1098 echo "got: conflicts must be resolved before merging can continue" \
1099 > $testroot/stderr.expected
1100 cmp -s $testroot/stderr.expected $testroot/stderr
1101 ret=$?
1102 if [ $ret -ne 0 ]; then
1103 diff -u $testroot/stderr.expected $testroot/stderr
1104 test_done "$testroot" "$ret"
1105 return 1
1108 (cd $testroot/wt && got status > $testroot/stdout)
1110 echo "C alpha" > $testroot/stdout.expected
1111 cmp -s $testroot/stdout.expected $testroot/stdout
1112 ret=$?
1113 if [ $ret -ne 0 ]; then
1114 diff -u $testroot/stdout.expected $testroot/stdout
1115 test_done "$testroot" "$ret"
1116 return 1
1119 # resolve the conflict by reverting all changes; now it is no-op merge
1120 (cd $testroot/wt && got revert alpha > /dev/null)
1121 ret=$?
1122 if [ $ret -ne 0 ]; then
1123 echo "got revert failed unexpectedly" >&2
1124 test_done "$testroot" "$ret"
1125 return 1
1128 (cd $testroot/wt && got merge -c > $testroot/stdout \
1129 2> $testroot/stderr)
1130 ret=$?
1131 if [ $ret -ne 0 ]; then
1132 echo "got merge failed unexpectedly" >&2
1133 test_done "$testroot" "$ret"
1134 return 1
1137 echo -n '' > $testroot/stderr.expected
1138 cmp -s $testroot/stderr.expected $testroot/stderr
1139 ret=$?
1140 if [ $ret -ne 0 ]; then
1141 diff -u $testroot/stderr.expected $testroot/stderr
1142 test_done "$testroot" "$ret"
1143 return 1
1146 local merge_commit=`git_show_head $testroot/repo`
1147 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1148 > $testroot/stdout.expected
1149 echo $merge_commit >> $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 (cd $testroot/wt && got status > $testroot/stdout)
1161 echo -n "" > $testroot/stdout.expected
1162 cmp -s $testroot/stdout.expected $testroot/stdout
1163 ret=$?
1164 if [ $ret -ne 0 ]; then
1165 diff -u $testroot/stdout.expected $testroot/stdout
1166 test_done "$testroot" "$ret"
1167 return 1
1170 # We should have created a merge commit with two parents.
1171 got log -r $testroot/repo -l1 -c $merge_commit | grep ^parent \
1172 > $testroot/stdout
1173 echo "parent 1: $master_commit" > $testroot/stdout.expected
1174 echo "parent 2: $branch_commit" >> $testroot/stdout.expected
1175 cmp -s $testroot/stdout.expected $testroot/stdout
1176 ret=$?
1177 if [ $ret -ne 0 ]; then
1178 diff -u $testroot/stdout.expected $testroot/stdout
1180 test_done "$testroot" "$ret"
1183 test_merge_imported_branch() {
1184 local testroot=`test_init merge_import`
1185 local commit0=`git_show_head $testroot/repo`
1186 local commit0_author_time=`git_show_author_time $testroot/repo`
1188 # import a new sub-tree to the 'files' branch such that
1189 # none of the files added here collide with existing ones
1190 mkdir -p $testroot/tree/there
1191 mkdir -p $testroot/tree/be/lots
1192 mkdir -p $testroot/tree/files
1193 echo "there should" > $testroot/tree/there/should
1194 echo "be lots of" > $testroot/tree/be/lots/of
1195 echo "files here" > $testroot/tree/files/here
1196 got import -r $testroot/repo -b files -m 'import files' \
1197 $testroot/tree > /dev/null
1199 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1200 ret=$?
1201 if [ $ret -ne 0 ]; then
1202 echo "got checkout failed unexpectedly" >&2
1203 test_done "$testroot" "$ret"
1204 return 1
1207 (cd $testroot/wt && got merge files > $testroot/stdout)
1208 ret=$?
1209 if [ $ret -ne 0 ]; then
1210 echo "got merge failed unexpectedly" >&2
1211 test_done "$testroot" "$ret"
1212 return 1
1215 local merge_commit0=`git_show_head $testroot/repo`
1216 cat > $testroot/stdout.expected <<EOF
1217 A be/lots/of
1218 A files/here
1219 A there/should
1220 Merged refs/heads/files into refs/heads/master: $merge_commit0
1221 EOF
1222 cmp -s $testroot/stdout.expected $testroot/stdout
1223 ret=$?
1224 if [ $ret -ne 0 ]; then
1225 diff -u $testroot/stdout.expected $testroot/stdout
1226 test_done "$testroot" "$ret"
1227 return 1
1230 # try to merge again while no new changes are available
1231 (cd $testroot/wt && got merge files > $testroot/stdout)
1232 ret=$?
1233 if [ $ret -ne 0 ]; then
1234 echo "got merge failed unexpectedly" >&2
1235 test_done "$testroot" "$ret"
1236 return 1
1238 echo "Already up-to-date" > $testroot/stdout.expected
1239 cmp -s $testroot/stdout.expected $testroot/stdout
1240 ret=$?
1241 if [ $ret -ne 0 ]; then
1242 diff -u $testroot/stdout.expected $testroot/stdout
1243 test_done "$testroot" "$ret"
1244 return 1
1247 # update the 'files' branch
1248 (cd $testroot/repo && git reset -q --hard master)
1249 (cd $testroot/repo && git checkout -q files)
1250 echo "indeed" > $testroot/repo/indeed
1251 (cd $testroot/repo && git add indeed)
1252 git_commit $testroot/repo -m "adding another file indeed"
1253 echo "be lots and lots of" > $testroot/repo/be/lots/of
1254 git_commit $testroot/repo -m "lots of changes"
1256 (cd $testroot/wt && got update > /dev/null)
1257 ret=$?
1258 if [ $ret -ne 0 ]; then
1259 echo "got update failed unexpectedly" >&2
1260 test_done "$testroot" "$ret"
1261 return 1
1264 # we should now be able to merge more changes from files branch
1265 (cd $testroot/wt && got merge files > $testroot/stdout)
1266 ret=$?
1267 if [ $ret -ne 0 ]; then
1268 echo "got merge failed unexpectedly" >&2
1269 test_done "$testroot" "$ret"
1270 return 1
1273 local merge_commit1=`git_show_branch_head $testroot/repo master`
1274 cat > $testroot/stdout.expected <<EOF
1275 G be/lots/of
1276 A indeed
1277 Merged refs/heads/files into refs/heads/master: $merge_commit1
1278 EOF
1280 cmp -s $testroot/stdout.expected $testroot/stdout
1281 ret=$?
1282 if [ $ret -ne 0 ]; then
1283 diff -u $testroot/stdout.expected $testroot/stdout
1285 test_done "$testroot" "$ret"
1288 test_merge_interrupt() {
1289 local testroot=`test_init merge_interrupt`
1290 local commit0=`git_show_head $testroot/repo`
1291 local commit0_author_time=`git_show_author_time $testroot/repo`
1293 (cd $testroot/repo && git checkout -q -b newbranch)
1294 echo "modified alpha on branch" > $testroot/repo/alpha
1295 git_commit $testroot/repo -m "committing to alpha on newbranch"
1296 local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1298 got checkout -b master $testroot/repo $testroot/wt > /dev/null
1299 ret=$?
1300 if [ $ret -ne 0 ]; then
1301 echo "got checkout failed unexpectedly" >&2
1302 test_done "$testroot" "$ret"
1303 return 1
1306 # create a non-conflicting commit
1307 (cd $testroot/repo && git checkout -q master)
1308 echo "modified beta on master" > $testroot/repo/beta
1309 git_commit $testroot/repo -m "committing to beta on master"
1310 local master_commit=`git_show_head $testroot/repo`
1312 # need an up-to-date work tree for 'got merge'
1313 (cd $testroot/wt && got update > /dev/null)
1314 ret=$?
1315 if [ $ret -ne 0 ]; then
1316 echo "got update failed unexpectedly" >&2
1317 test_done "$testroot" "$ret"
1318 return 1
1321 (cd $testroot/wt && got merge -n newbranch \
1322 > $testroot/stdout 2> $testroot/stderr)
1323 ret=$?
1324 if [ $ret -ne 0 ]; then
1325 echo "got merge failed unexpectedly" >&2
1326 test_done "$testroot" "1"
1327 return 1
1330 echo "G alpha" > $testroot/stdout.expected
1331 echo "Merge of refs/heads/newbranch interrupted on request" \
1332 >> $testroot/stdout.expected
1333 cmp -s $testroot/stdout.expected $testroot/stdout
1334 ret=$?
1335 if [ $ret -ne 0 ]; then
1336 diff -u $testroot/stdout.expected $testroot/stdout
1337 test_done "$testroot" "$ret"
1338 return 1
1341 (cd $testroot/wt && got status > $testroot/stdout)
1343 echo "M alpha" > $testroot/stdout.expected
1344 cmp -s $testroot/stdout.expected $testroot/stdout
1345 ret=$?
1346 if [ $ret -ne 0 ]; then
1347 diff -u $testroot/stdout.expected $testroot/stdout
1348 test_done "$testroot" "$ret"
1349 return 1
1352 echo "modified alpha on branch" > $testroot/content.expected
1353 cat $testroot/wt/alpha > $testroot/content
1354 cmp -s $testroot/content.expected $testroot/content
1355 ret=$?
1356 if [ $ret -ne 0 ]; then
1357 diff -u $testroot/content.expected $testroot/content
1358 test_done "$testroot" "$ret"
1359 return 1
1362 # adjust merge result
1363 echo "adjusted merge result" > $testroot/wt/alpha
1365 # continue the merge
1366 (cd $testroot/wt && got merge -c > $testroot/stdout)
1367 ret=$?
1368 if [ $ret -ne 0 ]; then
1369 echo "got merge failed unexpectedly" >&2
1370 test_done "$testroot" "$ret"
1371 return 1
1374 local merge_commit=`git_show_head $testroot/repo`
1376 echo "M alpha" > $testroot/stdout.expected
1377 echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1378 >> $testroot/stdout.expected
1379 echo $merge_commit >> $testroot/stdout.expected
1381 cmp -s $testroot/stdout.expected $testroot/stdout
1382 ret=$?
1383 if [ $ret -ne 0 ]; then
1384 diff -u $testroot/stdout.expected $testroot/stdout
1385 test_done "$testroot" "$ret"
1386 return 1
1389 (cd $testroot/wt && got status > $testroot/stdout)
1391 echo -n > $testroot/stdout.expected
1392 cmp -s $testroot/stdout.expected $testroot/stdout
1393 ret=$?
1394 if [ $ret -ne 0 ]; then
1395 diff -u $testroot/stdout.expected $testroot/stdout
1396 test_done "$testroot" "$ret"
1397 return 1
1400 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1401 echo "commit $merge_commit (master)" > $testroot/stdout.expected
1402 echo "commit $master_commit" >> $testroot/stdout.expected
1403 echo "commit $commit0" >> $testroot/stdout.expected
1404 cmp -s $testroot/stdout.expected $testroot/stdout
1405 ret=$?
1406 if [ $ret -ne 0 ]; then
1407 diff -u $testroot/stdout.expected $testroot/stdout
1408 test_done "$testroot" "$ret"
1409 return 1
1412 (cd $testroot/wt && got update > $testroot/stdout)
1414 echo 'Already up-to-date' > $testroot/stdout.expected
1415 cmp -s $testroot/stdout.expected $testroot/stdout
1416 ret=$?
1417 if [ $ret -ne 0 ]; then
1418 diff -u $testroot/stdout.expected $testroot/stdout
1419 test_done "$testroot" "$ret"
1420 return 1
1423 # We should have created a merge commit with two parents.
1424 (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
1425 echo "parent 1: $master_commit" > $testroot/stdout.expected
1426 echo "parent 2: $branch_commit0" >> $testroot/stdout.expected
1427 cmp -s $testroot/stdout.expected $testroot/stdout
1428 ret=$?
1429 if [ $ret -ne 0 ]; then
1430 diff -u $testroot/stdout.expected $testroot/stdout
1432 test_done "$testroot" "$ret"
1435 test_merge_umask() {
1436 local testroot=`test_init merge_umask`
1438 (cd $testroot/repo && git checkout -q -b newbranch)
1439 echo "modified alpha on branch" >$testroot/repo/alpha
1440 git_commit "$testroot/repo" -m "committing alpha on newbranch"
1441 echo "modified delta on branch" >$testroot/repo/gamma/delta
1442 git_commit "$testroot/repo" -m "committing delta on newbranch"
1444 # diverge from newbranch
1445 (cd "$testroot/repo" && git checkout -q master)
1446 echo "modified beta on master" >$testroot/repo/beta
1447 git_commit "$testroot/repo" -m "committing zeto no master"
1449 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1451 # using a subshell to avoid clobbering global umask
1452 (umask 077 && cd "$testroot/wt" && got merge newbranch) >/dev/null
1454 for f in alpha gamma/delta; do
1455 ls -l "$testroot/wt/$f" | grep -q ^-rw-------
1456 if [ $? -ne 0 ]; then
1457 echo "$f is not 0600 after merge" >&2
1458 ls -l "$testroot/wt/$f" >&2
1459 test_done "$testroot" 1
1461 done
1463 test_done "$testroot" 0
1466 test_merge_gitconfig_author() {
1467 local testroot=`test_init merge_gitconfig_author`
1469 (cd $testroot/repo && git config user.name 'Flan Luck')
1470 (cd $testroot/repo && git config user.email 'flan_luck@openbsd.org')
1472 (cd $testroot/repo && git checkout -q -b newbranch)
1473 echo "modified alpha on branch" >$testroot/repo/alpha
1474 git_commit "$testroot/repo" -m "committing alpha on newbranch"
1475 echo "modified delta on branch" >$testroot/repo/gamma/delta
1476 git_commit "$testroot/repo" -m "committing delta on newbranch"
1478 # diverge from newbranch
1479 (cd "$testroot/repo" && git checkout -q master)
1480 echo "modified beta on master" >$testroot/repo/beta
1481 git_commit "$testroot/repo" -m "committing zeto no master"
1483 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1485 # unset in a subshell to avoid affecting our environment
1486 (unset GOT_IGNORE_GITCONFIG && cd $testroot/wt && \
1487 got merge newbranch > /dev/null)
1489 (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
1490 ret=$?
1491 if [ $ret -ne 0 ]; then
1492 test_done "$testroot" "$ret"
1493 return 1
1496 echo "from: Flan Luck <flan_luck@openbsd.org>" \
1497 > $testroot/stdout.expected
1498 cmp -s $testroot/stdout.expected $testroot/stdout
1499 ret=$?
1500 if [ $ret -ne 0 ]; then
1501 diff -u $testroot/stdout.expected $testroot/stdout
1503 test_done "$testroot" "$ret"
1506 test_parseargs "$@"
1507 run_test test_merge_basic
1508 run_test test_merge_continue
1509 run_test test_merge_abort
1510 run_test test_merge_in_progress
1511 run_test test_merge_path_prefix
1512 run_test test_merge_missing_file
1513 run_test test_merge_no_op
1514 run_test test_merge_imported_branch
1515 run_test test_merge_interrupt
1516 run_test test_merge_umask
1517 run_test test_merge_gitconfig_author