3 10604dce 2021-09-24 thomas # Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
5 10604dce 2021-09-24 thomas # Permission to use, copy, modify, and distribute this software for any
6 10604dce 2021-09-24 thomas # purpose with or without fee is hereby granted, provided that the above
7 10604dce 2021-09-24 thomas # copyright notice and this permission notice appear in all copies.
9 10604dce 2021-09-24 thomas # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 10604dce 2021-09-24 thomas # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 10604dce 2021-09-24 thomas # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 10604dce 2021-09-24 thomas # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 10604dce 2021-09-24 thomas # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 10604dce 2021-09-24 thomas # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 10604dce 2021-09-24 thomas # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 10604dce 2021-09-24 thomas . ./common.sh
19 10604dce 2021-09-24 thomas test_merge_basic() {
20 10604dce 2021-09-24 thomas local testroot=`test_init merge_basic`
21 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
22 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
24 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
25 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
26 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to delta on newbranch"
27 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
29 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
30 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
31 10604dce 2021-09-24 thomas local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
32 10604dce 2021-09-24 thomas (cd $testroot/repo && git rm -q beta)
33 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "removing beta on newbranch"
34 10604dce 2021-09-24 thomas local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
35 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/repo/epsilon/new
36 10604dce 2021-09-24 thomas (cd $testroot/repo && git add epsilon/new)
37 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding new file on newbranch"
38 10604dce 2021-09-24 thomas local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
39 10604dce 2021-09-24 thomas (cd $testroot/repo && ln -s alpha symlink && git add symlink)
40 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding symlink on newbranch"
41 10604dce 2021-09-24 thomas local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
43 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
45 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
46 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
47 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
51 10604dce 2021-09-24 thomas # need a divergant commit on the main branch for 'got merge'
52 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
53 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
55 10604dce 2021-09-24 thomas if [ "$ret" == "0" ]; then
56 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
57 10604dce 2021-09-24 thomas test_done "$testroot" "1"
60 10604dce 2021-09-24 thomas echo -n "got: cannot create a merge commit because " \
61 10604dce 2021-09-24 thomas > $testroot/stderr.expected
62 10604dce 2021-09-24 thomas echo -n "refs/heads/newbranch is based on refs/heads/master; " \
63 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
64 10604dce 2021-09-24 thomas echo -n "refs/heads/newbranch can be integrated with " \
65 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
66 10604dce 2021-09-24 thomas echo "'got integrate' instead" >> $testroot/stderr.expected
67 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
69 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
70 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
71 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
75 10604dce 2021-09-24 thomas # create the required dirvergant commit
76 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
77 10604dce 2021-09-24 thomas echo "modified zeta on master" > $testroot/repo/epsilon/zeta
78 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to zeta on master"
79 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
81 10604dce 2021-09-24 thomas # need an up-to-date work tree for 'got merge'
82 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
83 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
85 10604dce 2021-09-24 thomas if [ "$ret" == "0" ]; then
86 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
87 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
90 10604dce 2021-09-24 thomas echo -n "got: work tree must be updated before it can be used " \
91 10604dce 2021-09-24 thomas > $testroot/stderr.expected
92 10604dce 2021-09-24 thomas echo "to merge a branch" >> $testroot/stderr.expected
93 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
95 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
96 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
97 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
101 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
103 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
104 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
105 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
109 10604dce 2021-09-24 thomas # must not use a mixed-commit work tree with 'got merge'
110 10604dce 2021-09-24 thomas (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
112 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
113 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
114 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
117 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
118 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
120 10604dce 2021-09-24 thomas if [ "$ret" == "0" ]; then
121 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
122 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
125 10604dce 2021-09-24 thomas echo -n "got: work tree contains files from multiple base commits; " \
126 10604dce 2021-09-24 thomas > $testroot/stderr.expected
127 10604dce 2021-09-24 thomas echo "the entire work tree must be updated first" \
128 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
129 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
131 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
132 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
133 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
137 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
139 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
140 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
141 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
145 10604dce 2021-09-24 thomas # must not have staged files with 'got merge'
146 10604dce 2021-09-24 thomas echo "modified file alpha" > $testroot/wt/alpha
147 10604dce 2021-09-24 thomas (cd $testroot/wt && got stage alpha > /dev/null)
149 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
150 10604dce 2021-09-24 thomas echo "got stage failed unexpectedly" >&2
151 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
154 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
155 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
157 10604dce 2021-09-24 thomas if [ "$ret" == "0" ]; then
158 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
159 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
162 10604dce 2021-09-24 thomas echo "got: alpha: file is staged" > $testroot/stderr.expected
163 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
165 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
166 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
167 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
170 10604dce 2021-09-24 thomas (cd $testroot/wt && got unstage alpha > /dev/null)
172 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
173 10604dce 2021-09-24 thomas echo "got unstage failed unexpectedly" >&2
174 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
178 10604dce 2021-09-24 thomas # must not have local changes with 'got merge'
179 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
180 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
182 10604dce 2021-09-24 thomas if [ "$ret" == "0" ]; then
183 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
184 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
187 10604dce 2021-09-24 thomas echo -n "got: work tree contains local changes; " \
188 10604dce 2021-09-24 thomas > $testroot/stderr.expected
189 10604dce 2021-09-24 thomas echo "these changes must be committed or reverted first" \
190 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
191 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
193 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
194 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
195 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
199 10604dce 2021-09-24 thomas (cd $testroot/wt && got revert alpha > /dev/null)
201 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
202 10604dce 2021-09-24 thomas echo "got revert failed unexpectedly" >&2
203 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
207 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch > $testroot/stdout)
209 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
210 10604dce 2021-09-24 thomas echo "got merge failed unexpectedly" >&2
211 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
215 10604dce 2021-09-24 thomas local merge_commit=`git_show_head $testroot/repo`
217 10604dce 2021-09-24 thomas echo "G alpha" >> $testroot/stdout.expected
218 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
219 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
220 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
221 10604dce 2021-09-24 thomas echo "A symlink" >> $testroot/stdout.expected
222 10604dce 2021-09-24 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
223 10604dce 2021-09-24 thomas >> $testroot/stdout.expected
224 10604dce 2021-09-24 thomas echo $merge_commit >> $testroot/stdout.expected
226 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
228 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
229 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
230 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
234 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/content.expected
235 10604dce 2021-09-24 thomas cat $testroot/wt/gamma/delta > $testroot/content
236 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
238 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
239 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
240 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
244 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/content.expected
245 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
246 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
248 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
249 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
250 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
254 10604dce 2021-09-24 thomas if [ -e $testroot/wt/beta ]; then
255 10604dce 2021-09-24 thomas echo "removed file beta still exists on disk" >&2
256 10604dce 2021-09-24 thomas test_done "$testroot" "1"
260 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/content.expected
261 10604dce 2021-09-24 thomas cat $testroot/wt/epsilon/new > $testroot/content
262 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
264 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
265 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
266 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
270 10604dce 2021-09-24 thomas readlink $testroot/wt/symlink > $testroot/stdout
271 10604dce 2021-09-24 thomas echo "alpha" > $testroot/stdout.expected
272 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
274 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
275 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
276 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
280 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
282 10604dce 2021-09-24 thomas echo -n > $testroot/stdout.expected
283 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
285 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
286 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
287 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
291 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
292 10604dce 2021-09-24 thomas echo "commit $merge_commit (master)" > $testroot/stdout.expected
293 10604dce 2021-09-24 thomas echo "commit $master_commit" >> $testroot/stdout.expected
294 10604dce 2021-09-24 thomas echo "commit $commit0" >> $testroot/stdout.expected
295 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
297 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
298 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
299 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
303 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > $testroot/stdout)
305 10604dce 2021-09-24 thomas echo 'Already up-to-date' > $testroot/stdout.expected
306 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
308 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
309 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
310 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
314 10604dce 2021-09-24 thomas # We should have created a merge commit with two parents.
315 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
316 10604dce 2021-09-24 thomas echo "parent 1: $master_commit" > $testroot/stdout.expected
317 10604dce 2021-09-24 thomas echo "parent 2: $branch_commit4" >> $testroot/stdout.expected
318 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
320 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
321 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
323 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
326 10604dce 2021-09-24 thomas test_merge_continue() {
327 10604dce 2021-09-24 thomas local testroot=`test_init merge_continue`
328 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
329 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
331 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
332 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
333 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to delta on newbranch"
334 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
336 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
337 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
338 10604dce 2021-09-24 thomas local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
339 10604dce 2021-09-24 thomas (cd $testroot/repo && git rm -q beta)
340 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "removing beta on newbranch"
341 10604dce 2021-09-24 thomas local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
342 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/repo/epsilon/new
343 10604dce 2021-09-24 thomas (cd $testroot/repo && git add epsilon/new)
344 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding new file on newbranch"
345 10604dce 2021-09-24 thomas local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
347 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
349 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
350 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
351 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
355 10604dce 2021-09-24 thomas # create a conflicting commit
356 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
357 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
358 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
359 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
361 10604dce 2021-09-24 thomas # need an up-to-date work tree for 'got merge'
362 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
364 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
365 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
366 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
370 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
371 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
373 10604dce 2021-09-24 thomas if [ "$ret" == "0" ]; then
374 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
375 10604dce 2021-09-24 thomas test_done "$testroot" "1"
379 10604dce 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
380 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
381 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
382 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
383 10604dce 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
384 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
386 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
387 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
388 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
392 10604dce 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
393 10604dce 2021-09-24 thomas > $testroot/stderr.expected
394 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
396 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
397 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
398 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
402 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
404 10604dce 2021-09-24 thomas echo "C alpha" > $testroot/stdout.expected
405 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
406 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
407 10604dce 2021-09-24 thomas echo "M gamma/delta" >> $testroot/stdout.expected
408 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
410 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
411 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
412 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
416 10604dce 2021-09-24 thomas echo '<<<<<<<' > $testroot/content.expected
417 10604dce 2021-09-24 thomas echo "modified alpha on master" >> $testroot/content.expected
418 10604dce 2021-09-24 thomas echo "||||||| 3-way merge base: commit $commit0" \
419 10604dce 2021-09-24 thomas >> $testroot/content.expected
420 10604dce 2021-09-24 thomas echo "alpha" >> $testroot/content.expected
421 10604dce 2021-09-24 thomas echo "=======" >> $testroot/content.expected
422 10604dce 2021-09-24 thomas echo "modified alpha on branch" >> $testroot/content.expected
423 10604dce 2021-09-24 thomas echo ">>>>>>> merged change: commit $branch_commit3" \
424 10604dce 2021-09-24 thomas >> $testroot/content.expected
425 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
426 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
428 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
429 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
430 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
434 10604dce 2021-09-24 thomas # resolve the conflict
435 10604dce 2021-09-24 thomas echo "modified alpha by both branches" > $testroot/wt/alpha
437 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge -c > $testroot/stdout)
439 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
440 10604dce 2021-09-24 thomas echo "got merge failed unexpectedly" >&2
441 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
445 10604dce 2021-09-24 thomas local merge_commit=`git_show_head $testroot/repo`
447 10604dce 2021-09-24 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
448 10604dce 2021-09-24 thomas > $testroot/stdout.expected
449 10604dce 2021-09-24 thomas echo $merge_commit >> $testroot/stdout.expected
451 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
453 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
454 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
455 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
459 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/content.expected
460 10604dce 2021-09-24 thomas cat $testroot/wt/gamma/delta > $testroot/content
461 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
463 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
464 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
465 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
469 10604dce 2021-09-24 thomas echo "modified alpha by both branches" > $testroot/content.expected
470 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
471 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
473 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
474 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
475 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
479 10604dce 2021-09-24 thomas if [ -e $testroot/wt/beta ]; then
480 10604dce 2021-09-24 thomas echo "removed file beta still exists on disk" >&2
481 10604dce 2021-09-24 thomas test_done "$testroot" "1"
485 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/content.expected
486 10604dce 2021-09-24 thomas cat $testroot/wt/epsilon/new > $testroot/content
487 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
489 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
490 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
491 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
495 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
497 10604dce 2021-09-24 thomas echo -n > $testroot/stdout.expected
498 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
500 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
501 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
502 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
506 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
507 10604dce 2021-09-24 thomas echo "commit $merge_commit (master)" > $testroot/stdout.expected
508 10604dce 2021-09-24 thomas echo "commit $master_commit" >> $testroot/stdout.expected
509 10604dce 2021-09-24 thomas echo "commit $commit0" >> $testroot/stdout.expected
510 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
512 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
513 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
514 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
518 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > $testroot/stdout)
520 10604dce 2021-09-24 thomas echo 'Already up-to-date' > $testroot/stdout.expected
521 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
523 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
524 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
525 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
529 10604dce 2021-09-24 thomas # We should have created a merge commit with two parents.
530 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
531 10604dce 2021-09-24 thomas echo "parent 1: $master_commit" > $testroot/stdout.expected
532 10604dce 2021-09-24 thomas echo "parent 2: $branch_commit3" >> $testroot/stdout.expected
533 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
535 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
536 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
538 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
541 10604dce 2021-09-24 thomas test_merge_abort() {
542 10604dce 2021-09-24 thomas local testroot=`test_init merge_abort`
543 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
544 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
546 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
547 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
548 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to delta on newbranch"
549 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
551 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
552 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
553 10604dce 2021-09-24 thomas local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
554 10604dce 2021-09-24 thomas (cd $testroot/repo && git rm -q beta)
555 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "removing beta on newbranch"
556 10604dce 2021-09-24 thomas local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
557 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/repo/epsilon/new
558 10604dce 2021-09-24 thomas (cd $testroot/repo && git add epsilon/new)
559 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding new file on newbranch"
560 10604dce 2021-09-24 thomas local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
561 10604dce 2021-09-24 thomas (cd $testroot/repo && ln -s alpha symlink && git add symlink)
562 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding symlink on newbranch"
563 10604dce 2021-09-24 thomas local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
565 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
567 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
568 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
569 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
573 10604dce 2021-09-24 thomas # create a conflicting commit
574 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
575 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
576 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
577 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
579 10604dce 2021-09-24 thomas # need an up-to-date work tree for 'got merge'
580 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
582 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
583 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
584 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
588 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
589 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
591 10604dce 2021-09-24 thomas if [ "$ret" == "0" ]; then
592 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
593 10604dce 2021-09-24 thomas test_done "$testroot" "1"
597 10604dce 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
598 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
599 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
600 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
601 10604dce 2021-09-24 thomas echo "A symlink" >> $testroot/stdout.expected
602 10604dce 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
603 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
605 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
606 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
607 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
611 10604dce 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
612 10604dce 2021-09-24 thomas > $testroot/stderr.expected
613 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
615 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
616 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
617 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
621 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
623 10604dce 2021-09-24 thomas echo "C alpha" > $testroot/stdout.expected
624 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
625 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
626 10604dce 2021-09-24 thomas echo "M gamma/delta" >> $testroot/stdout.expected
627 10604dce 2021-09-24 thomas echo "A symlink" >> $testroot/stdout.expected
628 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
630 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
631 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
632 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
636 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge -a > $testroot/stdout)
638 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
639 10604dce 2021-09-24 thomas echo "got merge failed unexpectedly" >&2
640 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
644 10604dce 2021-09-24 thomas echo "R alpha" > $testroot/stdout.expected
645 10604dce 2021-09-24 thomas echo "R beta" >> $testroot/stdout.expected
646 10604dce 2021-09-24 thomas echo "R epsilon/new" >> $testroot/stdout.expected
647 10604dce 2021-09-24 thomas echo "R gamma/delta" >> $testroot/stdout.expected
648 10604dce 2021-09-24 thomas echo "R symlink" >> $testroot/stdout.expected
649 10604dce 2021-09-24 thomas echo "Merge of refs/heads/newbranch aborted" \
650 10604dce 2021-09-24 thomas >> $testroot/stdout.expected
652 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
654 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
655 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
656 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
660 10604dce 2021-09-24 thomas echo "delta" > $testroot/content.expected
661 10604dce 2021-09-24 thomas cat $testroot/wt/gamma/delta > $testroot/content
662 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
664 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
665 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
666 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
670 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/content.expected
671 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
672 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
674 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
675 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
676 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
680 10604dce 2021-09-24 thomas echo "beta" > $testroot/content.expected
681 10604dce 2021-09-24 thomas cat $testroot/wt/beta > $testroot/content
682 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
684 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
685 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
686 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
690 10604dce 2021-09-24 thomas if [ -e $testroot/wt/epsilon/new ]; then
691 10604dce 2021-09-24 thomas echo "reverted file epsilon/new still exists on disk" >&2
692 10604dce 2021-09-24 thomas test_done "$testroot" "1"
696 10604dce 2021-09-24 thomas if [ -e $testroot/wt/symlink ]; then
697 10604dce 2021-09-24 thomas echo "reverted symlink still exists on disk" >&2
698 10604dce 2021-09-24 thomas test_done "$testroot" "1"
702 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
704 10604dce 2021-09-24 thomas echo -n "" > $testroot/stdout.expected
705 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
707 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
708 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
709 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
713 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
714 10604dce 2021-09-24 thomas echo "commit $master_commit (master)" > $testroot/stdout.expected
715 10604dce 2021-09-24 thomas echo "commit $commit0" >> $testroot/stdout.expected
716 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
718 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
719 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
720 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
724 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > $testroot/stdout)
726 10604dce 2021-09-24 thomas echo 'Already up-to-date' > $testroot/stdout.expected
727 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
729 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
730 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
732 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
735 10604dce 2021-09-24 thomas test_merge_in_progress() {
736 10604dce 2021-09-24 thomas local testroot=`test_init merge_in_progress`
737 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
738 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
740 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
741 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
742 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
743 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
745 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
747 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
748 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
749 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
753 10604dce 2021-09-24 thomas # create a conflicting commit
754 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
755 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
756 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
757 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
759 10604dce 2021-09-24 thomas # need an up-to-date work tree for 'got merge'
760 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
762 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
763 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
764 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
768 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
769 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
771 10604dce 2021-09-24 thomas if [ "$ret" == "0" ]; then
772 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
773 10604dce 2021-09-24 thomas test_done "$testroot" "1"
777 10604dce 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
778 10604dce 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
779 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
781 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
782 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
783 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
787 10604dce 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
788 10604dce 2021-09-24 thomas > $testroot/stderr.expected
789 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
791 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
792 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
793 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
797 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
799 10604dce 2021-09-24 thomas echo "C alpha" > $testroot/stdout.expected
800 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
802 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
803 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
804 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
808 10604dce 2021-09-24 thomas for cmd in update commit histedit "rebase newbranch" \
809 10604dce 2021-09-24 thomas "integrate newbranch" "stage alpha"; do
810 10604dce 2021-09-24 thomas (cd $testroot/wt && got $cmd > $testroot/stdout \
811 10604dce 2021-09-24 thomas 2> $testroot/stderr)
813 10604dce 2021-09-24 thomas echo -n > $testroot/stdout.expected
814 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
816 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
817 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
818 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
822 10604dce 2021-09-24 thomas echo -n "got: a merge operation is in progress in this " \
823 10604dce 2021-09-24 thomas > $testroot/stderr.expected
824 10604dce 2021-09-24 thomas echo "work tree and must be continued or aborted first" \
825 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
826 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
828 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
829 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
830 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
835 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
838 10604dce 2021-09-24 thomas test_merge_path_prefix() {
839 10604dce 2021-09-24 thomas local testroot=`test_init merge_path_prefix`
840 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
841 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
843 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
844 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
845 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
846 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
848 10604dce 2021-09-24 thomas got checkout -p epsilon -b master $testroot/repo $testroot/wt \
849 10604dce 2021-09-24 thomas > /dev/null
851 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
852 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
853 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
857 10604dce 2021-09-24 thomas # create a conflicting commit
858 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
859 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
860 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
861 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
863 10604dce 2021-09-24 thomas # need an up-to-date work tree for 'got merge'
864 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
866 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
867 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
868 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
872 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
873 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
875 10604dce 2021-09-24 thomas if [ "$ret" == "0" ]; then
876 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
877 10604dce 2021-09-24 thomas test_done "$testroot" "1"
881 10604dce 2021-09-24 thomas echo -n "got: cannot merge branch which contains changes outside " \
882 10604dce 2021-09-24 thomas > $testroot/stderr.expected
883 10604dce 2021-09-24 thomas echo "of this work tree's path prefix" >> $testroot/stderr.expected
884 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
886 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
887 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
889 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
892 10604dce 2021-09-24 thomas test_merge_missing_file() {
893 10604dce 2021-09-24 thomas local testroot=`test_init merge_missing_file`
894 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
895 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
897 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
898 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
899 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
900 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha and delta"
901 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
903 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
905 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
906 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
907 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
911 10604dce 2021-09-24 thomas # create a conflicting commit which renames alpha
912 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
913 10604dce 2021-09-24 thomas (cd $testroot/repo && git mv alpha epsilon/alpha-moved)
914 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "moving alpha on master"
915 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
917 10604dce 2021-09-24 thomas # need an up-to-date work tree for 'got merge'
918 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
920 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
921 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
922 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
926 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
927 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
929 10604dce 2021-09-24 thomas if [ "$ret" == "0" ]; then
930 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
931 10604dce 2021-09-24 thomas test_done "$testroot" "1"
935 10604dce 2021-09-24 thomas echo "! alpha" > $testroot/stdout.expected
936 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
937 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
939 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
940 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
941 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
945 88d249c2 2021-09-24 thomas echo -n "got: changes destined for missing files " \
946 10604dce 2021-09-24 thomas > $testroot/stderr.expected
947 10604dce 2021-09-24 thomas echo -n "were not yet merged and should be merged manually if " \
948 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
949 10604dce 2021-09-24 thomas echo "required before the merge operation is continued" \
950 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
951 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
953 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
954 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
955 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
959 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
961 10604dce 2021-09-24 thomas echo "M gamma/delta" > $testroot/stdout.expected
962 2d7ce510 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
964 2d7ce510 2021-09-24 thomas if [ "$ret" != "0" ]; then
965 2d7ce510 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
966 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
970 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
973 2d7ce510 2021-09-24 thomas test_merge_no_op() {
974 2d7ce510 2021-09-24 thomas local testroot=`test_init merge_no_op`
975 2d7ce510 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
976 2d7ce510 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
978 2d7ce510 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
979 2d7ce510 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
980 2d7ce510 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
981 2d7ce510 2021-09-24 thomas local branch_commitk=`git_show_branch_head $testroot/repo newbranch`
983 2d7ce510 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
985 2d7ce510 2021-09-24 thomas if [ "$ret" != "0" ]; then
986 2d7ce510 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
987 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
991 2d7ce510 2021-09-24 thomas # create a conflicting commit
992 2d7ce510 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
993 2d7ce510 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
994 2d7ce510 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
995 2d7ce510 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
997 2d7ce510 2021-09-24 thomas # need an up-to-date work tree for 'got merge'
998 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
1000 2d7ce510 2021-09-24 thomas if [ "$ret" != "0" ]; then
1001 2d7ce510 2021-09-24 thomas echo "got update failed unexpectedly" >&2
1002 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1003 2d7ce510 2021-09-24 thomas return 1
1006 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
1007 2d7ce510 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
1008 2d7ce510 2021-09-24 thomas ret="$?"
1009 2d7ce510 2021-09-24 thomas if [ "$ret" == "0" ]; then
1010 2d7ce510 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
1011 2d7ce510 2021-09-24 thomas test_done "$testroot" "1"
1012 2d7ce510 2021-09-24 thomas return 1
1015 2d7ce510 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
1016 2d7ce510 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1017 2d7ce510 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1018 2d7ce510 2021-09-24 thomas ret="$?"
1019 2d7ce510 2021-09-24 thomas if [ "$ret" != "0" ]; then
1020 2d7ce510 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1021 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1022 2d7ce510 2021-09-24 thomas return 1
1025 2d7ce510 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
1026 2d7ce510 2021-09-24 thomas > $testroot/stderr.expected
1027 2d7ce510 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1028 2d7ce510 2021-09-24 thomas ret="$?"
1029 2d7ce510 2021-09-24 thomas if [ "$ret" != "0" ]; then
1030 2d7ce510 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1031 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1032 2d7ce510 2021-09-24 thomas return 1
1035 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1037 2d7ce510 2021-09-24 thomas echo "C alpha" > $testroot/stdout.expected
1038 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1039 10604dce 2021-09-24 thomas ret="$?"
1040 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
1041 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1042 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1043 10604dce 2021-09-24 thomas return 1
1046 2d7ce510 2021-09-24 thomas # resolve the conflict by reverting all changes; now it is no-op merge
1047 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got revert alpha > /dev/null)
1048 2d7ce510 2021-09-24 thomas ret="$?"
1049 2d7ce510 2021-09-24 thomas if [ "$ret" != "0" ]; then
1050 2d7ce510 2021-09-24 thomas echo "got revert failed unexpectedly" >&2
1051 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1052 2d7ce510 2021-09-24 thomas return 1
1055 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got merge -c > $testroot/stdout \
1056 2d7ce510 2021-09-24 thomas 2> $testroot/stderr)
1057 2d7ce510 2021-09-24 thomas ret="$?"
1058 2d7ce510 2021-09-24 thomas if [ "$ret" == "0" ]; then
1059 2d7ce510 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
1060 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1061 2d7ce510 2021-09-24 thomas return 1
1064 2d7ce510 2021-09-24 thomas echo -n "got: merge of refs/heads/newbranch cannot proceed: " \
1065 2d7ce510 2021-09-24 thomas > $testroot/stderr.expected
1066 2d7ce510 2021-09-24 thomas echo "no changes to commit" >> $testroot/stderr.expected
1067 2d7ce510 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1068 2d7ce510 2021-09-24 thomas ret="$?"
1069 2d7ce510 2021-09-24 thomas if [ "$ret" != "0" ]; then
1070 2d7ce510 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1071 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1072 2d7ce510 2021-09-24 thomas return 1
1075 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1077 2d7ce510 2021-09-24 thomas echo -n "" > $testroot/stdout.expected
1078 2d7ce510 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1079 2d7ce510 2021-09-24 thomas ret="$?"
1080 2d7ce510 2021-09-24 thomas if [ "$ret" != "0" ]; then
1081 2d7ce510 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1083 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1086 10604dce 2021-09-24 thomas test_parseargs "$@"
1087 10604dce 2021-09-24 thomas run_test test_merge_basic
1088 10604dce 2021-09-24 thomas run_test test_merge_continue
1089 10604dce 2021-09-24 thomas run_test test_merge_abort
1090 10604dce 2021-09-24 thomas run_test test_merge_in_progress
1091 10604dce 2021-09-24 thomas run_test test_merge_path_prefix
1092 10604dce 2021-09-24 thomas run_test test_merge_missing_file
1093 2d7ce510 2021-09-24 thomas run_test test_merge_no_op