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`
42 ace90326 2021-09-27 thomas (cd $testroot/repo && ln -sf .got/bar dotgotbar.link)
43 ace90326 2021-09-27 thomas (cd $testroot/repo && git add dotgotbar.link)
44 ace90326 2021-09-27 thomas git_commit $testroot/repo -m "adding a bad symlink on newbranch"
45 ace90326 2021-09-27 thomas local branch_commit5=`git_show_branch_head $testroot/repo newbranch`
47 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
49 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
50 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
51 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
55 b6b86fd1 2022-08-30 thomas # need a divergant commit on the main branch for 'got merge'
56 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
57 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
59 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
60 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
61 10604dce 2021-09-24 thomas test_done "$testroot" "1"
64 10604dce 2021-09-24 thomas echo -n "got: cannot create a merge commit because " \
65 10604dce 2021-09-24 thomas > $testroot/stderr.expected
66 10604dce 2021-09-24 thomas echo -n "refs/heads/newbranch is based on refs/heads/master; " \
67 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
68 10604dce 2021-09-24 thomas echo -n "refs/heads/newbranch can be integrated with " \
69 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
70 10604dce 2021-09-24 thomas echo "'got integrate' instead" >> $testroot/stderr.expected
71 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
73 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
74 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
75 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
79 10604dce 2021-09-24 thomas # create the required dirvergant commit
80 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
81 10604dce 2021-09-24 thomas echo "modified zeta on master" > $testroot/repo/epsilon/zeta
82 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to zeta on master"
83 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
85 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
86 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
87 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
89 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
90 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
91 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
94 10604dce 2021-09-24 thomas echo -n "got: work tree must be updated before it can be used " \
95 10604dce 2021-09-24 thomas > $testroot/stderr.expected
96 10604dce 2021-09-24 thomas echo "to merge a branch" >> $testroot/stderr.expected
97 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
99 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
100 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
101 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
105 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
107 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
108 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
109 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
113 b6b86fd1 2022-08-30 thomas # must not use a mixed-commit work tree with 'got merge'
114 10604dce 2021-09-24 thomas (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
116 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
117 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
118 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
121 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
122 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
124 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
125 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
126 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
129 10604dce 2021-09-24 thomas echo -n "got: work tree contains files from multiple base commits; " \
130 10604dce 2021-09-24 thomas > $testroot/stderr.expected
131 10604dce 2021-09-24 thomas echo "the entire work tree must be updated first" \
132 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
133 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
135 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
136 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
137 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
141 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
143 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
144 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
145 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
149 b6b86fd1 2022-08-30 thomas # must not have staged files with 'got merge'
150 10604dce 2021-09-24 thomas echo "modified file alpha" > $testroot/wt/alpha
151 10604dce 2021-09-24 thomas (cd $testroot/wt && got stage alpha > /dev/null)
153 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
154 10604dce 2021-09-24 thomas echo "got stage failed unexpectedly" >&2
155 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
158 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
159 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
161 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
162 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
163 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
166 10604dce 2021-09-24 thomas echo "got: alpha: file is staged" > $testroot/stderr.expected
167 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
169 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
170 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
171 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
174 10604dce 2021-09-24 thomas (cd $testroot/wt && got unstage alpha > /dev/null)
176 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
177 10604dce 2021-09-24 thomas echo "got unstage failed unexpectedly" >&2
178 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
182 b6b86fd1 2022-08-30 thomas # must not have local changes with 'got merge'
183 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
184 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
186 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
187 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
188 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
191 10604dce 2021-09-24 thomas echo -n "got: work tree contains local changes; " \
192 10604dce 2021-09-24 thomas > $testroot/stderr.expected
193 10604dce 2021-09-24 thomas echo "these changes must be committed or reverted first" \
194 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
195 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
197 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
198 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
199 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
203 10604dce 2021-09-24 thomas (cd $testroot/wt && got revert alpha > /dev/null)
205 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
206 10604dce 2021-09-24 thomas echo "got revert failed unexpectedly" >&2
207 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
211 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch > $testroot/stdout)
213 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
214 10604dce 2021-09-24 thomas echo "got merge failed unexpectedly" >&2
215 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
219 10604dce 2021-09-24 thomas local merge_commit=`git_show_head $testroot/repo`
221 10604dce 2021-09-24 thomas echo "G alpha" >> $testroot/stdout.expected
222 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
223 ace90326 2021-09-27 thomas echo "A dotgotbar.link" >> $testroot/stdout.expected
224 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
225 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
226 10604dce 2021-09-24 thomas echo "A symlink" >> $testroot/stdout.expected
227 10604dce 2021-09-24 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
228 10604dce 2021-09-24 thomas >> $testroot/stdout.expected
229 10604dce 2021-09-24 thomas echo $merge_commit >> $testroot/stdout.expected
231 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
233 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
234 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
235 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
239 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/content.expected
240 10604dce 2021-09-24 thomas cat $testroot/wt/gamma/delta > $testroot/content
241 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
243 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
244 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
245 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
249 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/content.expected
250 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
251 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
253 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
254 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
255 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
259 10604dce 2021-09-24 thomas if [ -e $testroot/wt/beta ]; then
260 10604dce 2021-09-24 thomas echo "removed file beta still exists on disk" >&2
261 10604dce 2021-09-24 thomas test_done "$testroot" "1"
265 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/content.expected
266 10604dce 2021-09-24 thomas cat $testroot/wt/epsilon/new > $testroot/content
267 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
269 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
270 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
271 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
275 ace90326 2021-09-27 thomas if [ ! -h $testroot/wt/dotgotbar.link ]; then
276 ace90326 2021-09-27 thomas echo "dotgotbar.link is not a symlink"
277 ace90326 2021-09-27 thomas test_done "$testroot" "1"
281 10604dce 2021-09-24 thomas readlink $testroot/wt/symlink > $testroot/stdout
282 10604dce 2021-09-24 thomas echo "alpha" > $testroot/stdout.expected
283 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
285 fc414659 2022-04-16 thomas if [ $ret -ne 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 status > $testroot/stdout)
293 10604dce 2021-09-24 thomas echo -n > $testroot/stdout.expected
294 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
296 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
297 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
298 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
302 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
303 10604dce 2021-09-24 thomas echo "commit $merge_commit (master)" > $testroot/stdout.expected
304 10604dce 2021-09-24 thomas echo "commit $master_commit" >> $testroot/stdout.expected
305 10604dce 2021-09-24 thomas echo "commit $commit0" >> $testroot/stdout.expected
306 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
308 fc414659 2022-04-16 thomas if [ $ret -ne 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 (cd $testroot/wt && got update > $testroot/stdout)
316 ace90326 2021-09-27 thomas echo 'U dotgotbar.link' > $testroot/stdout.expected
317 ace90326 2021-09-27 thomas echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
318 ace90326 2021-09-27 thomas git_show_head $testroot/repo >> $testroot/stdout.expected
319 ace90326 2021-09-27 thomas echo >> $testroot/stdout.expected
320 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
322 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
323 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
324 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
328 ace90326 2021-09-27 thomas # update has changed the bad symlink into a regular file
329 ace90326 2021-09-27 thomas if [ -h $testroot/wt/dotgotbar.link ]; then
330 ace90326 2021-09-27 thomas echo "dotgotbar.link is a symlink"
331 ace90326 2021-09-27 thomas test_done "$testroot" "1"
335 10604dce 2021-09-24 thomas # We should have created a merge commit with two parents.
336 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
337 10604dce 2021-09-24 thomas echo "parent 1: $master_commit" > $testroot/stdout.expected
338 ace90326 2021-09-27 thomas echo "parent 2: $branch_commit5" >> $testroot/stdout.expected
339 ace90326 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
341 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
342 ace90326 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
343 ace90326 2021-09-27 thomas test_done "$testroot" "$ret"
347 ace90326 2021-09-27 thomas got tree -r $testroot/repo -c $merge_commit -R > $testroot/stdout
349 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
350 ace90326 2021-09-27 thomas echo "got tree failed unexpectedly" >&2
351 ace90326 2021-09-27 thomas test_done "$testroot" "$ret"
355 ace90326 2021-09-27 thomas # bad symlink dotgotbar.link appears as a symlink in the merge commit:
356 ace90326 2021-09-27 thomas cat > $testroot/stdout.expected <<EOF
358 ace90326 2021-09-27 thomas dotgotbar.link@ -> .got/bar
360 ace90326 2021-09-27 thomas epsilon/new
361 ace90326 2021-09-27 thomas epsilon/zeta
363 ace90326 2021-09-27 thomas gamma/delta
364 ace90326 2021-09-27 thomas symlink@ -> alpha
366 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
368 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
369 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
371 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
374 10604dce 2021-09-24 thomas test_merge_continue() {
375 10604dce 2021-09-24 thomas local testroot=`test_init merge_continue`
376 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
377 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
379 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
380 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
381 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to delta on newbranch"
382 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
384 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
385 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
386 10604dce 2021-09-24 thomas local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
387 10604dce 2021-09-24 thomas (cd $testroot/repo && git rm -q beta)
388 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "removing beta on newbranch"
389 10604dce 2021-09-24 thomas local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
390 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/repo/epsilon/new
391 10604dce 2021-09-24 thomas (cd $testroot/repo && git add epsilon/new)
392 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding new file on newbranch"
393 10604dce 2021-09-24 thomas local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
395 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
397 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
398 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
399 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
403 10604dce 2021-09-24 thomas # create a conflicting commit
404 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
405 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
406 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
407 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
409 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
410 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
412 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
413 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
414 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
418 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
419 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
421 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
422 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
423 10604dce 2021-09-24 thomas test_done "$testroot" "1"
427 10604dce 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
428 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
429 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
430 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
431 10604dce 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
432 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
434 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
435 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
436 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
440 10604dce 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
441 10604dce 2021-09-24 thomas > $testroot/stderr.expected
442 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
444 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
445 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
446 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
450 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
452 10604dce 2021-09-24 thomas echo "C alpha" > $testroot/stdout.expected
453 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
454 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
455 10604dce 2021-09-24 thomas echo "M gamma/delta" >> $testroot/stdout.expected
456 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
458 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
459 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
460 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
464 10604dce 2021-09-24 thomas echo '<<<<<<<' > $testroot/content.expected
465 10604dce 2021-09-24 thomas echo "modified alpha on master" >> $testroot/content.expected
466 10604dce 2021-09-24 thomas echo "||||||| 3-way merge base: commit $commit0" \
467 10604dce 2021-09-24 thomas >> $testroot/content.expected
468 10604dce 2021-09-24 thomas echo "alpha" >> $testroot/content.expected
469 10604dce 2021-09-24 thomas echo "=======" >> $testroot/content.expected
470 10604dce 2021-09-24 thomas echo "modified alpha on branch" >> $testroot/content.expected
471 10604dce 2021-09-24 thomas echo ">>>>>>> merged change: commit $branch_commit3" \
472 10604dce 2021-09-24 thomas >> $testroot/content.expected
473 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
474 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
476 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
477 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
478 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
482 10604dce 2021-09-24 thomas # resolve the conflict
483 10604dce 2021-09-24 thomas echo "modified alpha by both branches" > $testroot/wt/alpha
485 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge -c > $testroot/stdout)
487 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
488 10604dce 2021-09-24 thomas echo "got merge failed unexpectedly" >&2
489 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
493 10604dce 2021-09-24 thomas local merge_commit=`git_show_head $testroot/repo`
495 ae1e948a 2021-09-28 thomas echo "M alpha" > $testroot/stdout.expected
496 ae1e948a 2021-09-28 thomas echo "D beta" >> $testroot/stdout.expected
497 ae1e948a 2021-09-28 thomas echo "A epsilon/new" >> $testroot/stdout.expected
498 ae1e948a 2021-09-28 thomas echo "M gamma/delta" >> $testroot/stdout.expected
499 10604dce 2021-09-24 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
500 ae1e948a 2021-09-28 thomas >> $testroot/stdout.expected
501 10604dce 2021-09-24 thomas echo $merge_commit >> $testroot/stdout.expected
503 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
505 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
506 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
507 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
511 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/content.expected
512 10604dce 2021-09-24 thomas cat $testroot/wt/gamma/delta > $testroot/content
513 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
515 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
516 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
517 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
521 10604dce 2021-09-24 thomas echo "modified alpha by both branches" > $testroot/content.expected
522 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
523 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
525 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
526 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
527 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
531 10604dce 2021-09-24 thomas if [ -e $testroot/wt/beta ]; then
532 10604dce 2021-09-24 thomas echo "removed file beta still exists on disk" >&2
533 10604dce 2021-09-24 thomas test_done "$testroot" "1"
537 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/content.expected
538 10604dce 2021-09-24 thomas cat $testroot/wt/epsilon/new > $testroot/content
539 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
541 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
542 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
543 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
547 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
549 10604dce 2021-09-24 thomas echo -n > $testroot/stdout.expected
550 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
552 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
553 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
554 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
558 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
559 10604dce 2021-09-24 thomas echo "commit $merge_commit (master)" > $testroot/stdout.expected
560 10604dce 2021-09-24 thomas echo "commit $master_commit" >> $testroot/stdout.expected
561 10604dce 2021-09-24 thomas echo "commit $commit0" >> $testroot/stdout.expected
562 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
564 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
565 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
566 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
570 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > $testroot/stdout)
572 10604dce 2021-09-24 thomas echo 'Already up-to-date' > $testroot/stdout.expected
573 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
575 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
576 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
577 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
581 10604dce 2021-09-24 thomas # We should have created a merge commit with two parents.
582 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
583 10604dce 2021-09-24 thomas echo "parent 1: $master_commit" > $testroot/stdout.expected
584 10604dce 2021-09-24 thomas echo "parent 2: $branch_commit3" >> $testroot/stdout.expected
585 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
587 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
588 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
590 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
593 10604dce 2021-09-24 thomas test_merge_abort() {
594 10604dce 2021-09-24 thomas local testroot=`test_init merge_abort`
595 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
596 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
598 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
599 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
600 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to delta on newbranch"
601 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
603 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
604 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
605 10604dce 2021-09-24 thomas local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
606 10604dce 2021-09-24 thomas (cd $testroot/repo && git rm -q beta)
607 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "removing beta on newbranch"
608 10604dce 2021-09-24 thomas local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
609 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/repo/epsilon/new
610 10604dce 2021-09-24 thomas (cd $testroot/repo && git add epsilon/new)
611 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding new file on newbranch"
612 10604dce 2021-09-24 thomas local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
613 10604dce 2021-09-24 thomas (cd $testroot/repo && ln -s alpha symlink && git add symlink)
614 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding symlink on newbranch"
615 10604dce 2021-09-24 thomas local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
617 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
619 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
620 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
621 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
625 d52bac28 2021-10-08 thomas # unrelated unversioned file in work tree
626 d52bac28 2021-10-08 thomas touch $testroot/wt/unversioned-file
628 10604dce 2021-09-24 thomas # create a conflicting commit
629 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
630 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
631 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
632 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
634 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
635 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
637 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
638 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
639 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
643 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
644 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
646 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
647 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
648 10604dce 2021-09-24 thomas test_done "$testroot" "1"
652 10604dce 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
653 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
654 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
655 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
656 10604dce 2021-09-24 thomas echo "A symlink" >> $testroot/stdout.expected
657 10604dce 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
658 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
660 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
661 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
662 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
666 10604dce 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
667 10604dce 2021-09-24 thomas > $testroot/stderr.expected
668 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
670 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
671 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
672 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
676 8641a332 2023-04-14 thomas # unrelated added file added during conflict resolution
677 8641a332 2023-04-14 thomas touch $testroot/wt/added-file
678 8641a332 2023-04-14 thomas (cd $testroot/wt && got add added-file > /dev/null)
680 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
682 8641a332 2023-04-14 thomas echo "A added-file" > $testroot/stdout.expected
683 8641a332 2023-04-14 thomas echo "C alpha" >> $testroot/stdout.expected
684 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
685 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
686 10604dce 2021-09-24 thomas echo "M gamma/delta" >> $testroot/stdout.expected
687 10604dce 2021-09-24 thomas echo "A symlink" >> $testroot/stdout.expected
688 d52bac28 2021-10-08 thomas echo "? unversioned-file" >> $testroot/stdout.expected
689 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
691 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
692 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
693 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
697 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge -a > $testroot/stdout)
699 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
700 10604dce 2021-09-24 thomas echo "got merge failed unexpectedly" >&2
701 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
705 8641a332 2023-04-14 thomas echo "R added-file" > $testroot/stdout.expected
706 8641a332 2023-04-14 thomas echo "R alpha" >> $testroot/stdout.expected
707 10604dce 2021-09-24 thomas echo "R beta" >> $testroot/stdout.expected
708 10604dce 2021-09-24 thomas echo "R epsilon/new" >> $testroot/stdout.expected
709 10604dce 2021-09-24 thomas echo "R gamma/delta" >> $testroot/stdout.expected
710 10604dce 2021-09-24 thomas echo "R symlink" >> $testroot/stdout.expected
711 8641a332 2023-04-14 thomas echo "G added-file" >> $testroot/stdout.expected
712 10604dce 2021-09-24 thomas echo "Merge of refs/heads/newbranch aborted" \
713 10604dce 2021-09-24 thomas >> $testroot/stdout.expected
715 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
717 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
718 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
719 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
723 10604dce 2021-09-24 thomas echo "delta" > $testroot/content.expected
724 10604dce 2021-09-24 thomas cat $testroot/wt/gamma/delta > $testroot/content
725 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
727 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
728 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
729 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
733 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/content.expected
734 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
735 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
737 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
738 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
739 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
743 10604dce 2021-09-24 thomas echo "beta" > $testroot/content.expected
744 10604dce 2021-09-24 thomas cat $testroot/wt/beta > $testroot/content
745 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
747 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
748 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
749 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
753 10604dce 2021-09-24 thomas if [ -e $testroot/wt/epsilon/new ]; then
754 10604dce 2021-09-24 thomas echo "reverted file epsilon/new still exists on disk" >&2
755 10604dce 2021-09-24 thomas test_done "$testroot" "1"
759 10604dce 2021-09-24 thomas if [ -e $testroot/wt/symlink ]; then
760 10604dce 2021-09-24 thomas echo "reverted symlink still exists on disk" >&2
761 10604dce 2021-09-24 thomas test_done "$testroot" "1"
765 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
767 8641a332 2023-04-14 thomas echo "? added-file" > $testroot/stdout.expected
768 8641a332 2023-04-14 thomas echo "? unversioned-file" >> $testroot/stdout.expected
769 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
771 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
772 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
773 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
777 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
778 10604dce 2021-09-24 thomas echo "commit $master_commit (master)" > $testroot/stdout.expected
779 10604dce 2021-09-24 thomas echo "commit $commit0" >> $testroot/stdout.expected
780 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
782 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
783 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
784 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
788 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > $testroot/stdout)
790 10604dce 2021-09-24 thomas echo 'Already up-to-date' > $testroot/stdout.expected
791 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
793 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
794 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
796 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
799 10604dce 2021-09-24 thomas test_merge_in_progress() {
800 10604dce 2021-09-24 thomas local testroot=`test_init merge_in_progress`
801 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
802 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
804 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
805 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
806 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
807 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
809 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
811 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
812 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
813 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
817 10604dce 2021-09-24 thomas # create a conflicting commit
818 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
819 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
820 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
821 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
823 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
824 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
826 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
827 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
828 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
832 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
833 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
835 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
836 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
837 10604dce 2021-09-24 thomas test_done "$testroot" "1"
841 10604dce 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
842 10604dce 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
843 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
845 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
846 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
847 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
851 10604dce 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
852 10604dce 2021-09-24 thomas > $testroot/stderr.expected
853 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
855 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
856 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
857 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
861 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
863 10604dce 2021-09-24 thomas echo "C alpha" > $testroot/stdout.expected
864 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
866 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
867 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
868 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
872 10604dce 2021-09-24 thomas for cmd in update commit histedit "rebase newbranch" \
873 10604dce 2021-09-24 thomas "integrate newbranch" "stage alpha"; do
874 10604dce 2021-09-24 thomas (cd $testroot/wt && got $cmd > $testroot/stdout \
875 10604dce 2021-09-24 thomas 2> $testroot/stderr)
877 10604dce 2021-09-24 thomas echo -n > $testroot/stdout.expected
878 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
880 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
881 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
882 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
886 10604dce 2021-09-24 thomas echo -n "got: a merge operation is in progress in this " \
887 10604dce 2021-09-24 thomas > $testroot/stderr.expected
888 10604dce 2021-09-24 thomas echo "work tree and must be continued or aborted first" \
889 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
890 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
892 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
893 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
894 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
899 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
902 10604dce 2021-09-24 thomas test_merge_path_prefix() {
903 10604dce 2021-09-24 thomas local testroot=`test_init merge_path_prefix`
904 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
905 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
907 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
908 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
909 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
910 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
912 10604dce 2021-09-24 thomas got checkout -p epsilon -b master $testroot/repo $testroot/wt \
913 10604dce 2021-09-24 thomas > /dev/null
915 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
916 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
917 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
921 10604dce 2021-09-24 thomas # create a conflicting commit
922 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
923 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
924 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
925 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
927 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
928 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
930 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
931 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
932 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
936 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
937 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
939 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
940 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
941 10604dce 2021-09-24 thomas test_done "$testroot" "1"
945 10604dce 2021-09-24 thomas echo -n "got: cannot merge branch which contains changes outside " \
946 10604dce 2021-09-24 thomas > $testroot/stderr.expected
947 10604dce 2021-09-24 thomas echo "of this work tree's path prefix" >> $testroot/stderr.expected
948 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
950 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
951 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
953 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
956 10604dce 2021-09-24 thomas test_merge_missing_file() {
957 10604dce 2021-09-24 thomas local testroot=`test_init merge_missing_file`
958 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
959 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
961 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
962 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
963 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
964 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha and delta"
965 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
967 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
969 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
970 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
971 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
975 10604dce 2021-09-24 thomas # create a conflicting commit which renames alpha
976 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
977 10604dce 2021-09-24 thomas (cd $testroot/repo && git mv alpha epsilon/alpha-moved)
978 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "moving alpha on master"
979 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
981 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
982 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
984 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
985 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
986 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
990 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
991 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
993 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
994 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
995 10604dce 2021-09-24 thomas test_done "$testroot" "1"
999 10604dce 2021-09-24 thomas echo "! alpha" > $testroot/stdout.expected
1000 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
1001 0ef68859 2021-09-28 thomas echo -n "Files which had incoming changes but could not be found " \
1002 0ef68859 2021-09-28 thomas >> $testroot/stdout.expected
1003 0ef68859 2021-09-28 thomas echo "in the work tree: 1" >> $testroot/stdout.expected
1004 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1006 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1007 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1008 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1009 10604dce 2021-09-24 thomas return 1
1012 ba162991 2021-09-28 thomas echo -n "got: changes destined for some files " \
1013 10604dce 2021-09-24 thomas > $testroot/stderr.expected
1014 10604dce 2021-09-24 thomas echo -n "were not yet merged and should be merged manually if " \
1015 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
1016 10604dce 2021-09-24 thomas echo "required before the merge operation is continued" \
1017 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
1018 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1020 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1021 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1022 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1023 10604dce 2021-09-24 thomas return 1
1026 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1028 10604dce 2021-09-24 thomas echo "M gamma/delta" > $testroot/stdout.expected
1029 2d7ce510 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1031 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1032 2d7ce510 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1033 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1034 2d7ce510 2021-09-24 thomas return 1
1037 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1040 2d7ce510 2021-09-24 thomas test_merge_no_op() {
1041 2d7ce510 2021-09-24 thomas local testroot=`test_init merge_no_op`
1042 2d7ce510 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
1043 2d7ce510 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1045 2d7ce510 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
1046 2d7ce510 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
1047 2d7ce510 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
1048 2d7ce510 2021-09-24 thomas local branch_commitk=`git_show_branch_head $testroot/repo newbranch`
1050 2d7ce510 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
1052 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1053 2d7ce510 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
1054 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1055 2d7ce510 2021-09-24 thomas return 1
1058 2d7ce510 2021-09-24 thomas # create a conflicting commit
1059 2d7ce510 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
1060 2d7ce510 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
1061 2d7ce510 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
1062 2d7ce510 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
1064 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
1065 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
1067 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1068 2d7ce510 2021-09-24 thomas echo "got update failed unexpectedly" >&2
1069 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1070 2d7ce510 2021-09-24 thomas return 1
1073 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
1074 2d7ce510 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
1076 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
1077 2d7ce510 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
1078 2d7ce510 2021-09-24 thomas test_done "$testroot" "1"
1079 2d7ce510 2021-09-24 thomas return 1
1082 2d7ce510 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
1083 2d7ce510 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1084 2d7ce510 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1086 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1087 2d7ce510 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1088 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1089 2d7ce510 2021-09-24 thomas return 1
1092 2d7ce510 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
1093 2d7ce510 2021-09-24 thomas > $testroot/stderr.expected
1094 2d7ce510 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1096 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1097 2d7ce510 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1098 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1099 2d7ce510 2021-09-24 thomas return 1
1102 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1104 2d7ce510 2021-09-24 thomas echo "C alpha" > $testroot/stdout.expected
1105 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1107 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1108 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1109 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1110 10604dce 2021-09-24 thomas return 1
1113 2d7ce510 2021-09-24 thomas # resolve the conflict by reverting all changes; now it is no-op merge
1114 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got revert alpha > /dev/null)
1116 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1117 2d7ce510 2021-09-24 thomas echo "got revert failed unexpectedly" >&2
1118 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1119 2d7ce510 2021-09-24 thomas return 1
1122 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got merge -c > $testroot/stdout \
1123 2d7ce510 2021-09-24 thomas 2> $testroot/stderr)
1125 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
1126 2d7ce510 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
1127 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1128 2d7ce510 2021-09-24 thomas return 1
1131 2d7ce510 2021-09-24 thomas echo -n "got: merge of refs/heads/newbranch cannot proceed: " \
1132 2d7ce510 2021-09-24 thomas > $testroot/stderr.expected
1133 2d7ce510 2021-09-24 thomas echo "no changes to commit" >> $testroot/stderr.expected
1134 2d7ce510 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1136 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1137 2d7ce510 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1138 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1139 2d7ce510 2021-09-24 thomas return 1
1142 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1144 2d7ce510 2021-09-24 thomas echo -n "" > $testroot/stdout.expected
1145 768705e3 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1147 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1148 768705e3 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1150 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1153 768705e3 2021-09-27 thomas test_merge_imported_branch() {
1154 768705e3 2021-09-27 thomas local testroot=`test_init merge_import`
1155 768705e3 2021-09-27 thomas local commit0=`git_show_head $testroot/repo`
1156 768705e3 2021-09-27 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1158 768705e3 2021-09-27 thomas # import a new sub-tree to the 'files' branch such that
1159 768705e3 2021-09-27 thomas # none of the files added here collide with existing ones
1160 768705e3 2021-09-27 thomas mkdir -p $testroot/tree/there
1161 768705e3 2021-09-27 thomas mkdir -p $testroot/tree/be/lots
1162 768705e3 2021-09-27 thomas mkdir -p $testroot/tree/files
1163 768705e3 2021-09-27 thomas echo "there should" > $testroot/tree/there/should
1164 768705e3 2021-09-27 thomas echo "be lots of" > $testroot/tree/be/lots/of
1165 768705e3 2021-09-27 thomas echo "files here" > $testroot/tree/files/here
1166 768705e3 2021-09-27 thomas got import -r $testroot/repo -b files -m 'import files' \
1167 768705e3 2021-09-27 thomas $testroot/tree > /dev/null
1169 768705e3 2021-09-27 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
1171 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1172 768705e3 2021-09-27 thomas echo "got checkout failed unexpectedly" >&2
1173 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1174 768705e3 2021-09-27 thomas return 1
1177 768705e3 2021-09-27 thomas (cd $testroot/wt && got merge files > $testroot/stdout)
1179 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1180 768705e3 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1181 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1182 768705e3 2021-09-27 thomas return 1
1185 768705e3 2021-09-27 thomas local merge_commit0=`git_show_head $testroot/repo`
1186 768705e3 2021-09-27 thomas cat > $testroot/stdout.expected <<EOF
1187 768705e3 2021-09-27 thomas A be/lots/of
1188 768705e3 2021-09-27 thomas A files/here
1189 768705e3 2021-09-27 thomas A there/should
1190 768705e3 2021-09-27 thomas Merged refs/heads/files into refs/heads/master: $merge_commit0
1192 768705e3 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1194 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1195 768705e3 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1196 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1197 768705e3 2021-09-27 thomas return 1
1200 768705e3 2021-09-27 thomas # try to merge again while no new changes are available
1201 768705e3 2021-09-27 thomas (cd $testroot/wt && got merge files > $testroot/stdout)
1203 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1204 768705e3 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1205 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1206 768705e3 2021-09-27 thomas return 1
1208 768705e3 2021-09-27 thomas echo "Already up-to-date" > $testroot/stdout.expected
1209 2d7ce510 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1211 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1212 2d7ce510 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1213 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1214 768705e3 2021-09-27 thomas return 1
1217 768705e3 2021-09-27 thomas # update the 'files' branch
1218 768705e3 2021-09-27 thomas (cd $testroot/repo && git reset -q --hard master)
1219 768705e3 2021-09-27 thomas (cd $testroot/repo && git checkout -q files)
1220 768705e3 2021-09-27 thomas echo "indeed" > $testroot/repo/indeed
1221 768705e3 2021-09-27 thomas (cd $testroot/repo && git add indeed)
1222 768705e3 2021-09-27 thomas git_commit $testroot/repo -m "adding another file indeed"
1223 768705e3 2021-09-27 thomas echo "be lots and lots of" > $testroot/repo/be/lots/of
1224 768705e3 2021-09-27 thomas git_commit $testroot/repo -m "lots of changes"
1226 768705e3 2021-09-27 thomas (cd $testroot/wt && got update > /dev/null)
1228 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1229 768705e3 2021-09-27 thomas echo "got update failed unexpectedly" >&2
1230 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1231 768705e3 2021-09-27 thomas return 1
1234 768705e3 2021-09-27 thomas # we should now be able to merge more changes from files branch
1235 768705e3 2021-09-27 thomas (cd $testroot/wt && got merge files > $testroot/stdout)
1237 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1238 768705e3 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1239 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1240 768705e3 2021-09-27 thomas return 1
1243 768705e3 2021-09-27 thomas local merge_commit1=`git_show_branch_head $testroot/repo master`
1244 768705e3 2021-09-27 thomas cat > $testroot/stdout.expected <<EOF
1245 768705e3 2021-09-27 thomas G be/lots/of
1246 768705e3 2021-09-27 thomas A indeed
1247 768705e3 2021-09-27 thomas Merged refs/heads/files into refs/heads/master: $merge_commit1
1250 768705e3 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1252 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1253 768705e3 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1255 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1258 ba34626b 2021-09-27 thomas test_merge_interrupt() {
1259 ba34626b 2021-09-27 thomas local testroot=`test_init merge_interrupt`
1260 ba34626b 2021-09-27 thomas local commit0=`git_show_head $testroot/repo`
1261 ba34626b 2021-09-27 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1263 ba34626b 2021-09-27 thomas (cd $testroot/repo && git checkout -q -b newbranch)
1264 ba34626b 2021-09-27 thomas echo "modified alpha on branch" > $testroot/repo/alpha
1265 ba34626b 2021-09-27 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
1266 ba34626b 2021-09-27 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1268 ba34626b 2021-09-27 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
1270 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1271 ba34626b 2021-09-27 thomas echo "got checkout failed unexpectedly" >&2
1272 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1273 ba34626b 2021-09-27 thomas return 1
1276 ba34626b 2021-09-27 thomas # create a non-conflicting commit
1277 ba34626b 2021-09-27 thomas (cd $testroot/repo && git checkout -q master)
1278 ba34626b 2021-09-27 thomas echo "modified beta on master" > $testroot/repo/beta
1279 ba34626b 2021-09-27 thomas git_commit $testroot/repo -m "committing to beta on master"
1280 ba34626b 2021-09-27 thomas local master_commit=`git_show_head $testroot/repo`
1282 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
1283 ba34626b 2021-09-27 thomas (cd $testroot/wt && got update > /dev/null)
1285 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1286 ba34626b 2021-09-27 thomas echo "got update failed unexpectedly" >&2
1287 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1288 ba34626b 2021-09-27 thomas return 1
1291 ba34626b 2021-09-27 thomas (cd $testroot/wt && got merge -n newbranch \
1292 ba34626b 2021-09-27 thomas > $testroot/stdout 2> $testroot/stderr)
1294 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1295 ba34626b 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1296 ba34626b 2021-09-27 thomas test_done "$testroot" "1"
1297 ba34626b 2021-09-27 thomas return 1
1300 ba34626b 2021-09-27 thomas echo "G alpha" > $testroot/stdout.expected
1301 ba34626b 2021-09-27 thomas echo "Merge of refs/heads/newbranch interrupted on request" \
1302 ba34626b 2021-09-27 thomas >> $testroot/stdout.expected
1303 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1305 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1306 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1307 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1308 ba34626b 2021-09-27 thomas return 1
1311 ba34626b 2021-09-27 thomas (cd $testroot/wt && got status > $testroot/stdout)
1313 ba34626b 2021-09-27 thomas echo "M alpha" > $testroot/stdout.expected
1314 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1316 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1317 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1318 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1319 ba34626b 2021-09-27 thomas return 1
1322 ba34626b 2021-09-27 thomas echo "modified alpha on branch" > $testroot/content.expected
1323 ba34626b 2021-09-27 thomas cat $testroot/wt/alpha > $testroot/content
1324 ba34626b 2021-09-27 thomas cmp -s $testroot/content.expected $testroot/content
1326 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1327 ba34626b 2021-09-27 thomas diff -u $testroot/content.expected $testroot/content
1328 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1329 ba34626b 2021-09-27 thomas return 1
1332 ba34626b 2021-09-27 thomas # adjust merge result
1333 ba34626b 2021-09-27 thomas echo "adjusted merge result" > $testroot/wt/alpha
1335 ba34626b 2021-09-27 thomas # continue the merge
1336 ba34626b 2021-09-27 thomas (cd $testroot/wt && got merge -c > $testroot/stdout)
1338 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1339 ba34626b 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1340 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1341 ba34626b 2021-09-27 thomas return 1
1344 ba34626b 2021-09-27 thomas local merge_commit=`git_show_head $testroot/repo`
1346 ae1e948a 2021-09-28 thomas echo "M alpha" > $testroot/stdout.expected
1347 ba34626b 2021-09-27 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1348 ae1e948a 2021-09-28 thomas >> $testroot/stdout.expected
1349 ba34626b 2021-09-27 thomas echo $merge_commit >> $testroot/stdout.expected
1351 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1353 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1354 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1355 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1356 ba34626b 2021-09-27 thomas return 1
1359 ba34626b 2021-09-27 thomas (cd $testroot/wt && got status > $testroot/stdout)
1361 ba34626b 2021-09-27 thomas echo -n > $testroot/stdout.expected
1362 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1364 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1365 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1366 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1367 ba34626b 2021-09-27 thomas return 1
1370 ba34626b 2021-09-27 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1371 ba34626b 2021-09-27 thomas echo "commit $merge_commit (master)" > $testroot/stdout.expected
1372 ba34626b 2021-09-27 thomas echo "commit $master_commit" >> $testroot/stdout.expected
1373 ba34626b 2021-09-27 thomas echo "commit $commit0" >> $testroot/stdout.expected
1374 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1376 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1377 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1378 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1379 ba34626b 2021-09-27 thomas return 1
1382 ba34626b 2021-09-27 thomas (cd $testroot/wt && got update > $testroot/stdout)
1384 ba34626b 2021-09-27 thomas echo 'Already up-to-date' > $testroot/stdout.expected
1385 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1387 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1388 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1389 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1390 ba34626b 2021-09-27 thomas return 1
1393 ba34626b 2021-09-27 thomas # We should have created a merge commit with two parents.
1394 ba34626b 2021-09-27 thomas (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
1395 ba34626b 2021-09-27 thomas echo "parent 1: $master_commit" > $testroot/stdout.expected
1396 ba34626b 2021-09-27 thomas echo "parent 2: $branch_commit0" >> $testroot/stdout.expected
1397 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1399 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1400 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1402 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1405 a2c162eb 2022-10-30 thomas test_merge_umask() {
1406 a2c162eb 2022-10-30 thomas local testroot=`test_init merge_umask`
1408 a2c162eb 2022-10-30 thomas (cd $testroot/repo && git checkout -q -b newbranch)
1409 a2c162eb 2022-10-30 thomas echo "modified alpha on branch" >$testroot/repo/alpha
1410 a2c162eb 2022-10-30 thomas git_commit "$testroot/repo" -m "committing alpha on newbranch"
1411 a2c162eb 2022-10-30 thomas echo "modified delta on branch" >$testroot/repo/gamma/delta
1412 a2c162eb 2022-10-30 thomas git_commit "$testroot/repo" -m "committing delta on newbranch"
1414 a2c162eb 2022-10-30 thomas # diverge from newbranch
1415 a2c162eb 2022-10-30 thomas (cd "$testroot/repo" && git checkout -q master)
1416 a2c162eb 2022-10-30 thomas echo "modified beta on master" >$testroot/repo/beta
1417 a2c162eb 2022-10-30 thomas git_commit "$testroot/repo" -m "committing zeto no master"
1419 a2c162eb 2022-10-30 thomas got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1421 a2c162eb 2022-10-30 thomas # using a subshell to avoid clobbering global umask
1422 a2c162eb 2022-10-30 thomas (umask 077 && cd "$testroot/wt" && got merge newbranch) >/dev/null
1424 a2c162eb 2022-10-30 thomas for f in alpha gamma/delta; do
1425 a2c162eb 2022-10-30 thomas ls -l "$testroot/wt/$f" | grep -q ^-rw-------
1426 a2c162eb 2022-10-30 thomas if [ $? -ne 0 ]; then
1427 a2c162eb 2022-10-30 thomas echo "$f is not 0600 after merge" >&2
1428 a2c162eb 2022-10-30 thomas ls -l "$testroot/wt/$f" >&2
1429 a2c162eb 2022-10-30 thomas test_done "$testroot" 1
1433 a2c162eb 2022-10-30 thomas test_done "$testroot" 0
1436 b16f1832 2023-02-21 thomas test_merge_gitconfig_author() {
1437 b16f1832 2023-02-21 thomas local testroot=`test_init merge_gitconfig_author`
1439 b16f1832 2023-02-21 thomas (cd $testroot/repo && git config user.name 'Flan Luck')
1440 b16f1832 2023-02-21 thomas (cd $testroot/repo && git config user.email 'flan_luck@openbsd.org')
1442 b16f1832 2023-02-21 thomas (cd $testroot/repo && git checkout -q -b newbranch)
1443 b16f1832 2023-02-21 thomas echo "modified alpha on branch" >$testroot/repo/alpha
1444 b16f1832 2023-02-21 thomas git_commit "$testroot/repo" -m "committing alpha on newbranch"
1445 b16f1832 2023-02-21 thomas echo "modified delta on branch" >$testroot/repo/gamma/delta
1446 b16f1832 2023-02-21 thomas git_commit "$testroot/repo" -m "committing delta on newbranch"
1448 b16f1832 2023-02-21 thomas # diverge from newbranch
1449 b16f1832 2023-02-21 thomas (cd "$testroot/repo" && git checkout -q master)
1450 b16f1832 2023-02-21 thomas echo "modified beta on master" >$testroot/repo/beta
1451 b16f1832 2023-02-21 thomas git_commit "$testroot/repo" -m "committing zeto no master"
1453 b16f1832 2023-02-21 thomas got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1455 b16f1832 2023-02-21 thomas # unset in a subshell to avoid affecting our environment
1456 b16f1832 2023-02-21 thomas (unset GOT_IGNORE_GITCONFIG && cd $testroot/wt && \
1457 b16f1832 2023-02-21 thomas got merge newbranch > /dev/null)
1459 b16f1832 2023-02-21 thomas (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
1461 b16f1832 2023-02-21 thomas if [ $ret -ne 0 ]; then
1462 b16f1832 2023-02-21 thomas test_done "$testroot" "$ret"
1463 b16f1832 2023-02-21 thomas return 1
1466 b16f1832 2023-02-21 thomas echo "from: Flan Luck <flan_luck@openbsd.org>" \
1467 b16f1832 2023-02-21 thomas > $testroot/stdout.expected
1468 b16f1832 2023-02-21 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1470 b16f1832 2023-02-21 thomas if [ $ret -ne 0 ]; then
1471 b16f1832 2023-02-21 thomas diff -u $testroot/stdout.expected $testroot/stdout
1473 b16f1832 2023-02-21 thomas test_done "$testroot" "$ret"
1476 10604dce 2021-09-24 thomas test_parseargs "$@"
1477 10604dce 2021-09-24 thomas run_test test_merge_basic
1478 10604dce 2021-09-24 thomas run_test test_merge_continue
1479 10604dce 2021-09-24 thomas run_test test_merge_abort
1480 10604dce 2021-09-24 thomas run_test test_merge_in_progress
1481 10604dce 2021-09-24 thomas run_test test_merge_path_prefix
1482 10604dce 2021-09-24 thomas run_test test_merge_missing_file
1483 2d7ce510 2021-09-24 thomas run_test test_merge_no_op
1484 768705e3 2021-09-27 thomas run_test test_merge_imported_branch
1485 ba34626b 2021-09-27 thomas run_test test_merge_interrupt
1486 a2c162eb 2022-10-30 thomas run_test test_merge_umask
1487 b16f1832 2023-02-21 thomas run_test test_merge_gitconfig_author