3 f259c4c1 2021-09-24 stsp # Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
5 f259c4c1 2021-09-24 stsp # Permission to use, copy, modify, and distribute this software for any
6 f259c4c1 2021-09-24 stsp # purpose with or without fee is hereby granted, provided that the above
7 f259c4c1 2021-09-24 stsp # copyright notice and this permission notice appear in all copies.
9 f259c4c1 2021-09-24 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 f259c4c1 2021-09-24 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 f259c4c1 2021-09-24 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 f259c4c1 2021-09-24 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 f259c4c1 2021-09-24 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 f259c4c1 2021-09-24 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 f259c4c1 2021-09-24 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 f259c4c1 2021-09-24 stsp . ./common.sh
19 f259c4c1 2021-09-24 stsp test_merge_basic() {
20 f259c4c1 2021-09-24 stsp local testroot=`test_init merge_basic`
21 f259c4c1 2021-09-24 stsp local commit0=`git_show_head $testroot/repo`
22 f259c4c1 2021-09-24 stsp local commit0_author_time=`git_show_author_time $testroot/repo`
24 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git checkout -q -b newbranch)
25 f259c4c1 2021-09-24 stsp echo "modified delta on branch" > $testroot/repo/gamma/delta
26 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "committing to delta on newbranch"
27 f259c4c1 2021-09-24 stsp local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
29 f259c4c1 2021-09-24 stsp echo "modified alpha on branch" > $testroot/repo/alpha
30 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "committing to alpha on newbranch"
31 f259c4c1 2021-09-24 stsp local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
32 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git rm -q beta)
33 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "removing beta on newbranch"
34 f259c4c1 2021-09-24 stsp local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
35 f259c4c1 2021-09-24 stsp echo "new file on branch" > $testroot/repo/epsilon/new
36 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git add epsilon/new)
37 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "adding new file on newbranch"
38 f259c4c1 2021-09-24 stsp local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
39 f259c4c1 2021-09-24 stsp (cd $testroot/repo && ln -s alpha symlink && git add symlink)
40 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "adding symlink on newbranch"
41 f259c4c1 2021-09-24 stsp local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
42 5267b9e4 2021-09-26 stsp (cd $testroot/repo && ln -sf .got/bar dotgotbar.link)
43 5267b9e4 2021-09-26 stsp (cd $testroot/repo && git add dotgotbar.link)
44 5267b9e4 2021-09-26 stsp git_commit $testroot/repo -m "adding a bad symlink on newbranch"
45 5267b9e4 2021-09-26 stsp local branch_commit5=`git_show_branch_head $testroot/repo newbranch`
47 f259c4c1 2021-09-24 stsp got checkout -b master $testroot/repo $testroot/wt > /dev/null
49 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
50 f259c4c1 2021-09-24 stsp echo "got checkout failed unexpectedly" >&2
51 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
55 5e91dae4 2022-08-30 stsp # need a divergant commit on the main branch for 'got merge'
56 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got merge newbranch \
57 f259c4c1 2021-09-24 stsp > $testroot/stdout 2> $testroot/stderr)
59 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
60 f259c4c1 2021-09-24 stsp echo "got merge succeeded unexpectedly" >&2
61 f259c4c1 2021-09-24 stsp test_done "$testroot" "1"
64 f259c4c1 2021-09-24 stsp echo -n "got: cannot create a merge commit because " \
65 f259c4c1 2021-09-24 stsp > $testroot/stderr.expected
66 f259c4c1 2021-09-24 stsp echo -n "refs/heads/newbranch is based on refs/heads/master; " \
67 f259c4c1 2021-09-24 stsp >> $testroot/stderr.expected
68 f259c4c1 2021-09-24 stsp echo -n "refs/heads/newbranch can be integrated with " \
69 f259c4c1 2021-09-24 stsp >> $testroot/stderr.expected
70 f259c4c1 2021-09-24 stsp echo "'got integrate' instead" >> $testroot/stderr.expected
71 f259c4c1 2021-09-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
73 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
74 f259c4c1 2021-09-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
75 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
79 f259c4c1 2021-09-24 stsp # create the required dirvergant commit
80 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git checkout -q master)
81 f259c4c1 2021-09-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
82 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
83 f259c4c1 2021-09-24 stsp local master_commit=`git_show_head $testroot/repo`
85 5e91dae4 2022-08-30 stsp # need an up-to-date work tree for 'got merge'
86 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got merge newbranch \
87 f259c4c1 2021-09-24 stsp > $testroot/stdout 2> $testroot/stderr)
89 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
90 f259c4c1 2021-09-24 stsp echo "got merge succeeded unexpectedly" >&2
91 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
94 f259c4c1 2021-09-24 stsp echo -n "got: work tree must be updated before it can be used " \
95 f259c4c1 2021-09-24 stsp > $testroot/stderr.expected
96 f259c4c1 2021-09-24 stsp echo "to merge a branch" >> $testroot/stderr.expected
97 f259c4c1 2021-09-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
99 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
100 f259c4c1 2021-09-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
101 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
105 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got update > /dev/null)
107 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
108 f259c4c1 2021-09-24 stsp echo "got update failed unexpectedly" >&2
109 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
113 5e91dae4 2022-08-30 stsp # must not use a mixed-commit work tree with 'got merge'
114 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
116 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
117 f259c4c1 2021-09-24 stsp echo "got update failed unexpectedly" >&2
118 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
121 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got merge newbranch \
122 f259c4c1 2021-09-24 stsp > $testroot/stdout 2> $testroot/stderr)
124 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
125 f259c4c1 2021-09-24 stsp echo "got merge succeeded unexpectedly" >&2
126 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
129 f259c4c1 2021-09-24 stsp echo -n "got: work tree contains files from multiple base commits; " \
130 f259c4c1 2021-09-24 stsp > $testroot/stderr.expected
131 f259c4c1 2021-09-24 stsp echo "the entire work tree must be updated first" \
132 f259c4c1 2021-09-24 stsp >> $testroot/stderr.expected
133 f259c4c1 2021-09-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
135 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
136 f259c4c1 2021-09-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
137 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
141 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got update > /dev/null)
143 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
144 f259c4c1 2021-09-24 stsp echo "got update failed unexpectedly" >&2
145 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
149 5e91dae4 2022-08-30 stsp # must not have staged files with 'got merge'
150 f259c4c1 2021-09-24 stsp echo "modified file alpha" > $testroot/wt/alpha
151 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got stage alpha > /dev/null)
153 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
154 f259c4c1 2021-09-24 stsp echo "got stage failed unexpectedly" >&2
155 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
158 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got merge newbranch \
159 f259c4c1 2021-09-24 stsp > $testroot/stdout 2> $testroot/stderr)
161 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
162 f259c4c1 2021-09-24 stsp echo "got merge succeeded unexpectedly" >&2
163 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
166 f259c4c1 2021-09-24 stsp echo "got: alpha: file is staged" > $testroot/stderr.expected
167 f259c4c1 2021-09-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
169 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
170 f259c4c1 2021-09-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
171 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
174 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got unstage alpha > /dev/null)
176 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
177 f259c4c1 2021-09-24 stsp echo "got unstage failed unexpectedly" >&2
178 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
182 5e91dae4 2022-08-30 stsp # must not have local changes with 'got merge'
183 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got merge newbranch \
184 f259c4c1 2021-09-24 stsp > $testroot/stdout 2> $testroot/stderr)
186 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
187 f259c4c1 2021-09-24 stsp echo "got merge succeeded unexpectedly" >&2
188 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
191 f259c4c1 2021-09-24 stsp echo -n "got: work tree contains local changes; " \
192 f259c4c1 2021-09-24 stsp > $testroot/stderr.expected
193 f259c4c1 2021-09-24 stsp echo "these changes must be committed or reverted first" \
194 f259c4c1 2021-09-24 stsp >> $testroot/stderr.expected
195 f259c4c1 2021-09-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
197 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
198 f259c4c1 2021-09-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
199 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
203 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got revert alpha > /dev/null)
205 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
206 f259c4c1 2021-09-24 stsp echo "got revert failed unexpectedly" >&2
207 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
211 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got merge newbranch > $testroot/stdout)
213 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
214 f259c4c1 2021-09-24 stsp echo "got merge failed unexpectedly" >&2
215 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
219 f259c4c1 2021-09-24 stsp local merge_commit=`git_show_head $testroot/repo`
221 f259c4c1 2021-09-24 stsp echo "G alpha" >> $testroot/stdout.expected
222 f259c4c1 2021-09-24 stsp echo "D beta" >> $testroot/stdout.expected
223 5267b9e4 2021-09-26 stsp echo "A dotgotbar.link" >> $testroot/stdout.expected
224 f259c4c1 2021-09-24 stsp echo "A epsilon/new" >> $testroot/stdout.expected
225 f259c4c1 2021-09-24 stsp echo "G gamma/delta" >> $testroot/stdout.expected
226 f259c4c1 2021-09-24 stsp echo "A symlink" >> $testroot/stdout.expected
227 f259c4c1 2021-09-24 stsp echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
228 f259c4c1 2021-09-24 stsp >> $testroot/stdout.expected
229 f259c4c1 2021-09-24 stsp echo $merge_commit >> $testroot/stdout.expected
231 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
233 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
234 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
235 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
239 f259c4c1 2021-09-24 stsp echo "modified delta on branch" > $testroot/content.expected
240 f259c4c1 2021-09-24 stsp cat $testroot/wt/gamma/delta > $testroot/content
241 f259c4c1 2021-09-24 stsp cmp -s $testroot/content.expected $testroot/content
243 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
244 f259c4c1 2021-09-24 stsp diff -u $testroot/content.expected $testroot/content
245 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
249 f259c4c1 2021-09-24 stsp echo "modified alpha on branch" > $testroot/content.expected
250 f259c4c1 2021-09-24 stsp cat $testroot/wt/alpha > $testroot/content
251 f259c4c1 2021-09-24 stsp cmp -s $testroot/content.expected $testroot/content
253 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
254 f259c4c1 2021-09-24 stsp diff -u $testroot/content.expected $testroot/content
255 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
259 f259c4c1 2021-09-24 stsp if [ -e $testroot/wt/beta ]; then
260 f259c4c1 2021-09-24 stsp echo "removed file beta still exists on disk" >&2
261 f259c4c1 2021-09-24 stsp test_done "$testroot" "1"
265 f259c4c1 2021-09-24 stsp echo "new file on branch" > $testroot/content.expected
266 f259c4c1 2021-09-24 stsp cat $testroot/wt/epsilon/new > $testroot/content
267 f259c4c1 2021-09-24 stsp cmp -s $testroot/content.expected $testroot/content
269 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
270 f259c4c1 2021-09-24 stsp diff -u $testroot/content.expected $testroot/content
271 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
275 5267b9e4 2021-09-26 stsp if [ ! -h $testroot/wt/dotgotbar.link ]; then
276 5267b9e4 2021-09-26 stsp echo "dotgotbar.link is not a symlink"
277 5267b9e4 2021-09-26 stsp test_done "$testroot" "1"
281 f259c4c1 2021-09-24 stsp readlink $testroot/wt/symlink > $testroot/stdout
282 f259c4c1 2021-09-24 stsp echo "alpha" > $testroot/stdout.expected
283 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
285 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
286 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
287 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
291 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
293 f259c4c1 2021-09-24 stsp echo -n > $testroot/stdout.expected
294 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
296 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
297 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
298 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
302 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
303 f259c4c1 2021-09-24 stsp echo "commit $merge_commit (master)" > $testroot/stdout.expected
304 f259c4c1 2021-09-24 stsp echo "commit $master_commit" >> $testroot/stdout.expected
305 f259c4c1 2021-09-24 stsp echo "commit $commit0" >> $testroot/stdout.expected
306 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
308 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
309 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
310 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
314 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got update > $testroot/stdout)
316 5267b9e4 2021-09-26 stsp echo 'U dotgotbar.link' > $testroot/stdout.expected
317 5267b9e4 2021-09-26 stsp echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
318 5267b9e4 2021-09-26 stsp git_show_head $testroot/repo >> $testroot/stdout.expected
319 5267b9e4 2021-09-26 stsp echo >> $testroot/stdout.expected
320 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
322 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
323 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
324 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
328 5267b9e4 2021-09-26 stsp # update has changed the bad symlink into a regular file
329 5267b9e4 2021-09-26 stsp if [ -h $testroot/wt/dotgotbar.link ]; then
330 5267b9e4 2021-09-26 stsp echo "dotgotbar.link is a symlink"
331 5267b9e4 2021-09-26 stsp test_done "$testroot" "1"
335 f259c4c1 2021-09-24 stsp # We should have created a merge commit with two parents.
336 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
337 f259c4c1 2021-09-24 stsp echo "parent 1: $master_commit" > $testroot/stdout.expected
338 5267b9e4 2021-09-26 stsp echo "parent 2: $branch_commit5" >> $testroot/stdout.expected
339 5267b9e4 2021-09-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
341 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
342 5267b9e4 2021-09-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
343 5267b9e4 2021-09-26 stsp test_done "$testroot" "$ret"
347 5267b9e4 2021-09-26 stsp got tree -r $testroot/repo -c $merge_commit -R > $testroot/stdout
349 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
350 5267b9e4 2021-09-26 stsp echo "got tree failed unexpectedly" >&2
351 5267b9e4 2021-09-26 stsp test_done "$testroot" "$ret"
355 5267b9e4 2021-09-26 stsp # bad symlink dotgotbar.link appears as a symlink in the merge commit:
356 5267b9e4 2021-09-26 stsp cat > $testroot/stdout.expected <<EOF
358 5267b9e4 2021-09-26 stsp dotgotbar.link@ -> .got/bar
360 5267b9e4 2021-09-26 stsp epsilon/new
361 5267b9e4 2021-09-26 stsp epsilon/zeta
363 5267b9e4 2021-09-26 stsp gamma/delta
364 5267b9e4 2021-09-26 stsp symlink@ -> alpha
366 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
368 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
369 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
371 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
374 f259c4c1 2021-09-24 stsp test_merge_continue() {
375 f259c4c1 2021-09-24 stsp local testroot=`test_init merge_continue`
376 f259c4c1 2021-09-24 stsp local commit0=`git_show_head $testroot/repo`
377 f259c4c1 2021-09-24 stsp local commit0_author_time=`git_show_author_time $testroot/repo`
379 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git checkout -q -b newbranch)
380 f259c4c1 2021-09-24 stsp echo "modified delta on branch" > $testroot/repo/gamma/delta
381 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "committing to delta on newbranch"
382 f259c4c1 2021-09-24 stsp local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
384 f259c4c1 2021-09-24 stsp echo "modified alpha on branch" > $testroot/repo/alpha
385 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "committing to alpha on newbranch"
386 f259c4c1 2021-09-24 stsp local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
387 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git rm -q beta)
388 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "removing beta on newbranch"
389 f259c4c1 2021-09-24 stsp local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
390 f259c4c1 2021-09-24 stsp echo "new file on branch" > $testroot/repo/epsilon/new
391 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git add epsilon/new)
392 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "adding new file on newbranch"
393 f259c4c1 2021-09-24 stsp local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
395 f259c4c1 2021-09-24 stsp got checkout -b master $testroot/repo $testroot/wt > /dev/null
397 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
398 f259c4c1 2021-09-24 stsp echo "got checkout failed unexpectedly" >&2
399 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
403 f259c4c1 2021-09-24 stsp # create a conflicting commit
404 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git checkout -q master)
405 f259c4c1 2021-09-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
406 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "committing to alpha on master"
407 f259c4c1 2021-09-24 stsp local master_commit=`git_show_head $testroot/repo`
409 5e91dae4 2022-08-30 stsp # need an up-to-date work tree for 'got merge'
410 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got update > /dev/null)
412 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
413 f259c4c1 2021-09-24 stsp echo "got update failed unexpectedly" >&2
414 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
418 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got merge newbranch \
419 f259c4c1 2021-09-24 stsp > $testroot/stdout 2> $testroot/stderr)
421 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
422 f259c4c1 2021-09-24 stsp echo "got merge succeeded unexpectedly" >&2
423 f259c4c1 2021-09-24 stsp test_done "$testroot" "1"
427 f259c4c1 2021-09-24 stsp echo "C alpha" >> $testroot/stdout.expected
428 f259c4c1 2021-09-24 stsp echo "D beta" >> $testroot/stdout.expected
429 f259c4c1 2021-09-24 stsp echo "A epsilon/new" >> $testroot/stdout.expected
430 f259c4c1 2021-09-24 stsp echo "G gamma/delta" >> $testroot/stdout.expected
431 f259c4c1 2021-09-24 stsp echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
432 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
434 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
435 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
436 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
440 f259c4c1 2021-09-24 stsp echo "got: conflicts must be resolved before merging can continue" \
441 f259c4c1 2021-09-24 stsp > $testroot/stderr.expected
442 f259c4c1 2021-09-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
444 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
445 f259c4c1 2021-09-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
446 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
450 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
452 f259c4c1 2021-09-24 stsp echo "C alpha" > $testroot/stdout.expected
453 f259c4c1 2021-09-24 stsp echo "D beta" >> $testroot/stdout.expected
454 f259c4c1 2021-09-24 stsp echo "A epsilon/new" >> $testroot/stdout.expected
455 f259c4c1 2021-09-24 stsp echo "M gamma/delta" >> $testroot/stdout.expected
456 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
458 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
459 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
460 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
464 f259c4c1 2021-09-24 stsp echo '<<<<<<<' > $testroot/content.expected
465 f259c4c1 2021-09-24 stsp echo "modified alpha on master" >> $testroot/content.expected
466 f259c4c1 2021-09-24 stsp echo "||||||| 3-way merge base: commit $commit0" \
467 f259c4c1 2021-09-24 stsp >> $testroot/content.expected
468 f259c4c1 2021-09-24 stsp echo "alpha" >> $testroot/content.expected
469 f259c4c1 2021-09-24 stsp echo "=======" >> $testroot/content.expected
470 f259c4c1 2021-09-24 stsp echo "modified alpha on branch" >> $testroot/content.expected
471 f259c4c1 2021-09-24 stsp echo ">>>>>>> merged change: commit $branch_commit3" \
472 f259c4c1 2021-09-24 stsp >> $testroot/content.expected
473 f259c4c1 2021-09-24 stsp cat $testroot/wt/alpha > $testroot/content
474 f259c4c1 2021-09-24 stsp cmp -s $testroot/content.expected $testroot/content
476 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
477 f259c4c1 2021-09-24 stsp diff -u $testroot/content.expected $testroot/content
478 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
482 f259c4c1 2021-09-24 stsp # resolve the conflict
483 f259c4c1 2021-09-24 stsp echo "modified alpha by both branches" > $testroot/wt/alpha
485 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got merge -c > $testroot/stdout)
487 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
488 f259c4c1 2021-09-24 stsp echo "got merge failed unexpectedly" >&2
489 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
493 f259c4c1 2021-09-24 stsp local merge_commit=`git_show_head $testroot/repo`
495 0ff8d236 2021-09-28 stsp echo "M alpha" > $testroot/stdout.expected
496 0ff8d236 2021-09-28 stsp echo "D beta" >> $testroot/stdout.expected
497 0ff8d236 2021-09-28 stsp echo "A epsilon/new" >> $testroot/stdout.expected
498 0ff8d236 2021-09-28 stsp echo "M gamma/delta" >> $testroot/stdout.expected
499 f259c4c1 2021-09-24 stsp echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
500 0ff8d236 2021-09-28 stsp >> $testroot/stdout.expected
501 f259c4c1 2021-09-24 stsp echo $merge_commit >> $testroot/stdout.expected
503 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
505 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
506 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
507 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
511 f259c4c1 2021-09-24 stsp echo "modified delta on branch" > $testroot/content.expected
512 f259c4c1 2021-09-24 stsp cat $testroot/wt/gamma/delta > $testroot/content
513 f259c4c1 2021-09-24 stsp cmp -s $testroot/content.expected $testroot/content
515 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
516 f259c4c1 2021-09-24 stsp diff -u $testroot/content.expected $testroot/content
517 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
521 f259c4c1 2021-09-24 stsp echo "modified alpha by both branches" > $testroot/content.expected
522 f259c4c1 2021-09-24 stsp cat $testroot/wt/alpha > $testroot/content
523 f259c4c1 2021-09-24 stsp cmp -s $testroot/content.expected $testroot/content
525 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
526 f259c4c1 2021-09-24 stsp diff -u $testroot/content.expected $testroot/content
527 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
531 f259c4c1 2021-09-24 stsp if [ -e $testroot/wt/beta ]; then
532 f259c4c1 2021-09-24 stsp echo "removed file beta still exists on disk" >&2
533 f259c4c1 2021-09-24 stsp test_done "$testroot" "1"
537 f259c4c1 2021-09-24 stsp echo "new file on branch" > $testroot/content.expected
538 f259c4c1 2021-09-24 stsp cat $testroot/wt/epsilon/new > $testroot/content
539 f259c4c1 2021-09-24 stsp cmp -s $testroot/content.expected $testroot/content
541 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
542 f259c4c1 2021-09-24 stsp diff -u $testroot/content.expected $testroot/content
543 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
547 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
549 f259c4c1 2021-09-24 stsp echo -n > $testroot/stdout.expected
550 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
552 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
553 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
554 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
558 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
559 f259c4c1 2021-09-24 stsp echo "commit $merge_commit (master)" > $testroot/stdout.expected
560 f259c4c1 2021-09-24 stsp echo "commit $master_commit" >> $testroot/stdout.expected
561 f259c4c1 2021-09-24 stsp echo "commit $commit0" >> $testroot/stdout.expected
562 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
564 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
565 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
566 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
570 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got update > $testroot/stdout)
572 f259c4c1 2021-09-24 stsp echo 'Already up-to-date' > $testroot/stdout.expected
573 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
575 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
576 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
577 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
581 f259c4c1 2021-09-24 stsp # We should have created a merge commit with two parents.
582 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
583 f259c4c1 2021-09-24 stsp echo "parent 1: $master_commit" > $testroot/stdout.expected
584 f259c4c1 2021-09-24 stsp echo "parent 2: $branch_commit3" >> $testroot/stdout.expected
585 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
587 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
588 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
590 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
593 f259c4c1 2021-09-24 stsp test_merge_abort() {
594 f259c4c1 2021-09-24 stsp local testroot=`test_init merge_abort`
595 f259c4c1 2021-09-24 stsp local commit0=`git_show_head $testroot/repo`
596 f259c4c1 2021-09-24 stsp local commit0_author_time=`git_show_author_time $testroot/repo`
598 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git checkout -q -b newbranch)
599 f259c4c1 2021-09-24 stsp echo "modified delta on branch" > $testroot/repo/gamma/delta
600 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "committing to delta on newbranch"
601 f259c4c1 2021-09-24 stsp local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
603 f259c4c1 2021-09-24 stsp echo "modified alpha on branch" > $testroot/repo/alpha
604 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "committing to alpha on newbranch"
605 f259c4c1 2021-09-24 stsp local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
606 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git rm -q beta)
607 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "removing beta on newbranch"
608 f259c4c1 2021-09-24 stsp local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
609 f259c4c1 2021-09-24 stsp echo "new file on branch" > $testroot/repo/epsilon/new
610 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git add epsilon/new)
611 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "adding new file on newbranch"
612 f259c4c1 2021-09-24 stsp local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
613 f259c4c1 2021-09-24 stsp (cd $testroot/repo && ln -s alpha symlink && git add symlink)
614 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "adding symlink on newbranch"
615 f259c4c1 2021-09-24 stsp local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
617 f259c4c1 2021-09-24 stsp got checkout -b master $testroot/repo $testroot/wt > /dev/null
619 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
620 f259c4c1 2021-09-24 stsp echo "got checkout failed unexpectedly" >&2
621 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
625 41f061b2 2021-10-05 stsp # unrelated unversioned file in work tree
626 41f061b2 2021-10-05 stsp touch $testroot/wt/unversioned-file
628 f259c4c1 2021-09-24 stsp # create a conflicting commit
629 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git checkout -q master)
630 f259c4c1 2021-09-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
631 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "committing to alpha on master"
632 f259c4c1 2021-09-24 stsp local master_commit=`git_show_head $testroot/repo`
634 5e91dae4 2022-08-30 stsp # need an up-to-date work tree for 'got merge'
635 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got update > /dev/null)
637 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
638 f259c4c1 2021-09-24 stsp echo "got update failed unexpectedly" >&2
639 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
643 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got merge newbranch \
644 f259c4c1 2021-09-24 stsp > $testroot/stdout 2> $testroot/stderr)
646 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
647 f259c4c1 2021-09-24 stsp echo "got merge succeeded unexpectedly" >&2
648 f259c4c1 2021-09-24 stsp test_done "$testroot" "1"
652 f259c4c1 2021-09-24 stsp echo "C alpha" >> $testroot/stdout.expected
653 f259c4c1 2021-09-24 stsp echo "D beta" >> $testroot/stdout.expected
654 f259c4c1 2021-09-24 stsp echo "A epsilon/new" >> $testroot/stdout.expected
655 f259c4c1 2021-09-24 stsp echo "G gamma/delta" >> $testroot/stdout.expected
656 f259c4c1 2021-09-24 stsp echo "A symlink" >> $testroot/stdout.expected
657 f259c4c1 2021-09-24 stsp echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
658 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
660 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
661 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
662 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
666 f259c4c1 2021-09-24 stsp echo "got: conflicts must be resolved before merging can continue" \
667 f259c4c1 2021-09-24 stsp > $testroot/stderr.expected
668 f259c4c1 2021-09-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
670 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
671 f259c4c1 2021-09-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
672 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
676 af179be7 2023-04-14 stsp # unrelated added file added during conflict resolution
677 af179be7 2023-04-14 stsp touch $testroot/wt/added-file
678 af179be7 2023-04-14 stsp (cd $testroot/wt && got add added-file > /dev/null)
680 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
682 af179be7 2023-04-14 stsp echo "A added-file" > $testroot/stdout.expected
683 af179be7 2023-04-14 stsp echo "C alpha" >> $testroot/stdout.expected
684 f259c4c1 2021-09-24 stsp echo "D beta" >> $testroot/stdout.expected
685 f259c4c1 2021-09-24 stsp echo "A epsilon/new" >> $testroot/stdout.expected
686 f259c4c1 2021-09-24 stsp echo "M gamma/delta" >> $testroot/stdout.expected
687 f259c4c1 2021-09-24 stsp echo "A symlink" >> $testroot/stdout.expected
688 41f061b2 2021-10-05 stsp echo "? unversioned-file" >> $testroot/stdout.expected
689 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
691 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
692 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
693 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
697 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got merge -a > $testroot/stdout)
699 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
700 f259c4c1 2021-09-24 stsp echo "got merge failed unexpectedly" >&2
701 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
705 af179be7 2023-04-14 stsp echo "R added-file" > $testroot/stdout.expected
706 af179be7 2023-04-14 stsp echo "R alpha" >> $testroot/stdout.expected
707 f259c4c1 2021-09-24 stsp echo "R beta" >> $testroot/stdout.expected
708 f259c4c1 2021-09-24 stsp echo "R epsilon/new" >> $testroot/stdout.expected
709 f259c4c1 2021-09-24 stsp echo "R gamma/delta" >> $testroot/stdout.expected
710 f259c4c1 2021-09-24 stsp echo "R symlink" >> $testroot/stdout.expected
711 af179be7 2023-04-14 stsp echo "G added-file" >> $testroot/stdout.expected
712 f259c4c1 2021-09-24 stsp echo "Merge of refs/heads/newbranch aborted" \
713 f259c4c1 2021-09-24 stsp >> $testroot/stdout.expected
715 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
717 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
718 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
719 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
723 f259c4c1 2021-09-24 stsp echo "delta" > $testroot/content.expected
724 f259c4c1 2021-09-24 stsp cat $testroot/wt/gamma/delta > $testroot/content
725 f259c4c1 2021-09-24 stsp cmp -s $testroot/content.expected $testroot/content
727 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
728 f259c4c1 2021-09-24 stsp diff -u $testroot/content.expected $testroot/content
729 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
733 f259c4c1 2021-09-24 stsp echo "modified alpha on master" > $testroot/content.expected
734 f259c4c1 2021-09-24 stsp cat $testroot/wt/alpha > $testroot/content
735 f259c4c1 2021-09-24 stsp cmp -s $testroot/content.expected $testroot/content
737 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
738 f259c4c1 2021-09-24 stsp diff -u $testroot/content.expected $testroot/content
739 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
743 f259c4c1 2021-09-24 stsp echo "beta" > $testroot/content.expected
744 f259c4c1 2021-09-24 stsp cat $testroot/wt/beta > $testroot/content
745 f259c4c1 2021-09-24 stsp cmp -s $testroot/content.expected $testroot/content
747 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
748 f259c4c1 2021-09-24 stsp diff -u $testroot/content.expected $testroot/content
749 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
753 f259c4c1 2021-09-24 stsp if [ -e $testroot/wt/epsilon/new ]; then
754 f259c4c1 2021-09-24 stsp echo "reverted file epsilon/new still exists on disk" >&2
755 f259c4c1 2021-09-24 stsp test_done "$testroot" "1"
759 f259c4c1 2021-09-24 stsp if [ -e $testroot/wt/symlink ]; then
760 f259c4c1 2021-09-24 stsp echo "reverted symlink still exists on disk" >&2
761 f259c4c1 2021-09-24 stsp test_done "$testroot" "1"
765 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
767 af179be7 2023-04-14 stsp echo "? added-file" > $testroot/stdout.expected
768 af179be7 2023-04-14 stsp echo "? unversioned-file" >> $testroot/stdout.expected
769 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
771 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
772 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
773 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
777 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
778 f259c4c1 2021-09-24 stsp echo "commit $master_commit (master)" > $testroot/stdout.expected
779 f259c4c1 2021-09-24 stsp echo "commit $commit0" >> $testroot/stdout.expected
780 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
782 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
783 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
784 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
788 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got update > $testroot/stdout)
790 f259c4c1 2021-09-24 stsp echo 'Already up-to-date' > $testroot/stdout.expected
791 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
793 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
794 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
796 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
799 f259c4c1 2021-09-24 stsp test_merge_in_progress() {
800 f259c4c1 2021-09-24 stsp local testroot=`test_init merge_in_progress`
801 f259c4c1 2021-09-24 stsp local commit0=`git_show_head $testroot/repo`
802 f259c4c1 2021-09-24 stsp local commit0_author_time=`git_show_author_time $testroot/repo`
804 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git checkout -q -b newbranch)
805 f259c4c1 2021-09-24 stsp echo "modified alpha on branch" > $testroot/repo/alpha
806 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "committing to alpha on newbranch"
807 f259c4c1 2021-09-24 stsp local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
809 f259c4c1 2021-09-24 stsp got checkout -b master $testroot/repo $testroot/wt > /dev/null
811 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
812 f259c4c1 2021-09-24 stsp echo "got checkout failed unexpectedly" >&2
813 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
817 f259c4c1 2021-09-24 stsp # create a conflicting commit
818 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git checkout -q master)
819 f259c4c1 2021-09-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
820 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "committing to alpha on master"
821 f259c4c1 2021-09-24 stsp local master_commit=`git_show_head $testroot/repo`
823 5e91dae4 2022-08-30 stsp # need an up-to-date work tree for 'got merge'
824 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got update > /dev/null)
826 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
827 f259c4c1 2021-09-24 stsp echo "got update failed unexpectedly" >&2
828 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
832 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got merge newbranch \
833 f259c4c1 2021-09-24 stsp > $testroot/stdout 2> $testroot/stderr)
835 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
836 f259c4c1 2021-09-24 stsp echo "got merge succeeded unexpectedly" >&2
837 f259c4c1 2021-09-24 stsp test_done "$testroot" "1"
841 f259c4c1 2021-09-24 stsp echo "C alpha" >> $testroot/stdout.expected
842 f259c4c1 2021-09-24 stsp echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
843 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
845 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
846 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
847 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
851 f259c4c1 2021-09-24 stsp echo "got: conflicts must be resolved before merging can continue" \
852 f259c4c1 2021-09-24 stsp > $testroot/stderr.expected
853 f259c4c1 2021-09-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
855 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
856 f259c4c1 2021-09-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
857 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
861 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
863 f259c4c1 2021-09-24 stsp echo "C alpha" > $testroot/stdout.expected
864 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
866 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
867 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
868 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
872 f259c4c1 2021-09-24 stsp for cmd in update commit histedit "rebase newbranch" \
873 f259c4c1 2021-09-24 stsp "integrate newbranch" "stage alpha"; do
874 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got $cmd > $testroot/stdout \
875 f259c4c1 2021-09-24 stsp 2> $testroot/stderr)
877 f259c4c1 2021-09-24 stsp echo -n > $testroot/stdout.expected
878 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
880 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
881 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
882 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
886 f259c4c1 2021-09-24 stsp echo -n "got: a merge operation is in progress in this " \
887 f259c4c1 2021-09-24 stsp > $testroot/stderr.expected
888 f259c4c1 2021-09-24 stsp echo "work tree and must be continued or aborted first" \
889 f259c4c1 2021-09-24 stsp >> $testroot/stderr.expected
890 f259c4c1 2021-09-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
892 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
893 f259c4c1 2021-09-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
894 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
899 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
902 f259c4c1 2021-09-24 stsp test_merge_path_prefix() {
903 f259c4c1 2021-09-24 stsp local testroot=`test_init merge_path_prefix`
904 f259c4c1 2021-09-24 stsp local commit0=`git_show_head $testroot/repo`
905 f259c4c1 2021-09-24 stsp local commit0_author_time=`git_show_author_time $testroot/repo`
907 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git checkout -q -b newbranch)
908 f259c4c1 2021-09-24 stsp echo "modified alpha on branch" > $testroot/repo/alpha
909 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "committing to alpha on newbranch"
910 f259c4c1 2021-09-24 stsp local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
912 f259c4c1 2021-09-24 stsp got checkout -p epsilon -b master $testroot/repo $testroot/wt \
913 f259c4c1 2021-09-24 stsp > /dev/null
915 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
916 f259c4c1 2021-09-24 stsp echo "got checkout failed unexpectedly" >&2
917 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
921 f259c4c1 2021-09-24 stsp # create a conflicting commit
922 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git checkout -q master)
923 f259c4c1 2021-09-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
924 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "committing to alpha on master"
925 f259c4c1 2021-09-24 stsp local master_commit=`git_show_head $testroot/repo`
927 5e91dae4 2022-08-30 stsp # need an up-to-date work tree for 'got merge'
928 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got update > /dev/null)
930 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
931 f259c4c1 2021-09-24 stsp echo "got update failed unexpectedly" >&2
932 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
936 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got merge newbranch \
937 f259c4c1 2021-09-24 stsp > $testroot/stdout 2> $testroot/stderr)
939 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
940 f259c4c1 2021-09-24 stsp echo "got merge succeeded unexpectedly" >&2
941 f259c4c1 2021-09-24 stsp test_done "$testroot" "1"
945 f259c4c1 2021-09-24 stsp echo -n "got: cannot merge branch which contains changes outside " \
946 f259c4c1 2021-09-24 stsp > $testroot/stderr.expected
947 f259c4c1 2021-09-24 stsp echo "of this work tree's path prefix" >> $testroot/stderr.expected
948 f259c4c1 2021-09-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
950 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
951 f259c4c1 2021-09-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
953 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
956 f259c4c1 2021-09-24 stsp test_merge_missing_file() {
957 f259c4c1 2021-09-24 stsp local testroot=`test_init merge_missing_file`
958 f259c4c1 2021-09-24 stsp local commit0=`git_show_head $testroot/repo`
959 f259c4c1 2021-09-24 stsp local commit0_author_time=`git_show_author_time $testroot/repo`
961 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git checkout -q -b newbranch)
962 f259c4c1 2021-09-24 stsp echo "modified alpha on branch" > $testroot/repo/alpha
963 f259c4c1 2021-09-24 stsp echo "modified delta on branch" > $testroot/repo/gamma/delta
964 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "committing to alpha and delta"
965 f259c4c1 2021-09-24 stsp local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
967 f259c4c1 2021-09-24 stsp got checkout -b master $testroot/repo $testroot/wt > /dev/null
969 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
970 f259c4c1 2021-09-24 stsp echo "got checkout failed unexpectedly" >&2
971 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
975 f259c4c1 2021-09-24 stsp # create a conflicting commit which renames alpha
976 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git checkout -q master)
977 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git mv alpha epsilon/alpha-moved)
978 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "moving alpha on master"
979 f259c4c1 2021-09-24 stsp local master_commit=`git_show_head $testroot/repo`
981 5e91dae4 2022-08-30 stsp # need an up-to-date work tree for 'got merge'
982 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got update > /dev/null)
984 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
985 f259c4c1 2021-09-24 stsp echo "got update failed unexpectedly" >&2
986 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
990 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got merge newbranch \
991 f259c4c1 2021-09-24 stsp > $testroot/stdout 2> $testroot/stderr)
993 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
994 f259c4c1 2021-09-24 stsp echo "got merge succeeded unexpectedly" >&2
995 f259c4c1 2021-09-24 stsp test_done "$testroot" "1"
999 f259c4c1 2021-09-24 stsp echo "! alpha" > $testroot/stdout.expected
1000 f259c4c1 2021-09-24 stsp echo "G gamma/delta" >> $testroot/stdout.expected
1001 35ca1db7 2021-09-28 stsp echo -n "Files which had incoming changes but could not be found " \
1002 35ca1db7 2021-09-28 stsp >> $testroot/stdout.expected
1003 35ca1db7 2021-09-28 stsp echo "in the work tree: 1" >> $testroot/stdout.expected
1004 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1006 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1007 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
1008 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
1012 c1b05723 2021-09-28 stsp echo -n "got: changes destined for some files " \
1013 f259c4c1 2021-09-24 stsp > $testroot/stderr.expected
1014 f259c4c1 2021-09-24 stsp echo -n "were not yet merged and should be merged manually if " \
1015 f259c4c1 2021-09-24 stsp >> $testroot/stderr.expected
1016 f259c4c1 2021-09-24 stsp echo "required before the merge operation is continued" \
1017 f259c4c1 2021-09-24 stsp >> $testroot/stderr.expected
1018 f259c4c1 2021-09-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
1020 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1021 f259c4c1 2021-09-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
1022 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
1026 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
1028 f259c4c1 2021-09-24 stsp echo "M gamma/delta" > $testroot/stdout.expected
1029 a6a8f8bb 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1031 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1032 a6a8f8bb 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
1033 a6a8f8bb 2021-09-24 stsp test_done "$testroot" "$ret"
1037 a6a8f8bb 2021-09-24 stsp test_done "$testroot" "$ret"
1040 a6a8f8bb 2021-09-24 stsp test_merge_no_op() {
1041 a6a8f8bb 2021-09-24 stsp local testroot=`test_init merge_no_op`
1042 a6a8f8bb 2021-09-24 stsp local commit0=`git_show_head $testroot/repo`
1043 a6a8f8bb 2021-09-24 stsp local commit0_author_time=`git_show_author_time $testroot/repo`
1045 a6a8f8bb 2021-09-24 stsp (cd $testroot/repo && git checkout -q -b newbranch)
1046 a6a8f8bb 2021-09-24 stsp echo "modified alpha on branch" > $testroot/repo/alpha
1047 a6a8f8bb 2021-09-24 stsp git_commit $testroot/repo -m "committing to alpha on newbranch"
1048 35d2583f 2023-04-17 stsp local branch_commit=`git_show_branch_head $testroot/repo newbranch`
1050 a6a8f8bb 2021-09-24 stsp got checkout -b master $testroot/repo $testroot/wt > /dev/null
1052 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1053 a6a8f8bb 2021-09-24 stsp echo "got checkout failed unexpectedly" >&2
1054 a6a8f8bb 2021-09-24 stsp test_done "$testroot" "$ret"
1058 a6a8f8bb 2021-09-24 stsp # create a conflicting commit
1059 a6a8f8bb 2021-09-24 stsp (cd $testroot/repo && git checkout -q master)
1060 a6a8f8bb 2021-09-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
1061 a6a8f8bb 2021-09-24 stsp git_commit $testroot/repo -m "committing to alpha on master"
1062 a6a8f8bb 2021-09-24 stsp local master_commit=`git_show_head $testroot/repo`
1064 5e91dae4 2022-08-30 stsp # need an up-to-date work tree for 'got merge'
1065 a6a8f8bb 2021-09-24 stsp (cd $testroot/wt && got update > /dev/null)
1067 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1068 a6a8f8bb 2021-09-24 stsp echo "got update failed unexpectedly" >&2
1069 a6a8f8bb 2021-09-24 stsp test_done "$testroot" "$ret"
1073 a6a8f8bb 2021-09-24 stsp (cd $testroot/wt && got merge newbranch \
1074 a6a8f8bb 2021-09-24 stsp > $testroot/stdout 2> $testroot/stderr)
1076 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
1077 a6a8f8bb 2021-09-24 stsp echo "got merge succeeded unexpectedly" >&2
1078 a6a8f8bb 2021-09-24 stsp test_done "$testroot" "1"
1082 a6a8f8bb 2021-09-24 stsp echo "C alpha" >> $testroot/stdout.expected
1083 a6a8f8bb 2021-09-24 stsp echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1084 a6a8f8bb 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1086 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1087 a6a8f8bb 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
1088 a6a8f8bb 2021-09-24 stsp test_done "$testroot" "$ret"
1092 a6a8f8bb 2021-09-24 stsp echo "got: conflicts must be resolved before merging can continue" \
1093 a6a8f8bb 2021-09-24 stsp > $testroot/stderr.expected
1094 a6a8f8bb 2021-09-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
1096 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1097 a6a8f8bb 2021-09-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
1098 a6a8f8bb 2021-09-24 stsp test_done "$testroot" "$ret"
1102 a6a8f8bb 2021-09-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
1104 a6a8f8bb 2021-09-24 stsp echo "C alpha" > $testroot/stdout.expected
1105 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1107 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1108 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
1109 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
1113 a6a8f8bb 2021-09-24 stsp # resolve the conflict by reverting all changes; now it is no-op merge
1114 a6a8f8bb 2021-09-24 stsp (cd $testroot/wt && got revert alpha > /dev/null)
1116 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1117 a6a8f8bb 2021-09-24 stsp echo "got revert failed unexpectedly" >&2
1118 a6a8f8bb 2021-09-24 stsp test_done "$testroot" "$ret"
1122 a6a8f8bb 2021-09-24 stsp (cd $testroot/wt && got merge -c > $testroot/stdout \
1123 a6a8f8bb 2021-09-24 stsp 2> $testroot/stderr)
1125 35d2583f 2023-04-17 stsp if [ $ret -ne 0 ]; then
1126 35d2583f 2023-04-17 stsp echo "got merge failed unexpectedly" >&2
1127 a6a8f8bb 2021-09-24 stsp test_done "$testroot" "$ret"
1131 35d2583f 2023-04-17 stsp echo -n '' > $testroot/stderr.expected
1132 a6a8f8bb 2021-09-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
1134 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1135 a6a8f8bb 2021-09-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
1136 35d2583f 2023-04-17 stsp test_done "$testroot" "$ret"
1140 35d2583f 2023-04-17 stsp local merge_commit=`git_show_head $testroot/repo`
1141 35d2583f 2023-04-17 stsp echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1142 35d2583f 2023-04-17 stsp > $testroot/stdout.expected
1143 35d2583f 2023-04-17 stsp echo $merge_commit >> $testroot/stdout.expected
1145 35d2583f 2023-04-17 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1147 35d2583f 2023-04-17 stsp if [ $ret -ne 0 ]; then
1148 35d2583f 2023-04-17 stsp diff -u $testroot/stdout.expected $testroot/stdout
1149 a6a8f8bb 2021-09-24 stsp test_done "$testroot" "$ret"
1153 a6a8f8bb 2021-09-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
1155 a6a8f8bb 2021-09-24 stsp echo -n "" > $testroot/stdout.expected
1156 4e91ef15 2021-09-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1158 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1159 4e91ef15 2021-09-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
1160 35d2583f 2023-04-17 stsp test_done "$testroot" "$ret"
1164 35d2583f 2023-04-17 stsp # We should have created a merge commit with two parents.
1165 35d2583f 2023-04-17 stsp got log -r $testroot/repo -l1 -c $merge_commit | grep ^parent \
1166 35d2583f 2023-04-17 stsp > $testroot/stdout
1167 35d2583f 2023-04-17 stsp echo "parent 1: $master_commit" > $testroot/stdout.expected
1168 35d2583f 2023-04-17 stsp echo "parent 2: $branch_commit" >> $testroot/stdout.expected
1169 35d2583f 2023-04-17 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1171 35d2583f 2023-04-17 stsp if [ $ret -ne 0 ]; then
1172 35d2583f 2023-04-17 stsp diff -u $testroot/stdout.expected $testroot/stdout
1174 4e91ef15 2021-09-26 stsp test_done "$testroot" "$ret"
1177 4e91ef15 2021-09-26 stsp test_merge_imported_branch() {
1178 4e91ef15 2021-09-26 stsp local testroot=`test_init merge_import`
1179 4e91ef15 2021-09-26 stsp local commit0=`git_show_head $testroot/repo`
1180 4e91ef15 2021-09-26 stsp local commit0_author_time=`git_show_author_time $testroot/repo`
1182 4e91ef15 2021-09-26 stsp # import a new sub-tree to the 'files' branch such that
1183 4e91ef15 2021-09-26 stsp # none of the files added here collide with existing ones
1184 4e91ef15 2021-09-26 stsp mkdir -p $testroot/tree/there
1185 4e91ef15 2021-09-26 stsp mkdir -p $testroot/tree/be/lots
1186 4e91ef15 2021-09-26 stsp mkdir -p $testroot/tree/files
1187 4e91ef15 2021-09-26 stsp echo "there should" > $testroot/tree/there/should
1188 4e91ef15 2021-09-26 stsp echo "be lots of" > $testroot/tree/be/lots/of
1189 4e91ef15 2021-09-26 stsp echo "files here" > $testroot/tree/files/here
1190 4e91ef15 2021-09-26 stsp got import -r $testroot/repo -b files -m 'import files' \
1191 4e91ef15 2021-09-26 stsp $testroot/tree > /dev/null
1193 4e91ef15 2021-09-26 stsp got checkout -b master $testroot/repo $testroot/wt > /dev/null
1195 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1196 4e91ef15 2021-09-26 stsp echo "got checkout failed unexpectedly" >&2
1197 4e91ef15 2021-09-26 stsp test_done "$testroot" "$ret"
1201 4e91ef15 2021-09-26 stsp (cd $testroot/wt && got merge files > $testroot/stdout)
1203 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1204 4e91ef15 2021-09-26 stsp echo "got merge failed unexpectedly" >&2
1205 4e91ef15 2021-09-26 stsp test_done "$testroot" "$ret"
1209 4e91ef15 2021-09-26 stsp local merge_commit0=`git_show_head $testroot/repo`
1210 4e91ef15 2021-09-26 stsp cat > $testroot/stdout.expected <<EOF
1211 4e91ef15 2021-09-26 stsp A be/lots/of
1212 4e91ef15 2021-09-26 stsp A files/here
1213 4e91ef15 2021-09-26 stsp A there/should
1214 4e91ef15 2021-09-26 stsp Merged refs/heads/files into refs/heads/master: $merge_commit0
1216 4e91ef15 2021-09-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1218 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1219 4e91ef15 2021-09-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
1220 4e91ef15 2021-09-26 stsp test_done "$testroot" "$ret"
1224 4e91ef15 2021-09-26 stsp # try to merge again while no new changes are available
1225 4e91ef15 2021-09-26 stsp (cd $testroot/wt && got merge files > $testroot/stdout)
1227 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1228 4e91ef15 2021-09-26 stsp echo "got merge failed unexpectedly" >&2
1229 4e91ef15 2021-09-26 stsp test_done "$testroot" "$ret"
1232 4e91ef15 2021-09-26 stsp echo "Already up-to-date" > $testroot/stdout.expected
1233 a6a8f8bb 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1235 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1236 a6a8f8bb 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
1237 4e91ef15 2021-09-26 stsp test_done "$testroot" "$ret"
1241 4e91ef15 2021-09-26 stsp # update the 'files' branch
1242 4e91ef15 2021-09-26 stsp (cd $testroot/repo && git reset -q --hard master)
1243 4e91ef15 2021-09-26 stsp (cd $testroot/repo && git checkout -q files)
1244 4e91ef15 2021-09-26 stsp echo "indeed" > $testroot/repo/indeed
1245 4e91ef15 2021-09-26 stsp (cd $testroot/repo && git add indeed)
1246 4e91ef15 2021-09-26 stsp git_commit $testroot/repo -m "adding another file indeed"
1247 4e91ef15 2021-09-26 stsp echo "be lots and lots of" > $testroot/repo/be/lots/of
1248 4e91ef15 2021-09-26 stsp git_commit $testroot/repo -m "lots of changes"
1250 4e91ef15 2021-09-26 stsp (cd $testroot/wt && got update > /dev/null)
1252 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1253 4e91ef15 2021-09-26 stsp echo "got update failed unexpectedly" >&2
1254 4e91ef15 2021-09-26 stsp test_done "$testroot" "$ret"
1258 4e91ef15 2021-09-26 stsp # we should now be able to merge more changes from files branch
1259 4e91ef15 2021-09-26 stsp (cd $testroot/wt && got merge files > $testroot/stdout)
1261 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1262 4e91ef15 2021-09-26 stsp echo "got merge failed unexpectedly" >&2
1263 4e91ef15 2021-09-26 stsp test_done "$testroot" "$ret"
1267 4e91ef15 2021-09-26 stsp local merge_commit1=`git_show_branch_head $testroot/repo master`
1268 4e91ef15 2021-09-26 stsp cat > $testroot/stdout.expected <<EOF
1269 4e91ef15 2021-09-26 stsp G be/lots/of
1271 4e91ef15 2021-09-26 stsp Merged refs/heads/files into refs/heads/master: $merge_commit1
1274 4e91ef15 2021-09-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1276 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1277 4e91ef15 2021-09-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
1279 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
1282 088449d3 2021-09-26 stsp test_merge_interrupt() {
1283 088449d3 2021-09-26 stsp local testroot=`test_init merge_interrupt`
1284 088449d3 2021-09-26 stsp local commit0=`git_show_head $testroot/repo`
1285 088449d3 2021-09-26 stsp local commit0_author_time=`git_show_author_time $testroot/repo`
1287 088449d3 2021-09-26 stsp (cd $testroot/repo && git checkout -q -b newbranch)
1288 088449d3 2021-09-26 stsp echo "modified alpha on branch" > $testroot/repo/alpha
1289 088449d3 2021-09-26 stsp git_commit $testroot/repo -m "committing to alpha on newbranch"
1290 088449d3 2021-09-26 stsp local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1292 088449d3 2021-09-26 stsp got checkout -b master $testroot/repo $testroot/wt > /dev/null
1294 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1295 088449d3 2021-09-26 stsp echo "got checkout failed unexpectedly" >&2
1296 088449d3 2021-09-26 stsp test_done "$testroot" "$ret"
1300 088449d3 2021-09-26 stsp # create a non-conflicting commit
1301 088449d3 2021-09-26 stsp (cd $testroot/repo && git checkout -q master)
1302 088449d3 2021-09-26 stsp echo "modified beta on master" > $testroot/repo/beta
1303 088449d3 2021-09-26 stsp git_commit $testroot/repo -m "committing to beta on master"
1304 088449d3 2021-09-26 stsp local master_commit=`git_show_head $testroot/repo`
1306 5e91dae4 2022-08-30 stsp # need an up-to-date work tree for 'got merge'
1307 088449d3 2021-09-26 stsp (cd $testroot/wt && got update > /dev/null)
1309 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1310 088449d3 2021-09-26 stsp echo "got update failed unexpectedly" >&2
1311 088449d3 2021-09-26 stsp test_done "$testroot" "$ret"
1315 088449d3 2021-09-26 stsp (cd $testroot/wt && got merge -n newbranch \
1316 088449d3 2021-09-26 stsp > $testroot/stdout 2> $testroot/stderr)
1318 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1319 088449d3 2021-09-26 stsp echo "got merge failed unexpectedly" >&2
1320 088449d3 2021-09-26 stsp test_done "$testroot" "1"
1324 088449d3 2021-09-26 stsp echo "G alpha" > $testroot/stdout.expected
1325 088449d3 2021-09-26 stsp echo "Merge of refs/heads/newbranch interrupted on request" \
1326 088449d3 2021-09-26 stsp >> $testroot/stdout.expected
1327 088449d3 2021-09-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1329 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1330 088449d3 2021-09-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
1331 088449d3 2021-09-26 stsp test_done "$testroot" "$ret"
1335 088449d3 2021-09-26 stsp (cd $testroot/wt && got status > $testroot/stdout)
1337 088449d3 2021-09-26 stsp echo "M alpha" > $testroot/stdout.expected
1338 088449d3 2021-09-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1340 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1341 088449d3 2021-09-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
1342 088449d3 2021-09-26 stsp test_done "$testroot" "$ret"
1346 088449d3 2021-09-26 stsp echo "modified alpha on branch" > $testroot/content.expected
1347 088449d3 2021-09-26 stsp cat $testroot/wt/alpha > $testroot/content
1348 088449d3 2021-09-26 stsp cmp -s $testroot/content.expected $testroot/content
1350 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1351 088449d3 2021-09-26 stsp diff -u $testroot/content.expected $testroot/content
1352 088449d3 2021-09-26 stsp test_done "$testroot" "$ret"
1356 088449d3 2021-09-26 stsp # adjust merge result
1357 088449d3 2021-09-26 stsp echo "adjusted merge result" > $testroot/wt/alpha
1359 088449d3 2021-09-26 stsp # continue the merge
1360 088449d3 2021-09-26 stsp (cd $testroot/wt && got merge -c > $testroot/stdout)
1362 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1363 088449d3 2021-09-26 stsp echo "got merge failed unexpectedly" >&2
1364 088449d3 2021-09-26 stsp test_done "$testroot" "$ret"
1368 088449d3 2021-09-26 stsp local merge_commit=`git_show_head $testroot/repo`
1370 0ff8d236 2021-09-28 stsp echo "M alpha" > $testroot/stdout.expected
1371 088449d3 2021-09-26 stsp echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1372 0ff8d236 2021-09-28 stsp >> $testroot/stdout.expected
1373 088449d3 2021-09-26 stsp echo $merge_commit >> $testroot/stdout.expected
1375 088449d3 2021-09-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1377 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1378 088449d3 2021-09-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
1379 088449d3 2021-09-26 stsp test_done "$testroot" "$ret"
1383 088449d3 2021-09-26 stsp (cd $testroot/wt && got status > $testroot/stdout)
1385 088449d3 2021-09-26 stsp echo -n > $testroot/stdout.expected
1386 088449d3 2021-09-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1388 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1389 088449d3 2021-09-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
1390 088449d3 2021-09-26 stsp test_done "$testroot" "$ret"
1394 088449d3 2021-09-26 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1395 088449d3 2021-09-26 stsp echo "commit $merge_commit (master)" > $testroot/stdout.expected
1396 088449d3 2021-09-26 stsp echo "commit $master_commit" >> $testroot/stdout.expected
1397 088449d3 2021-09-26 stsp echo "commit $commit0" >> $testroot/stdout.expected
1398 088449d3 2021-09-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1400 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1401 088449d3 2021-09-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
1402 088449d3 2021-09-26 stsp test_done "$testroot" "$ret"
1406 088449d3 2021-09-26 stsp (cd $testroot/wt && got update > $testroot/stdout)
1408 088449d3 2021-09-26 stsp echo 'Already up-to-date' > $testroot/stdout.expected
1409 088449d3 2021-09-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1411 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1412 088449d3 2021-09-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
1413 088449d3 2021-09-26 stsp test_done "$testroot" "$ret"
1417 088449d3 2021-09-26 stsp # We should have created a merge commit with two parents.
1418 088449d3 2021-09-26 stsp (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
1419 088449d3 2021-09-26 stsp echo "parent 1: $master_commit" > $testroot/stdout.expected
1420 088449d3 2021-09-26 stsp echo "parent 2: $branch_commit0" >> $testroot/stdout.expected
1421 088449d3 2021-09-26 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1423 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
1424 088449d3 2021-09-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
1426 088449d3 2021-09-26 stsp test_done "$testroot" "$ret"
1429 b2b3fce1 2022-10-29 op test_merge_umask() {
1430 b2b3fce1 2022-10-29 op local testroot=`test_init merge_umask`
1432 b2b3fce1 2022-10-29 op (cd $testroot/repo && git checkout -q -b newbranch)
1433 b2b3fce1 2022-10-29 op echo "modified alpha on branch" >$testroot/repo/alpha
1434 b2b3fce1 2022-10-29 op git_commit "$testroot/repo" -m "committing alpha on newbranch"
1435 b2b3fce1 2022-10-29 op echo "modified delta on branch" >$testroot/repo/gamma/delta
1436 b2b3fce1 2022-10-29 op git_commit "$testroot/repo" -m "committing delta on newbranch"
1438 b2b3fce1 2022-10-29 op # diverge from newbranch
1439 b2b3fce1 2022-10-29 op (cd "$testroot/repo" && git checkout -q master)
1440 b2b3fce1 2022-10-29 op echo "modified beta on master" >$testroot/repo/beta
1441 b2b3fce1 2022-10-29 op git_commit "$testroot/repo" -m "committing zeto no master"
1443 b2b3fce1 2022-10-29 op got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1445 b2b3fce1 2022-10-29 op # using a subshell to avoid clobbering global umask
1446 b2b3fce1 2022-10-29 op (umask 077 && cd "$testroot/wt" && got merge newbranch) >/dev/null
1448 b2b3fce1 2022-10-29 op for f in alpha gamma/delta; do
1449 b2b3fce1 2022-10-29 op ls -l "$testroot/wt/$f" | grep -q ^-rw-------
1450 b2b3fce1 2022-10-29 op if [ $? -ne 0 ]; then
1451 b2b3fce1 2022-10-29 op echo "$f is not 0600 after merge" >&2
1452 b2b3fce1 2022-10-29 op ls -l "$testroot/wt/$f" >&2
1453 b2b3fce1 2022-10-29 op test_done "$testroot" 1
1457 b2b3fce1 2022-10-29 op test_done "$testroot" 0
1460 d51d11be 2023-02-21 op test_merge_gitconfig_author() {
1461 d51d11be 2023-02-21 op local testroot=`test_init merge_gitconfig_author`
1463 d51d11be 2023-02-21 op (cd $testroot/repo && git config user.name 'Flan Luck')
1464 d51d11be 2023-02-21 op (cd $testroot/repo && git config user.email 'flan_luck@openbsd.org')
1466 d51d11be 2023-02-21 op (cd $testroot/repo && git checkout -q -b newbranch)
1467 d51d11be 2023-02-21 op echo "modified alpha on branch" >$testroot/repo/alpha
1468 d51d11be 2023-02-21 op git_commit "$testroot/repo" -m "committing alpha on newbranch"
1469 d51d11be 2023-02-21 op echo "modified delta on branch" >$testroot/repo/gamma/delta
1470 d51d11be 2023-02-21 op git_commit "$testroot/repo" -m "committing delta on newbranch"
1472 d51d11be 2023-02-21 op # diverge from newbranch
1473 d51d11be 2023-02-21 op (cd "$testroot/repo" && git checkout -q master)
1474 d51d11be 2023-02-21 op echo "modified beta on master" >$testroot/repo/beta
1475 d51d11be 2023-02-21 op git_commit "$testroot/repo" -m "committing zeto no master"
1477 d51d11be 2023-02-21 op got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1479 d51d11be 2023-02-21 op # unset in a subshell to avoid affecting our environment
1480 d51d11be 2023-02-21 op (unset GOT_IGNORE_GITCONFIG && cd $testroot/wt && \
1481 d51d11be 2023-02-21 op got merge newbranch > /dev/null)
1483 d51d11be 2023-02-21 op (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
1485 d51d11be 2023-02-21 op if [ $ret -ne 0 ]; then
1486 d51d11be 2023-02-21 op test_done "$testroot" "$ret"
1490 d51d11be 2023-02-21 op echo "from: Flan Luck <flan_luck@openbsd.org>" \
1491 d51d11be 2023-02-21 op > $testroot/stdout.expected
1492 d51d11be 2023-02-21 op cmp -s $testroot/stdout.expected $testroot/stdout
1494 d51d11be 2023-02-21 op if [ $ret -ne 0 ]; then
1495 d51d11be 2023-02-21 op diff -u $testroot/stdout.expected $testroot/stdout
1497 d51d11be 2023-02-21 op test_done "$testroot" "$ret"
1500 f259c4c1 2021-09-24 stsp test_parseargs "$@"
1501 f259c4c1 2021-09-24 stsp run_test test_merge_basic
1502 f259c4c1 2021-09-24 stsp run_test test_merge_continue
1503 f259c4c1 2021-09-24 stsp run_test test_merge_abort
1504 f259c4c1 2021-09-24 stsp run_test test_merge_in_progress
1505 f259c4c1 2021-09-24 stsp run_test test_merge_path_prefix
1506 f259c4c1 2021-09-24 stsp run_test test_merge_missing_file
1507 a6a8f8bb 2021-09-24 stsp run_test test_merge_no_op
1508 4e91ef15 2021-09-26 stsp run_test test_merge_imported_branch
1509 088449d3 2021-09-26 stsp run_test test_merge_interrupt
1510 b2b3fce1 2022-10-29 op run_test test_merge_umask
1511 d51d11be 2023-02-21 op run_test test_merge_gitconfig_author