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 d1e03b8c 2023-10-08 thomas git -C $testroot/repo 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 d1e03b8c 2023-10-08 thomas git -C $testroot/repo 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 d1e03b8c 2023-10-08 thomas git -C $testroot/repo 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 d1e03b8c 2023-10-08 thomas (cd $testroot/repo && ln -s alpha symlink)
40 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add symlink
41 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding symlink on newbranch"
42 10604dce 2021-09-24 thomas local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
43 ace90326 2021-09-27 thomas (cd $testroot/repo && ln -sf .got/bar dotgotbar.link)
44 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add dotgotbar.link
45 ace90326 2021-09-27 thomas git_commit $testroot/repo -m "adding a bad symlink on newbranch"
46 ace90326 2021-09-27 thomas local branch_commit5=`git_show_branch_head $testroot/repo newbranch`
48 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
50 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
51 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
52 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
56 2b72f32d 2023-06-22 thomas # create a divergent commit
57 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q master
58 10604dce 2021-09-24 thomas echo "modified zeta on master" > $testroot/repo/epsilon/zeta
59 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to zeta on master"
60 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
62 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
63 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
64 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
66 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
67 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
68 0b477035 2023-06-22 thomas test_done "$testroot" "1"
71 10604dce 2021-09-24 thomas echo -n "got: work tree must be updated before it can be used " \
72 10604dce 2021-09-24 thomas > $testroot/stderr.expected
73 10604dce 2021-09-24 thomas echo "to merge a branch" >> $testroot/stderr.expected
74 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
76 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
77 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
78 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
82 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
84 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
85 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
86 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
90 b6b86fd1 2022-08-30 thomas # must not use a mixed-commit work tree with 'got merge'
91 10604dce 2021-09-24 thomas (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
93 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
94 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
95 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
98 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
99 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
101 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
102 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
103 0b477035 2023-06-22 thomas test_done "$testroot" "1"
106 10604dce 2021-09-24 thomas echo -n "got: work tree contains files from multiple base commits; " \
107 10604dce 2021-09-24 thomas > $testroot/stderr.expected
108 10604dce 2021-09-24 thomas echo "the entire work tree must be updated first" \
109 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
110 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
112 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
113 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
114 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
118 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
120 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
121 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
122 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
126 b6b86fd1 2022-08-30 thomas # must not have staged files with 'got merge'
127 10604dce 2021-09-24 thomas echo "modified file alpha" > $testroot/wt/alpha
128 10604dce 2021-09-24 thomas (cd $testroot/wt && got stage alpha > /dev/null)
130 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
131 10604dce 2021-09-24 thomas echo "got stage failed unexpectedly" >&2
132 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
135 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
136 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
138 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
139 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
140 0b477035 2023-06-22 thomas test_done "$testroot" "1"
143 10604dce 2021-09-24 thomas echo "got: alpha: file is staged" > $testroot/stderr.expected
144 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
146 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
147 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
148 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
151 10604dce 2021-09-24 thomas (cd $testroot/wt && got unstage alpha > /dev/null)
153 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
154 10604dce 2021-09-24 thomas echo "got unstage failed unexpectedly" >&2
155 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
159 b6b86fd1 2022-08-30 thomas # must not have local changes with 'got merge'
160 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
161 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
163 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
164 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
165 0b477035 2023-06-22 thomas test_done "$testroot" "1"
168 10604dce 2021-09-24 thomas echo -n "got: work tree contains local changes; " \
169 10604dce 2021-09-24 thomas > $testroot/stderr.expected
170 10604dce 2021-09-24 thomas echo "these changes must be committed or reverted first" \
171 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
172 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
174 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
175 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
176 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
180 10604dce 2021-09-24 thomas (cd $testroot/wt && got revert alpha > /dev/null)
182 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
183 10604dce 2021-09-24 thomas echo "got revert failed unexpectedly" >&2
184 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
188 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch > $testroot/stdout)
190 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
191 10604dce 2021-09-24 thomas echo "got merge failed unexpectedly" >&2
192 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
196 10604dce 2021-09-24 thomas local merge_commit=`git_show_head $testroot/repo`
198 10604dce 2021-09-24 thomas echo "G alpha" >> $testroot/stdout.expected
199 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
200 ace90326 2021-09-27 thomas echo "A dotgotbar.link" >> $testroot/stdout.expected
201 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
202 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
203 10604dce 2021-09-24 thomas echo "A symlink" >> $testroot/stdout.expected
204 10604dce 2021-09-24 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
205 10604dce 2021-09-24 thomas >> $testroot/stdout.expected
206 10604dce 2021-09-24 thomas echo $merge_commit >> $testroot/stdout.expected
208 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
210 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
211 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
212 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
216 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/content.expected
217 10604dce 2021-09-24 thomas cat $testroot/wt/gamma/delta > $testroot/content
218 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
220 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
221 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
222 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
226 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/content.expected
227 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
228 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
230 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
231 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
232 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
236 10604dce 2021-09-24 thomas if [ -e $testroot/wt/beta ]; then
237 10604dce 2021-09-24 thomas echo "removed file beta still exists on disk" >&2
238 10604dce 2021-09-24 thomas test_done "$testroot" "1"
242 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/content.expected
243 10604dce 2021-09-24 thomas cat $testroot/wt/epsilon/new > $testroot/content
244 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
246 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
247 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
248 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
252 ace90326 2021-09-27 thomas if [ ! -h $testroot/wt/dotgotbar.link ]; then
253 ace90326 2021-09-27 thomas echo "dotgotbar.link is not a symlink"
254 ace90326 2021-09-27 thomas test_done "$testroot" "1"
258 10604dce 2021-09-24 thomas readlink $testroot/wt/symlink > $testroot/stdout
259 10604dce 2021-09-24 thomas echo "alpha" > $testroot/stdout.expected
260 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
262 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
263 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
264 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
268 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
270 10604dce 2021-09-24 thomas echo -n > $testroot/stdout.expected
271 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
273 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
274 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
275 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
279 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
280 10604dce 2021-09-24 thomas echo "commit $merge_commit (master)" > $testroot/stdout.expected
281 10604dce 2021-09-24 thomas echo "commit $master_commit" >> $testroot/stdout.expected
282 10604dce 2021-09-24 thomas echo "commit $commit0" >> $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 update > $testroot/stdout)
293 ace90326 2021-09-27 thomas echo 'U dotgotbar.link' > $testroot/stdout.expected
294 ace90326 2021-09-27 thomas echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
295 ace90326 2021-09-27 thomas git_show_head $testroot/repo >> $testroot/stdout.expected
296 ace90326 2021-09-27 thomas echo >> $testroot/stdout.expected
297 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
299 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
300 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
301 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
305 ace90326 2021-09-27 thomas # update has changed the bad symlink into a regular file
306 ace90326 2021-09-27 thomas if [ -h $testroot/wt/dotgotbar.link ]; then
307 ace90326 2021-09-27 thomas echo "dotgotbar.link is a symlink"
308 ace90326 2021-09-27 thomas test_done "$testroot" "1"
312 10604dce 2021-09-24 thomas # We should have created a merge commit with two parents.
313 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
314 10604dce 2021-09-24 thomas echo "parent 1: $master_commit" > $testroot/stdout.expected
315 ace90326 2021-09-27 thomas echo "parent 2: $branch_commit5" >> $testroot/stdout.expected
316 ace90326 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
318 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
319 ace90326 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
320 ace90326 2021-09-27 thomas test_done "$testroot" "$ret"
324 ace90326 2021-09-27 thomas got tree -r $testroot/repo -c $merge_commit -R > $testroot/stdout
326 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
327 ace90326 2021-09-27 thomas echo "got tree failed unexpectedly" >&2
328 ace90326 2021-09-27 thomas test_done "$testroot" "$ret"
332 ace90326 2021-09-27 thomas # bad symlink dotgotbar.link appears as a symlink in the merge commit:
333 ace90326 2021-09-27 thomas cat > $testroot/stdout.expected <<EOF
335 ace90326 2021-09-27 thomas dotgotbar.link@ -> .got/bar
337 ace90326 2021-09-27 thomas epsilon/new
338 ace90326 2021-09-27 thomas epsilon/zeta
340 ace90326 2021-09-27 thomas gamma/delta
341 ace90326 2021-09-27 thomas symlink@ -> alpha
343 2b72f32d 2023-06-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
345 2b72f32d 2023-06-22 thomas if [ $ret -ne 0 ]; then
346 2b72f32d 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
348 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
351 2b72f32d 2023-06-22 thomas test_merge_forward() {
352 2b72f32d 2023-06-22 thomas local testroot=`test_init merge_forward`
353 2b72f32d 2023-06-22 thomas local commit0=`git_show_head $testroot/repo`
355 2b72f32d 2023-06-22 thomas # Create a commit before branching, which will be used to help test
356 2b72f32d 2023-06-22 thomas # preconditions for "got merge".
357 2b72f32d 2023-06-22 thomas echo "modified alpha" > $testroot/repo/alpha
358 2b72f32d 2023-06-22 thomas git_commit $testroot/repo -m "common commit"
359 2b72f32d 2023-06-22 thomas local commit1=`git_show_head $testroot/repo`
361 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
362 2b72f32d 2023-06-22 thomas echo "modified beta on branch" > $testroot/repo/beta
363 2b72f32d 2023-06-22 thomas git_commit $testroot/repo -m "committing to beta on newbranch"
364 2b72f32d 2023-06-22 thomas local commit2=`git_show_head $testroot/repo`
366 2b72f32d 2023-06-22 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
368 2b72f32d 2023-06-22 thomas if [ $ret -ne 0 ]; then
369 2b72f32d 2023-06-22 thomas echo "got checkout failed unexpectedly" >&2
370 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
374 2b72f32d 2023-06-22 thomas # must not use a mixed-commit work tree with 'got merge'
375 2b72f32d 2023-06-22 thomas (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
377 2b72f32d 2023-06-22 thomas if [ $ret -ne 0 ]; then
378 2b72f32d 2023-06-22 thomas echo "got update failed unexpectedly" >&2
379 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
382 2b72f32d 2023-06-22 thomas (cd $testroot/wt && got merge newbranch \
383 2b72f32d 2023-06-22 thomas > $testroot/stdout 2> $testroot/stderr)
385 2b72f32d 2023-06-22 thomas if [ $ret -eq 0 ]; then
386 2b72f32d 2023-06-22 thomas echo "got merge succeeded unexpectedly" >&2
387 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
390 2b72f32d 2023-06-22 thomas echo -n "got: work tree contains files from multiple base commits; " \
391 2b72f32d 2023-06-22 thomas > $testroot/stderr.expected
392 2b72f32d 2023-06-22 thomas echo "the entire work tree must be updated first" \
393 2b72f32d 2023-06-22 thomas >> $testroot/stderr.expected
394 2b72f32d 2023-06-22 thomas cmp -s $testroot/stderr.expected $testroot/stderr
396 2b72f32d 2023-06-22 thomas if [ $ret -ne 0 ]; then
397 2b72f32d 2023-06-22 thomas diff -u $testroot/stderr.expected $testroot/stderr
398 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
402 2b72f32d 2023-06-22 thomas (cd $testroot/wt && got update > /dev/null)
404 2b72f32d 2023-06-22 thomas if [ $ret -ne 0 ]; then
405 2b72f32d 2023-06-22 thomas echo "got update failed unexpectedly" >&2
406 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
410 2b72f32d 2023-06-22 thomas # 'got merge -n' refuses to fast-forward
411 2b72f32d 2023-06-22 thomas (cd $testroot/wt && got merge -n newbranch \
412 2b72f32d 2023-06-22 thomas > $testroot/stdout 2> $testroot/stderr)
414 2b72f32d 2023-06-22 thomas if [ $ret -eq 0 ]; then
415 2b72f32d 2023-06-22 thomas echo "got merge succeeded unexpectedly" >&2
416 2b72f32d 2023-06-22 thomas test_done "$testroot" "1"
420 0619bbce 2023-06-22 thomas echo -n "got: there are no changes to merge since " \
421 0619bbce 2023-06-22 thomas > $testroot/stderr.expected
422 0619bbce 2023-06-22 thomas echo -n "refs/heads/newbranch is already based on " \
423 2b72f32d 2023-06-22 thomas >> $testroot/stderr.expected
424 0619bbce 2023-06-22 thomas echo -n "refs/heads/master; merge cannot be interrupted " \
425 0619bbce 2023-06-22 thomas >> $testroot/stderr.expected
426 0619bbce 2023-06-22 thomas echo "for amending; -n: option cannot be used" \
427 0619bbce 2023-06-22 thomas >> $testroot/stderr.expected
429 2b72f32d 2023-06-22 thomas cmp -s $testroot/stderr.expected $testroot/stderr
431 2b72f32d 2023-06-22 thomas if [ $ret -ne 0 ]; then
432 2b72f32d 2023-06-22 thomas diff -u $testroot/stderr.expected $testroot/stderr
433 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
437 2b72f32d 2023-06-22 thomas (cd $testroot/wt && got merge newbranch \
438 2b72f32d 2023-06-22 thomas > $testroot/stdout 2> $testroot/stderr)
440 2b72f32d 2023-06-22 thomas if [ $ret -ne 0 ]; then
441 2b72f32d 2023-06-22 thomas echo "got merge failed unexpectedly" >&2
442 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
446 2b72f32d 2023-06-22 thomas echo "Forwarding refs/heads/master to refs/heads/newbranch" \
447 2b72f32d 2023-06-22 thomas > $testroot/stdout.expected
448 2b72f32d 2023-06-22 thomas echo "U beta" >> $testroot/stdout.expected
449 2b72f32d 2023-06-22 thomas echo "Updated to commit $commit2" \
450 2b72f32d 2023-06-22 thomas >> $testroot/stdout.expected
451 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
453 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
454 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
455 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
459 2b72f32d 2023-06-22 thomas (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
460 2b72f32d 2023-06-22 thomas echo -n "commit $commit2 " > $testroot/stdout.expected
461 2b72f32d 2023-06-22 thomas echo "(master, newbranch)" >> $testroot/stdout.expected
462 2b72f32d 2023-06-22 thomas echo "commit $commit1" >> $testroot/stdout.expected
463 2b72f32d 2023-06-22 thomas echo "commit $commit0" >> $testroot/stdout.expected
464 31009ade 2023-07-05 thomas cmp -s $testroot/stdout.expected $testroot/stdout
466 31009ade 2023-07-05 thomas if [ $ret -ne 0 ]; then
467 31009ade 2023-07-05 thomas diff -u $testroot/stdout.expected $testroot/stdout
468 31009ade 2023-07-05 thomas test_done "$testroot" "$ret"
471 31009ade 2023-07-05 thomas test_done "$testroot" "$ret"
474 31009ade 2023-07-05 thomas test_merge_forward_commit() {
475 31009ade 2023-07-05 thomas local testroot=`test_init merge_forward_commit`
476 31009ade 2023-07-05 thomas local commit0=`git_show_head $testroot/repo`
478 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
479 31009ade 2023-07-05 thomas echo "modified alpha on branch" > $testroot/repo/alpha
480 31009ade 2023-07-05 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
481 31009ade 2023-07-05 thomas local commit1=`git_show_head $testroot/repo`
483 31009ade 2023-07-05 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
485 31009ade 2023-07-05 thomas if [ $ret -ne 0 ]; then
486 31009ade 2023-07-05 thomas echo "got checkout failed unexpectedly" >&2
487 31009ade 2023-07-05 thomas test_done "$testroot" "$ret"
491 31009ade 2023-07-05 thomas (cd $testroot/wt && got merge -M newbranch > $testroot/stdout)
493 31009ade 2023-07-05 thomas if [ $ret -ne 0 ]; then
494 31009ade 2023-07-05 thomas echo "got merge failed unexpectedly" >&2
495 31009ade 2023-07-05 thomas test_done "$testroot" "$ret"
499 31009ade 2023-07-05 thomas local merge_commit=`git_show_branch_head $testroot/repo master`
501 31009ade 2023-07-05 thomas echo "G alpha" >> $testroot/stdout.expected
502 31009ade 2023-07-05 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
503 31009ade 2023-07-05 thomas >> $testroot/stdout.expected
504 31009ade 2023-07-05 thomas echo $merge_commit >> $testroot/stdout.expected
506 31009ade 2023-07-05 thomas cmp -s $testroot/stdout.expected $testroot/stdout
508 31009ade 2023-07-05 thomas if [ $ret -ne 0 ]; then
509 31009ade 2023-07-05 thomas diff -u $testroot/stdout.expected $testroot/stdout
510 31009ade 2023-07-05 thomas test_done "$testroot" "$ret"
514 31009ade 2023-07-05 thomas # We should have created a merge commit with two parents.
515 31009ade 2023-07-05 thomas (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
516 31009ade 2023-07-05 thomas echo "parent 1: $commit0" > $testroot/stdout.expected
517 31009ade 2023-07-05 thomas echo "parent 2: $commit1" >> $testroot/stdout.expected
518 31009ade 2023-07-05 thomas cmp -s $testroot/stdout.expected $testroot/stdout
520 31009ade 2023-07-05 thomas if [ $ret -ne 0 ]; then
521 31009ade 2023-07-05 thomas diff -u $testroot/stdout.expected $testroot/stdout
522 31009ade 2023-07-05 thomas test_done "$testroot" "$ret"
526 31009ade 2023-07-05 thomas test_done "$testroot" "$ret"
529 31009ade 2023-07-05 thomas test_merge_forward_interrupt() {
530 31009ade 2023-07-05 thomas # Test -M and -n options together.
531 31009ade 2023-07-05 thomas local testroot=`test_init merge_forward_commit`
532 31009ade 2023-07-05 thomas local commit0=`git_show_head $testroot/repo`
534 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
535 31009ade 2023-07-05 thomas echo "modified alpha on branch" > $testroot/repo/alpha
536 31009ade 2023-07-05 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
537 31009ade 2023-07-05 thomas local commit1=`git_show_head $testroot/repo`
539 31009ade 2023-07-05 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
541 31009ade 2023-07-05 thomas if [ $ret -ne 0 ]; then
542 31009ade 2023-07-05 thomas echo "got checkout failed unexpectedly" >&2
543 31009ade 2023-07-05 thomas test_done "$testroot" "$ret"
547 31009ade 2023-07-05 thomas (cd $testroot/wt && got merge -M -n newbranch > $testroot/stdout)
549 31009ade 2023-07-05 thomas if [ $ret -ne 0 ]; then
550 31009ade 2023-07-05 thomas echo "got merge failed unexpectedly" >&2
551 31009ade 2023-07-05 thomas test_done "$testroot" "$ret"
555 31009ade 2023-07-05 thomas echo "G alpha" > $testroot/stdout.expected
556 31009ade 2023-07-05 thomas echo "Merge of refs/heads/newbranch interrupted on request" \
557 31009ade 2023-07-05 thomas >> $testroot/stdout.expected
558 31009ade 2023-07-05 thomas cmp -s $testroot/stdout.expected $testroot/stdout
560 31009ade 2023-07-05 thomas if [ $ret -ne 0 ]; then
561 31009ade 2023-07-05 thomas diff -u $testroot/stdout.expected $testroot/stdout
562 31009ade 2023-07-05 thomas test_done "$testroot" "$ret"
566 31009ade 2023-07-05 thomas # Continue the merge.
567 31009ade 2023-07-05 thomas (cd $testroot/wt && got merge -c > $testroot/stdout)
569 31009ade 2023-07-05 thomas if [ $ret -ne 0 ]; then
570 31009ade 2023-07-05 thomas echo "got merge failed unexpectedly" >&2
571 31009ade 2023-07-05 thomas test_done "$testroot" "$ret"
575 31009ade 2023-07-05 thomas local merge_commit=`git_show_branch_head $testroot/repo master`
577 31009ade 2023-07-05 thomas echo "M alpha" > $testroot/stdout.expected
578 31009ade 2023-07-05 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
579 31009ade 2023-07-05 thomas >> $testroot/stdout.expected
580 31009ade 2023-07-05 thomas echo $merge_commit >> $testroot/stdout.expected
582 2b72f32d 2023-06-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
584 2b72f32d 2023-06-22 thomas if [ $ret -ne 0 ]; then
585 2b72f32d 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
586 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
590 31009ade 2023-07-05 thomas # We should have created a merge commit with two parents.
591 31009ade 2023-07-05 thomas (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
592 31009ade 2023-07-05 thomas echo "parent 1: $commit0" > $testroot/stdout.expected
593 31009ade 2023-07-05 thomas echo "parent 2: $commit1" >> $testroot/stdout.expected
594 31009ade 2023-07-05 thomas cmp -s $testroot/stdout.expected $testroot/stdout
596 31009ade 2023-07-05 thomas if [ $ret -ne 0 ]; then
597 31009ade 2023-07-05 thomas diff -u $testroot/stdout.expected $testroot/stdout
599 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
602 2b72f32d 2023-06-22 thomas test_merge_backward() {
603 2b72f32d 2023-06-22 thomas local testroot=`test_init merge_backward`
604 2b72f32d 2023-06-22 thomas local commit0=`git_show_head $testroot/repo`
606 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
607 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q master
608 2b72f32d 2023-06-22 thomas echo "modified alpha on master" > $testroot/repo/alpha
609 2b72f32d 2023-06-22 thomas git_commit $testroot/repo -m "committing to alpha on master"
611 2b72f32d 2023-06-22 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
613 2b72f32d 2023-06-22 thomas if [ $ret -ne 0 ]; then
614 2b72f32d 2023-06-22 thomas echo "got checkout failed unexpectedly" >&2
615 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
619 2b72f32d 2023-06-22 thomas (cd $testroot/wt && got merge newbranch \
620 2b72f32d 2023-06-22 thomas > $testroot/stdout 2> $testroot/stderr)
622 2b72f32d 2023-06-22 thomas if [ $ret -ne 0 ]; then
623 2b72f32d 2023-06-22 thomas echo "got merge failed unexpectedly" >&2
624 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
627 2b72f32d 2023-06-22 thomas echo "Already up-to-date" > $testroot/stdout.expected
628 2b72f32d 2023-06-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
630 2b72f32d 2023-06-22 thomas if [ $ret -ne 0 ]; then
631 2b72f32d 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
632 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
635 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
638 10604dce 2021-09-24 thomas test_merge_continue() {
639 10604dce 2021-09-24 thomas local testroot=`test_init merge_continue`
640 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
641 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
643 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
644 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
645 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to delta on newbranch"
646 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
648 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
649 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
650 10604dce 2021-09-24 thomas local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
651 d1e03b8c 2023-10-08 thomas git -C $testroot/repo rm -q beta
652 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "removing beta on newbranch"
653 10604dce 2021-09-24 thomas local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
654 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/repo/epsilon/new
655 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add epsilon/new
656 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding new file on newbranch"
657 10604dce 2021-09-24 thomas local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
659 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
661 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
662 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
663 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
667 10604dce 2021-09-24 thomas # create a conflicting commit
668 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q master
669 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
670 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
671 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
673 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
674 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
676 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
677 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
678 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
682 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
683 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
685 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
686 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
687 10604dce 2021-09-24 thomas test_done "$testroot" "1"
691 10604dce 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
692 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
693 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
694 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
695 10604dce 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
696 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
698 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
699 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
700 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
704 10604dce 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
705 10604dce 2021-09-24 thomas > $testroot/stderr.expected
706 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
708 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
709 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
710 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
714 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
716 cd634f2d 2024-03-30 thomas cat > $testroot/stdout.expected <<EOF
719 cd634f2d 2024-03-30 thomas A epsilon/new
720 cd634f2d 2024-03-30 thomas M gamma/delta
721 cd634f2d 2024-03-30 thomas Work tree is merging refs/heads/newbranch into refs/heads/master
723 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
725 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
726 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
727 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
731 10604dce 2021-09-24 thomas echo '<<<<<<<' > $testroot/content.expected
732 10604dce 2021-09-24 thomas echo "modified alpha on master" >> $testroot/content.expected
733 10604dce 2021-09-24 thomas echo "||||||| 3-way merge base: commit $commit0" \
734 10604dce 2021-09-24 thomas >> $testroot/content.expected
735 10604dce 2021-09-24 thomas echo "alpha" >> $testroot/content.expected
736 10604dce 2021-09-24 thomas echo "=======" >> $testroot/content.expected
737 10604dce 2021-09-24 thomas echo "modified alpha on branch" >> $testroot/content.expected
738 10604dce 2021-09-24 thomas echo ">>>>>>> merged change: commit $branch_commit3" \
739 10604dce 2021-09-24 thomas >> $testroot/content.expected
740 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
741 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
743 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
744 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
745 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
749 10604dce 2021-09-24 thomas # resolve the conflict
750 10604dce 2021-09-24 thomas echo "modified alpha by both branches" > $testroot/wt/alpha
752 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge -c > $testroot/stdout)
754 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
755 10604dce 2021-09-24 thomas echo "got merge failed unexpectedly" >&2
756 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
760 10604dce 2021-09-24 thomas local merge_commit=`git_show_head $testroot/repo`
762 ae1e948a 2021-09-28 thomas echo "M alpha" > $testroot/stdout.expected
763 ae1e948a 2021-09-28 thomas echo "D beta" >> $testroot/stdout.expected
764 ae1e948a 2021-09-28 thomas echo "A epsilon/new" >> $testroot/stdout.expected
765 ae1e948a 2021-09-28 thomas echo "M gamma/delta" >> $testroot/stdout.expected
766 10604dce 2021-09-24 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
767 ae1e948a 2021-09-28 thomas >> $testroot/stdout.expected
768 10604dce 2021-09-24 thomas echo $merge_commit >> $testroot/stdout.expected
770 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
772 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
773 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
774 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
778 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/content.expected
779 10604dce 2021-09-24 thomas cat $testroot/wt/gamma/delta > $testroot/content
780 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
782 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
783 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
784 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
788 10604dce 2021-09-24 thomas echo "modified alpha by both branches" > $testroot/content.expected
789 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
790 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
792 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
793 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
794 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
798 10604dce 2021-09-24 thomas if [ -e $testroot/wt/beta ]; then
799 10604dce 2021-09-24 thomas echo "removed file beta still exists on disk" >&2
800 10604dce 2021-09-24 thomas test_done "$testroot" "1"
804 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/content.expected
805 10604dce 2021-09-24 thomas cat $testroot/wt/epsilon/new > $testroot/content
806 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
808 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
809 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
810 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
814 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
816 10604dce 2021-09-24 thomas echo -n > $testroot/stdout.expected
817 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
819 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
820 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
821 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
825 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
826 10604dce 2021-09-24 thomas echo "commit $merge_commit (master)" > $testroot/stdout.expected
827 10604dce 2021-09-24 thomas echo "commit $master_commit" >> $testroot/stdout.expected
828 10604dce 2021-09-24 thomas echo "commit $commit0" >> $testroot/stdout.expected
829 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
831 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
832 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
833 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
837 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > $testroot/stdout)
839 10604dce 2021-09-24 thomas echo 'Already up-to-date' > $testroot/stdout.expected
840 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
842 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
843 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
844 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
848 10604dce 2021-09-24 thomas # We should have created a merge commit with two parents.
849 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
850 10604dce 2021-09-24 thomas echo "parent 1: $master_commit" > $testroot/stdout.expected
851 10604dce 2021-09-24 thomas echo "parent 2: $branch_commit3" >> $testroot/stdout.expected
852 fe3f264b 2023-06-08 thomas cmp -s $testroot/stdout.expected $testroot/stdout
854 fe3f264b 2023-06-08 thomas if [ $ret -ne 0 ]; then
855 fe3f264b 2023-06-08 thomas diff -u $testroot/stdout.expected $testroot/stdout
857 fe3f264b 2023-06-08 thomas test_done "$testroot" "$ret"
860 fe3f264b 2023-06-08 thomas test_merge_continue_new_commit() {
861 fe3f264b 2023-06-08 thomas # "got merge -c" should refuse to run if the current branch tip has
862 fe3f264b 2023-06-08 thomas # changed since the merge was started, to avoid clobbering the changes.
863 fe3f264b 2023-06-08 thomas local testroot=`test_init merge_continue_new_commit`
865 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
866 fe3f264b 2023-06-08 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
867 fe3f264b 2023-06-08 thomas git_commit $testroot/repo -m "committing to delta on newbranch"
869 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q master
870 fe3f264b 2023-06-08 thomas echo "modified alpha on master" > $testroot/repo/alpha
871 fe3f264b 2023-06-08 thomas git_commit $testroot/repo -m "committing to alpha on master"
873 fe3f264b 2023-06-08 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
875 fe3f264b 2023-06-08 thomas if [ $ret -ne 0 ]; then
876 fe3f264b 2023-06-08 thomas echo "got checkout failed unexpectedly" >&2
877 fe3f264b 2023-06-08 thomas test_done "$testroot" "$ret"
881 fe3f264b 2023-06-08 thomas (cd $testroot/wt && got merge -n newbranch >/dev/null)
883 fe3f264b 2023-06-08 thomas if [ $ret -ne 0 ]; then
884 fe3f264b 2023-06-08 thomas echo "got merge failed unexpectedly" >&2
885 fe3f264b 2023-06-08 thomas test_done "$testroot" "$ret"
889 fe3f264b 2023-06-08 thomas echo "modified alpha again on master" > $testroot/repo/alpha
890 fe3f264b 2023-06-08 thomas git_commit $testroot/repo -m "committing to alpha on master again"
892 fe3f264b 2023-06-08 thomas (cd $testroot/wt && got merge -c > $testroot/stdout 2> $testroot/stderr)
894 fe3f264b 2023-06-08 thomas if [ $ret -eq 0 ]; then
895 fe3f264b 2023-06-08 thomas echo "got merge succeeded unexpectedly" >&2
896 fe3f264b 2023-06-08 thomas test_done "$testroot" "1"
900 fe3f264b 2023-06-08 thomas echo -n > $testroot/stdout.expected
901 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
903 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
904 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
905 fe3f264b 2023-06-08 thomas test_done "$testroot" "$ret"
909 fe3f264b 2023-06-08 thomas echo -n "got: merging cannot proceed because the work tree is no " \
910 fe3f264b 2023-06-08 thomas > $testroot/stderr.expected
911 fe3f264b 2023-06-08 thomas echo "longer up-to-date; merge must be aborted and retried" \
912 fe3f264b 2023-06-08 thomas >> $testroot/stderr.expected
913 fe3f264b 2023-06-08 thomas cmp -s $testroot/stderr.expected $testroot/stderr
915 fe3f264b 2023-06-08 thomas if [ $ret -ne 0 ]; then
916 fe3f264b 2023-06-08 thomas diff -u $testroot/stderr.expected $testroot/stderr
918 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
921 10604dce 2021-09-24 thomas test_merge_abort() {
922 10604dce 2021-09-24 thomas local testroot=`test_init merge_abort`
923 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
924 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
926 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
927 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
928 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to delta on newbranch"
929 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
931 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
932 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
933 10604dce 2021-09-24 thomas local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
934 d1e03b8c 2023-10-08 thomas git -C $testroot/repo rm -q beta
935 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "removing beta on newbranch"
936 10604dce 2021-09-24 thomas local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
937 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/repo/epsilon/new
938 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add epsilon/new
939 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding new file on newbranch"
940 10604dce 2021-09-24 thomas local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
941 d1e03b8c 2023-10-08 thomas (cd $testroot/repo && ln -s alpha symlink)
942 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add symlink
943 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding symlink on newbranch"
944 10604dce 2021-09-24 thomas local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
946 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
948 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
949 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
950 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
954 d52bac28 2021-10-08 thomas # unrelated unversioned file in work tree
955 d52bac28 2021-10-08 thomas touch $testroot/wt/unversioned-file
957 10604dce 2021-09-24 thomas # create a conflicting commit
958 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q master
959 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
960 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
961 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
963 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
964 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
966 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
967 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
968 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
972 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
973 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
975 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
976 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
977 10604dce 2021-09-24 thomas test_done "$testroot" "1"
981 10604dce 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
982 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
983 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
984 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
985 10604dce 2021-09-24 thomas echo "A symlink" >> $testroot/stdout.expected
986 10604dce 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
987 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
989 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
990 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
991 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
995 10604dce 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
996 10604dce 2021-09-24 thomas > $testroot/stderr.expected
997 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
999 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1000 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1001 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1002 10604dce 2021-09-24 thomas return 1
1005 8641a332 2023-04-14 thomas # unrelated added file added during conflict resolution
1006 8641a332 2023-04-14 thomas touch $testroot/wt/added-file
1007 8641a332 2023-04-14 thomas (cd $testroot/wt && got add added-file > /dev/null)
1009 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1011 cd634f2d 2024-03-30 thomas cat > $testroot/stdout.expected <<EOF
1012 cd634f2d 2024-03-30 thomas A added-file
1015 cd634f2d 2024-03-30 thomas A epsilon/new
1016 cd634f2d 2024-03-30 thomas M gamma/delta
1017 cd634f2d 2024-03-30 thomas A symlink
1018 cd634f2d 2024-03-30 thomas ? unversioned-file
1019 cd634f2d 2024-03-30 thomas Work tree is merging refs/heads/newbranch into refs/heads/master
1021 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1023 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1024 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1025 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1026 10604dce 2021-09-24 thomas return 1
1029 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge -a > $testroot/stdout)
1031 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1032 10604dce 2021-09-24 thomas echo "got merge failed unexpectedly" >&2
1033 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1034 10604dce 2021-09-24 thomas return 1
1037 8641a332 2023-04-14 thomas echo "R added-file" > $testroot/stdout.expected
1038 8641a332 2023-04-14 thomas echo "R alpha" >> $testroot/stdout.expected
1039 10604dce 2021-09-24 thomas echo "R beta" >> $testroot/stdout.expected
1040 10604dce 2021-09-24 thomas echo "R epsilon/new" >> $testroot/stdout.expected
1041 10604dce 2021-09-24 thomas echo "R gamma/delta" >> $testroot/stdout.expected
1042 10604dce 2021-09-24 thomas echo "R symlink" >> $testroot/stdout.expected
1043 8641a332 2023-04-14 thomas echo "G added-file" >> $testroot/stdout.expected
1044 10604dce 2021-09-24 thomas echo "Merge of refs/heads/newbranch aborted" \
1045 10604dce 2021-09-24 thomas >> $testroot/stdout.expected
1047 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1049 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1050 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1051 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1052 10604dce 2021-09-24 thomas return 1
1055 10604dce 2021-09-24 thomas echo "delta" > $testroot/content.expected
1056 10604dce 2021-09-24 thomas cat $testroot/wt/gamma/delta > $testroot/content
1057 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
1059 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1060 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
1061 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1062 10604dce 2021-09-24 thomas return 1
1065 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/content.expected
1066 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
1067 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
1069 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1070 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
1071 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1072 10604dce 2021-09-24 thomas return 1
1075 10604dce 2021-09-24 thomas echo "beta" > $testroot/content.expected
1076 10604dce 2021-09-24 thomas cat $testroot/wt/beta > $testroot/content
1077 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
1079 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1080 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
1081 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1082 10604dce 2021-09-24 thomas return 1
1085 10604dce 2021-09-24 thomas if [ -e $testroot/wt/epsilon/new ]; then
1086 10604dce 2021-09-24 thomas echo "reverted file epsilon/new still exists on disk" >&2
1087 10604dce 2021-09-24 thomas test_done "$testroot" "1"
1088 10604dce 2021-09-24 thomas return 1
1091 10604dce 2021-09-24 thomas if [ -e $testroot/wt/symlink ]; then
1092 10604dce 2021-09-24 thomas echo "reverted symlink still exists on disk" >&2
1093 10604dce 2021-09-24 thomas test_done "$testroot" "1"
1094 10604dce 2021-09-24 thomas return 1
1097 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1099 8641a332 2023-04-14 thomas echo "? added-file" > $testroot/stdout.expected
1100 8641a332 2023-04-14 thomas echo "? unversioned-file" >> $testroot/stdout.expected
1101 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1103 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1104 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1105 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1106 10604dce 2021-09-24 thomas return 1
1109 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1110 10604dce 2021-09-24 thomas echo "commit $master_commit (master)" > $testroot/stdout.expected
1111 10604dce 2021-09-24 thomas echo "commit $commit0" >> $testroot/stdout.expected
1112 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1114 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1115 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1116 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1117 10604dce 2021-09-24 thomas return 1
1120 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > $testroot/stdout)
1122 10604dce 2021-09-24 thomas echo 'Already up-to-date' > $testroot/stdout.expected
1123 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1125 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1126 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1128 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1131 10604dce 2021-09-24 thomas test_merge_in_progress() {
1132 10604dce 2021-09-24 thomas local testroot=`test_init merge_in_progress`
1133 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
1134 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1136 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
1137 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
1138 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
1139 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1141 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
1143 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1144 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
1145 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1146 10604dce 2021-09-24 thomas return 1
1149 10604dce 2021-09-24 thomas # create a conflicting commit
1150 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q master
1151 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
1152 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
1153 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
1155 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
1156 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
1158 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1159 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
1160 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1161 10604dce 2021-09-24 thomas return 1
1164 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
1165 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
1167 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
1168 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
1169 10604dce 2021-09-24 thomas test_done "$testroot" "1"
1170 10604dce 2021-09-24 thomas return 1
1173 10604dce 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
1174 10604dce 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1175 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1177 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1178 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1179 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1180 10604dce 2021-09-24 thomas return 1
1183 10604dce 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
1184 10604dce 2021-09-24 thomas > $testroot/stderr.expected
1185 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1187 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1188 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1189 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1190 10604dce 2021-09-24 thomas return 1
1193 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1195 cd634f2d 2024-03-30 thomas cat > $testroot/stdout.expected <<EOF
1197 cd634f2d 2024-03-30 thomas Work tree is merging refs/heads/newbranch into refs/heads/master
1199 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1201 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1202 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1203 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1204 10604dce 2021-09-24 thomas return 1
1207 10604dce 2021-09-24 thomas for cmd in update commit histedit "rebase newbranch" \
1208 d8a7bd7d 2023-06-01 thomas "integrate newbranch" "merge newbranch" "stage alpha"; do
1209 10604dce 2021-09-24 thomas (cd $testroot/wt && got $cmd > $testroot/stdout \
1210 10604dce 2021-09-24 thomas 2> $testroot/stderr)
1212 d8a7bd7d 2023-06-01 thomas if [ $ret -eq 0 ]; then
1213 d8a7bd7d 2023-06-01 thomas echo "got $cmd succeeded unexpectedly" >&2
1214 d8a7bd7d 2023-06-01 thomas test_done "$testroot" "1"
1215 d8a7bd7d 2023-06-01 thomas return 1
1218 10604dce 2021-09-24 thomas echo -n > $testroot/stdout.expected
1219 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1221 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1222 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1223 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1224 10604dce 2021-09-24 thomas return 1
1227 10604dce 2021-09-24 thomas echo -n "got: a merge operation is in progress in this " \
1228 10604dce 2021-09-24 thomas > $testroot/stderr.expected
1229 10604dce 2021-09-24 thomas echo "work tree and must be continued or aborted first" \
1230 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
1231 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1233 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1234 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1235 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1236 10604dce 2021-09-24 thomas return 1
1240 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1243 10604dce 2021-09-24 thomas test_merge_path_prefix() {
1244 10604dce 2021-09-24 thomas local testroot=`test_init merge_path_prefix`
1245 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
1246 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1248 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
1249 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
1250 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
1251 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1253 10604dce 2021-09-24 thomas got checkout -p epsilon -b master $testroot/repo $testroot/wt \
1254 10604dce 2021-09-24 thomas > /dev/null
1256 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1257 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
1258 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1259 10604dce 2021-09-24 thomas return 1
1262 10604dce 2021-09-24 thomas # create a conflicting commit
1263 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q master
1264 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
1265 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
1266 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
1268 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
1269 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
1271 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1272 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
1273 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1274 10604dce 2021-09-24 thomas return 1
1277 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
1278 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
1280 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
1281 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
1282 10604dce 2021-09-24 thomas test_done "$testroot" "1"
1283 10604dce 2021-09-24 thomas return 1
1286 10604dce 2021-09-24 thomas echo -n "got: cannot merge branch which contains changes outside " \
1287 10604dce 2021-09-24 thomas > $testroot/stderr.expected
1288 10604dce 2021-09-24 thomas echo "of this work tree's path prefix" >> $testroot/stderr.expected
1289 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1291 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1292 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1294 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1297 10604dce 2021-09-24 thomas test_merge_missing_file() {
1298 10604dce 2021-09-24 thomas local testroot=`test_init merge_missing_file`
1299 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
1300 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1302 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
1303 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
1304 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
1305 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha and delta"
1306 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1308 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
1310 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1311 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
1312 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1313 10604dce 2021-09-24 thomas return 1
1316 10604dce 2021-09-24 thomas # create a conflicting commit which renames alpha
1317 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q master
1318 d1e03b8c 2023-10-08 thomas git -C $testroot/repo mv alpha epsilon/alpha-moved
1319 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "moving alpha on master"
1320 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
1322 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
1323 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
1325 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1326 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
1327 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1328 10604dce 2021-09-24 thomas return 1
1331 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
1332 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
1334 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
1335 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
1336 10604dce 2021-09-24 thomas test_done "$testroot" "1"
1337 10604dce 2021-09-24 thomas return 1
1340 10604dce 2021-09-24 thomas echo "! alpha" > $testroot/stdout.expected
1341 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
1342 0ef68859 2021-09-28 thomas echo -n "Files which had incoming changes but could not be found " \
1343 0ef68859 2021-09-28 thomas >> $testroot/stdout.expected
1344 0ef68859 2021-09-28 thomas echo "in the work tree: 1" >> $testroot/stdout.expected
1345 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1347 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1348 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1349 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1350 10604dce 2021-09-24 thomas return 1
1353 ba162991 2021-09-28 thomas echo -n "got: changes destined for some files " \
1354 10604dce 2021-09-24 thomas > $testroot/stderr.expected
1355 10604dce 2021-09-24 thomas echo -n "were not yet merged and should be merged manually if " \
1356 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
1357 10604dce 2021-09-24 thomas echo "required before the merge operation is continued" \
1358 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
1359 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1361 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1362 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1363 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1364 10604dce 2021-09-24 thomas return 1
1367 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1369 cd634f2d 2024-03-30 thomas cat > $testroot/stdout.expected <<EOF
1370 cd634f2d 2024-03-30 thomas M gamma/delta
1371 cd634f2d 2024-03-30 thomas Work tree is merging refs/heads/newbranch into refs/heads/master
1373 2d7ce510 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1375 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1376 2d7ce510 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1377 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1378 2d7ce510 2021-09-24 thomas return 1
1381 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1384 2d7ce510 2021-09-24 thomas test_merge_no_op() {
1385 2d7ce510 2021-09-24 thomas local testroot=`test_init merge_no_op`
1386 2d7ce510 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
1387 2d7ce510 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1389 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
1390 2d7ce510 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
1391 2d7ce510 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
1392 1678610c 2023-04-22 thomas local branch_commit=`git_show_branch_head $testroot/repo newbranch`
1394 2d7ce510 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
1396 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1397 2d7ce510 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
1398 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1399 2d7ce510 2021-09-24 thomas return 1
1402 2d7ce510 2021-09-24 thomas # create a conflicting commit
1403 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q master
1404 2d7ce510 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
1405 2d7ce510 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
1406 2d7ce510 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
1408 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
1409 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
1411 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1412 2d7ce510 2021-09-24 thomas echo "got update failed unexpectedly" >&2
1413 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1414 2d7ce510 2021-09-24 thomas return 1
1417 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
1418 2d7ce510 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
1420 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
1421 2d7ce510 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
1422 2d7ce510 2021-09-24 thomas test_done "$testroot" "1"
1423 2d7ce510 2021-09-24 thomas return 1
1426 2d7ce510 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
1427 2d7ce510 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1428 2d7ce510 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1430 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1431 2d7ce510 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1432 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1433 2d7ce510 2021-09-24 thomas return 1
1436 2d7ce510 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
1437 2d7ce510 2021-09-24 thomas > $testroot/stderr.expected
1438 2d7ce510 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1440 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1441 2d7ce510 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1442 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1443 2d7ce510 2021-09-24 thomas return 1
1446 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1448 cd634f2d 2024-03-30 thomas cat > $testroot/stdout.expected <<EOF
1450 cd634f2d 2024-03-30 thomas Work tree is merging refs/heads/newbranch into refs/heads/master
1452 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1454 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1455 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1456 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1457 10604dce 2021-09-24 thomas return 1
1460 2d7ce510 2021-09-24 thomas # resolve the conflict by reverting all changes; now it is no-op merge
1461 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got revert alpha > /dev/null)
1463 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1464 2d7ce510 2021-09-24 thomas echo "got revert failed unexpectedly" >&2
1465 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1466 2d7ce510 2021-09-24 thomas return 1
1469 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got merge -c > $testroot/stdout \
1470 2d7ce510 2021-09-24 thomas 2> $testroot/stderr)
1472 1678610c 2023-04-22 thomas if [ $ret -ne 0 ]; then
1473 1678610c 2023-04-22 thomas echo "got merge failed unexpectedly" >&2
1474 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1475 2d7ce510 2021-09-24 thomas return 1
1478 1678610c 2023-04-22 thomas echo -n '' > $testroot/stderr.expected
1479 2d7ce510 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1481 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1482 2d7ce510 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1483 1678610c 2023-04-22 thomas test_done "$testroot" "$ret"
1484 1678610c 2023-04-22 thomas return 1
1487 1678610c 2023-04-22 thomas local merge_commit=`git_show_head $testroot/repo`
1488 1678610c 2023-04-22 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1489 1678610c 2023-04-22 thomas > $testroot/stdout.expected
1490 1678610c 2023-04-22 thomas echo $merge_commit >> $testroot/stdout.expected
1492 1678610c 2023-04-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1494 1678610c 2023-04-22 thomas if [ $ret -ne 0 ]; then
1495 1678610c 2023-04-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1496 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1497 2d7ce510 2021-09-24 thomas return 1
1500 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1502 2d7ce510 2021-09-24 thomas echo -n "" > $testroot/stdout.expected
1503 768705e3 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1505 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1506 768705e3 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1507 1678610c 2023-04-22 thomas test_done "$testroot" "$ret"
1508 1678610c 2023-04-22 thomas return 1
1511 1678610c 2023-04-22 thomas # We should have created a merge commit with two parents.
1512 1678610c 2023-04-22 thomas got log -r $testroot/repo -l1 -c $merge_commit | grep ^parent \
1513 1678610c 2023-04-22 thomas > $testroot/stdout
1514 1678610c 2023-04-22 thomas echo "parent 1: $master_commit" > $testroot/stdout.expected
1515 1678610c 2023-04-22 thomas echo "parent 2: $branch_commit" >> $testroot/stdout.expected
1516 1678610c 2023-04-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1518 1678610c 2023-04-22 thomas if [ $ret -ne 0 ]; then
1519 1678610c 2023-04-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1521 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1524 768705e3 2021-09-27 thomas test_merge_imported_branch() {
1525 768705e3 2021-09-27 thomas local testroot=`test_init merge_import`
1526 768705e3 2021-09-27 thomas local commit0=`git_show_head $testroot/repo`
1527 768705e3 2021-09-27 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1529 768705e3 2021-09-27 thomas # import a new sub-tree to the 'files' branch such that
1530 768705e3 2021-09-27 thomas # none of the files added here collide with existing ones
1531 768705e3 2021-09-27 thomas mkdir -p $testroot/tree/there
1532 768705e3 2021-09-27 thomas mkdir -p $testroot/tree/be/lots
1533 768705e3 2021-09-27 thomas mkdir -p $testroot/tree/files
1534 768705e3 2021-09-27 thomas echo "there should" > $testroot/tree/there/should
1535 768705e3 2021-09-27 thomas echo "be lots of" > $testroot/tree/be/lots/of
1536 768705e3 2021-09-27 thomas echo "files here" > $testroot/tree/files/here
1537 768705e3 2021-09-27 thomas got import -r $testroot/repo -b files -m 'import files' \
1538 768705e3 2021-09-27 thomas $testroot/tree > /dev/null
1540 768705e3 2021-09-27 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
1542 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1543 768705e3 2021-09-27 thomas echo "got checkout failed unexpectedly" >&2
1544 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1545 768705e3 2021-09-27 thomas return 1
1548 768705e3 2021-09-27 thomas (cd $testroot/wt && got merge files > $testroot/stdout)
1550 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1551 768705e3 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1552 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1553 768705e3 2021-09-27 thomas return 1
1556 768705e3 2021-09-27 thomas local merge_commit0=`git_show_head $testroot/repo`
1557 768705e3 2021-09-27 thomas cat > $testroot/stdout.expected <<EOF
1558 768705e3 2021-09-27 thomas A be/lots/of
1559 768705e3 2021-09-27 thomas A files/here
1560 768705e3 2021-09-27 thomas A there/should
1561 768705e3 2021-09-27 thomas Merged refs/heads/files into refs/heads/master: $merge_commit0
1563 768705e3 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1565 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1566 768705e3 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1567 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1568 768705e3 2021-09-27 thomas return 1
1571 768705e3 2021-09-27 thomas # try to merge again while no new changes are available
1572 768705e3 2021-09-27 thomas (cd $testroot/wt && got merge files > $testroot/stdout)
1574 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1575 768705e3 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1576 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1577 768705e3 2021-09-27 thomas return 1
1579 768705e3 2021-09-27 thomas echo "Already up-to-date" > $testroot/stdout.expected
1580 2d7ce510 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1582 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1583 2d7ce510 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1584 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1585 768705e3 2021-09-27 thomas return 1
1588 768705e3 2021-09-27 thomas # update the 'files' branch
1589 d1e03b8c 2023-10-08 thomas git -C $testroot/repo reset -q --hard master
1590 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q files
1591 768705e3 2021-09-27 thomas echo "indeed" > $testroot/repo/indeed
1592 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add indeed
1593 768705e3 2021-09-27 thomas git_commit $testroot/repo -m "adding another file indeed"
1594 768705e3 2021-09-27 thomas echo "be lots and lots of" > $testroot/repo/be/lots/of
1595 768705e3 2021-09-27 thomas git_commit $testroot/repo -m "lots of changes"
1597 768705e3 2021-09-27 thomas (cd $testroot/wt && got update > /dev/null)
1599 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1600 768705e3 2021-09-27 thomas echo "got update failed unexpectedly" >&2
1601 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1602 768705e3 2021-09-27 thomas return 1
1605 768705e3 2021-09-27 thomas # we should now be able to merge more changes from files branch
1606 768705e3 2021-09-27 thomas (cd $testroot/wt && got merge files > $testroot/stdout)
1608 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1609 768705e3 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1610 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1611 768705e3 2021-09-27 thomas return 1
1614 768705e3 2021-09-27 thomas local merge_commit1=`git_show_branch_head $testroot/repo master`
1615 768705e3 2021-09-27 thomas cat > $testroot/stdout.expected <<EOF
1616 768705e3 2021-09-27 thomas G be/lots/of
1617 768705e3 2021-09-27 thomas A indeed
1618 768705e3 2021-09-27 thomas Merged refs/heads/files into refs/heads/master: $merge_commit1
1621 768705e3 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1623 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1624 768705e3 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1626 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1629 ba34626b 2021-09-27 thomas test_merge_interrupt() {
1630 ba34626b 2021-09-27 thomas local testroot=`test_init merge_interrupt`
1631 ba34626b 2021-09-27 thomas local commit0=`git_show_head $testroot/repo`
1632 ba34626b 2021-09-27 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1634 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
1635 ba34626b 2021-09-27 thomas echo "modified alpha on branch" > $testroot/repo/alpha
1636 ba34626b 2021-09-27 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
1637 ba34626b 2021-09-27 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1639 ba34626b 2021-09-27 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
1641 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1642 ba34626b 2021-09-27 thomas echo "got checkout failed unexpectedly" >&2
1643 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1644 ba34626b 2021-09-27 thomas return 1
1647 ba34626b 2021-09-27 thomas # create a non-conflicting commit
1648 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q master
1649 ba34626b 2021-09-27 thomas echo "modified beta on master" > $testroot/repo/beta
1650 ba34626b 2021-09-27 thomas git_commit $testroot/repo -m "committing to beta on master"
1651 ba34626b 2021-09-27 thomas local master_commit=`git_show_head $testroot/repo`
1653 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
1654 ba34626b 2021-09-27 thomas (cd $testroot/wt && got update > /dev/null)
1656 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1657 ba34626b 2021-09-27 thomas echo "got update failed unexpectedly" >&2
1658 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1659 ba34626b 2021-09-27 thomas return 1
1662 ba34626b 2021-09-27 thomas (cd $testroot/wt && got merge -n newbranch \
1663 ba34626b 2021-09-27 thomas > $testroot/stdout 2> $testroot/stderr)
1665 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1666 ba34626b 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1667 ba34626b 2021-09-27 thomas test_done "$testroot" "1"
1668 ba34626b 2021-09-27 thomas return 1
1671 ba34626b 2021-09-27 thomas echo "G alpha" > $testroot/stdout.expected
1672 ba34626b 2021-09-27 thomas echo "Merge of refs/heads/newbranch interrupted on request" \
1673 ba34626b 2021-09-27 thomas >> $testroot/stdout.expected
1674 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1676 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1677 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1678 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1679 ba34626b 2021-09-27 thomas return 1
1682 ba34626b 2021-09-27 thomas (cd $testroot/wt && got status > $testroot/stdout)
1684 cd634f2d 2024-03-30 thomas cat > $testroot/stdout.expected <<EOF
1686 cd634f2d 2024-03-30 thomas Work tree is merging refs/heads/newbranch into refs/heads/master
1688 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1690 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1691 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1692 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1693 ba34626b 2021-09-27 thomas return 1
1696 ba34626b 2021-09-27 thomas echo "modified alpha on branch" > $testroot/content.expected
1697 ba34626b 2021-09-27 thomas cat $testroot/wt/alpha > $testroot/content
1698 ba34626b 2021-09-27 thomas cmp -s $testroot/content.expected $testroot/content
1700 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1701 ba34626b 2021-09-27 thomas diff -u $testroot/content.expected $testroot/content
1702 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1703 ba34626b 2021-09-27 thomas return 1
1706 ba34626b 2021-09-27 thomas # adjust merge result
1707 ba34626b 2021-09-27 thomas echo "adjusted merge result" > $testroot/wt/alpha
1709 ba34626b 2021-09-27 thomas # continue the merge
1710 ba34626b 2021-09-27 thomas (cd $testroot/wt && got merge -c > $testroot/stdout)
1712 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1713 ba34626b 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1714 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1715 ba34626b 2021-09-27 thomas return 1
1718 ba34626b 2021-09-27 thomas local merge_commit=`git_show_head $testroot/repo`
1720 ae1e948a 2021-09-28 thomas echo "M alpha" > $testroot/stdout.expected
1721 ba34626b 2021-09-27 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1722 ae1e948a 2021-09-28 thomas >> $testroot/stdout.expected
1723 ba34626b 2021-09-27 thomas echo $merge_commit >> $testroot/stdout.expected
1725 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1727 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1728 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1729 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1730 ba34626b 2021-09-27 thomas return 1
1733 ba34626b 2021-09-27 thomas (cd $testroot/wt && got status > $testroot/stdout)
1735 ba34626b 2021-09-27 thomas echo -n > $testroot/stdout.expected
1736 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1738 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1739 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1740 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1741 ba34626b 2021-09-27 thomas return 1
1744 ba34626b 2021-09-27 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1745 ba34626b 2021-09-27 thomas echo "commit $merge_commit (master)" > $testroot/stdout.expected
1746 ba34626b 2021-09-27 thomas echo "commit $master_commit" >> $testroot/stdout.expected
1747 ba34626b 2021-09-27 thomas echo "commit $commit0" >> $testroot/stdout.expected
1748 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1750 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1751 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1752 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1753 ba34626b 2021-09-27 thomas return 1
1756 ba34626b 2021-09-27 thomas (cd $testroot/wt && got update > $testroot/stdout)
1758 ba34626b 2021-09-27 thomas echo 'Already up-to-date' > $testroot/stdout.expected
1759 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1761 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1762 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1763 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1764 ba34626b 2021-09-27 thomas return 1
1767 ba34626b 2021-09-27 thomas # We should have created a merge commit with two parents.
1768 ba34626b 2021-09-27 thomas (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
1769 ba34626b 2021-09-27 thomas echo "parent 1: $master_commit" > $testroot/stdout.expected
1770 ba34626b 2021-09-27 thomas echo "parent 2: $branch_commit0" >> $testroot/stdout.expected
1771 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1773 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1774 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1776 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1779 a2c162eb 2022-10-30 thomas test_merge_umask() {
1780 a2c162eb 2022-10-30 thomas local testroot=`test_init merge_umask`
1782 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
1783 a2c162eb 2022-10-30 thomas echo "modified alpha on branch" >$testroot/repo/alpha
1784 a2c162eb 2022-10-30 thomas git_commit "$testroot/repo" -m "committing alpha on newbranch"
1785 a2c162eb 2022-10-30 thomas echo "modified delta on branch" >$testroot/repo/gamma/delta
1786 a2c162eb 2022-10-30 thomas git_commit "$testroot/repo" -m "committing delta on newbranch"
1788 a2c162eb 2022-10-30 thomas # diverge from newbranch
1789 d1e03b8c 2023-10-08 thomas git -C "$testroot/repo" checkout -q master
1790 a2c162eb 2022-10-30 thomas echo "modified beta on master" >$testroot/repo/beta
1791 a2c162eb 2022-10-30 thomas git_commit "$testroot/repo" -m "committing zeto no master"
1793 a2c162eb 2022-10-30 thomas got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1795 a2c162eb 2022-10-30 thomas # using a subshell to avoid clobbering global umask
1796 a2c162eb 2022-10-30 thomas (umask 077 && cd "$testroot/wt" && got merge newbranch) >/dev/null
1798 a2c162eb 2022-10-30 thomas for f in alpha gamma/delta; do
1799 a2c162eb 2022-10-30 thomas ls -l "$testroot/wt/$f" | grep -q ^-rw-------
1800 a2c162eb 2022-10-30 thomas if [ $? -ne 0 ]; then
1801 a2c162eb 2022-10-30 thomas echo "$f is not 0600 after merge" >&2
1802 a2c162eb 2022-10-30 thomas ls -l "$testroot/wt/$f" >&2
1803 a2c162eb 2022-10-30 thomas test_done "$testroot" 1
1807 a2c162eb 2022-10-30 thomas test_done "$testroot" 0
1810 b16f1832 2023-02-21 thomas test_merge_gitconfig_author() {
1811 b16f1832 2023-02-21 thomas local testroot=`test_init merge_gitconfig_author`
1813 d1e03b8c 2023-10-08 thomas git -C $testroot/repo config user.name 'Flan Luck'
1814 d1e03b8c 2023-10-08 thomas git -C $testroot/repo config user.email 'flan_luck@openbsd.org'
1816 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
1817 b16f1832 2023-02-21 thomas echo "modified alpha on branch" >$testroot/repo/alpha
1818 b16f1832 2023-02-21 thomas git_commit "$testroot/repo" -m "committing alpha on newbranch"
1819 b16f1832 2023-02-21 thomas echo "modified delta on branch" >$testroot/repo/gamma/delta
1820 b16f1832 2023-02-21 thomas git_commit "$testroot/repo" -m "committing delta on newbranch"
1822 b16f1832 2023-02-21 thomas # diverge from newbranch
1823 d1e03b8c 2023-10-08 thomas git -C "$testroot/repo" checkout -q master
1824 b16f1832 2023-02-21 thomas echo "modified beta on master" >$testroot/repo/beta
1825 b16f1832 2023-02-21 thomas git_commit "$testroot/repo" -m "committing zeto no master"
1827 b16f1832 2023-02-21 thomas got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1829 b16f1832 2023-02-21 thomas # unset in a subshell to avoid affecting our environment
1830 b16f1832 2023-02-21 thomas (unset GOT_IGNORE_GITCONFIG && cd $testroot/wt && \
1831 b16f1832 2023-02-21 thomas got merge newbranch > /dev/null)
1833 b16f1832 2023-02-21 thomas (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
1835 b16f1832 2023-02-21 thomas if [ $ret -ne 0 ]; then
1836 b16f1832 2023-02-21 thomas test_done "$testroot" "$ret"
1837 b16f1832 2023-02-21 thomas return 1
1840 b16f1832 2023-02-21 thomas echo "from: Flan Luck <flan_luck@openbsd.org>" \
1841 b16f1832 2023-02-21 thomas > $testroot/stdout.expected
1842 b16f1832 2023-02-21 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1844 b16f1832 2023-02-21 thomas if [ $ret -ne 0 ]; then
1845 b16f1832 2023-02-21 thomas diff -u $testroot/stdout.expected $testroot/stdout
1847 b16f1832 2023-02-21 thomas test_done "$testroot" "$ret"
1850 4434a15a 2023-06-22 thomas test_merge_fetched_branch() {
1851 4434a15a 2023-06-22 thomas local testroot=`test_init merge_fetched_branch`
1852 4434a15a 2023-06-22 thomas local testurl=ssh://127.0.0.1/$testroot
1853 4434a15a 2023-06-22 thomas local commit_id=`git_show_head $testroot/repo`
1855 4434a15a 2023-06-22 thomas got clone -q $testurl/repo $testroot/repo-clone
1857 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1858 4434a15a 2023-06-22 thomas echo "got clone command failed unexpectedly" >&2
1859 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1860 4434a15a 2023-06-22 thomas return 1
1863 4434a15a 2023-06-22 thomas echo "modified alpha" > $testroot/repo/alpha
1864 4434a15a 2023-06-22 thomas git_commit $testroot/repo -m "modified alpha"
1865 4434a15a 2023-06-22 thomas local commit_id2=`git_show_head $testroot/repo`
1867 4434a15a 2023-06-22 thomas got fetch -q -r $testroot/repo-clone > $testroot/stdout
1869 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1870 4434a15a 2023-06-22 thomas echo "got fetch command failed unexpectedly" >&2
1871 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1872 4434a15a 2023-06-22 thomas return 1
1875 4434a15a 2023-06-22 thomas echo -n > $testroot/stdout.expected
1877 4434a15a 2023-06-22 thomas cmp -s $testroot/stdout $testroot/stdout.expected
1879 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1880 4434a15a 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1881 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1882 4434a15a 2023-06-22 thomas return 1
1885 4434a15a 2023-06-22 thomas got ref -l -r $testroot/repo-clone > $testroot/stdout
1887 4434a15a 2023-06-22 thomas echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1888 4434a15a 2023-06-22 thomas echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1889 4434a15a 2023-06-22 thomas echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1890 4434a15a 2023-06-22 thomas >> $testroot/stdout.expected
1891 4434a15a 2023-06-22 thomas echo "refs/remotes/origin/master: $commit_id2" \
1892 4434a15a 2023-06-22 thomas >> $testroot/stdout.expected
1894 4434a15a 2023-06-22 thomas cmp -s $testroot/stdout $testroot/stdout.expected
1896 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1897 4434a15a 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1898 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1899 4434a15a 2023-06-22 thomas return 1
1902 4434a15a 2023-06-22 thomas got checkout $testroot/repo-clone $testroot/wt > /dev/null
1904 4434a15a 2023-06-22 thomas echo "modified beta" > $testroot/wt/beta
1905 4434a15a 2023-06-22 thomas (cd $testroot/wt && got commit -m "modified beta" > /dev/null)
1906 4434a15a 2023-06-22 thomas local commit_id3=`git_show_head $testroot/repo-clone`
1908 4434a15a 2023-06-22 thomas (cd $testroot/wt && got update > /dev/null)
1909 4434a15a 2023-06-22 thomas (cd $testroot/wt && got merge origin/master > $testroot/stdout)
1910 4434a15a 2023-06-22 thomas local merge_commit_id=`git_show_head $testroot/repo-clone`
1912 4434a15a 2023-06-22 thomas cat > $testroot/stdout.expected <<EOF
1914 4434a15a 2023-06-22 thomas Merged refs/remotes/origin/master into refs/heads/master: $merge_commit_id
1917 4434a15a 2023-06-22 thomas cmp -s $testroot/stdout $testroot/stdout.expected
1919 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1920 4434a15a 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1922 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1925 4434a15a 2023-06-22 thomas test_merge_fetched_branch_remote() {
1926 4434a15a 2023-06-22 thomas local testroot=`test_init merge_fetched_branch_remote`
1927 4434a15a 2023-06-22 thomas local testurl=ssh://127.0.0.1/$testroot
1928 4434a15a 2023-06-22 thomas local commit_id=`git_show_head $testroot/repo`
1930 4434a15a 2023-06-22 thomas got clone -q $testurl/repo $testroot/repo-clone
1932 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1933 4434a15a 2023-06-22 thomas echo "got clone command failed unexpectedly" >&2
1934 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1935 4434a15a 2023-06-22 thomas return 1
1938 4434a15a 2023-06-22 thomas echo "modified alpha" > $testroot/repo/alpha
1939 4434a15a 2023-06-22 thomas git_commit $testroot/repo -m "modified alpha"
1940 4434a15a 2023-06-22 thomas local commit_id2=`git_show_head $testroot/repo`
1942 4434a15a 2023-06-22 thomas got fetch -q -r $testroot/repo-clone > $testroot/stdout
1944 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1945 4434a15a 2023-06-22 thomas echo "got fetch command failed unexpectedly" >&2
1946 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1947 4434a15a 2023-06-22 thomas return 1
1950 4434a15a 2023-06-22 thomas echo -n > $testroot/stdout.expected
1952 4434a15a 2023-06-22 thomas cmp -s $testroot/stdout $testroot/stdout.expected
1954 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1955 4434a15a 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1956 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1957 4434a15a 2023-06-22 thomas return 1
1960 4434a15a 2023-06-22 thomas got ref -l -r $testroot/repo-clone > $testroot/stdout
1962 4434a15a 2023-06-22 thomas echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1963 4434a15a 2023-06-22 thomas echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1964 4434a15a 2023-06-22 thomas echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1965 4434a15a 2023-06-22 thomas >> $testroot/stdout.expected
1966 4434a15a 2023-06-22 thomas echo "refs/remotes/origin/master: $commit_id2" \
1967 4434a15a 2023-06-22 thomas >> $testroot/stdout.expected
1969 4434a15a 2023-06-22 thomas cmp -s $testroot/stdout $testroot/stdout.expected
1971 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1972 4434a15a 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1973 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1974 4434a15a 2023-06-22 thomas return 1
1977 4434a15a 2023-06-22 thomas got checkout $testroot/repo-clone $testroot/wt > /dev/null
1979 4434a15a 2023-06-22 thomas echo "modified beta" > $testroot/wt/beta
1980 4434a15a 2023-06-22 thomas (cd $testroot/wt && got commit -m "modified beta" > /dev/null)
1981 4434a15a 2023-06-22 thomas local commit_id3=`git_show_head $testroot/repo-clone`
1983 4434a15a 2023-06-22 thomas (cd $testroot/wt && got update -b origin/master > /dev/null)
1984 4434a15a 2023-06-22 thomas (cd $testroot/wt && got merge master > \
1985 4434a15a 2023-06-22 thomas $testroot/stdout 2> $testroot/stderr)
1986 4434a15a 2023-06-22 thomas local merge_commit_id=`git_show_head $testroot/repo-clone`
1988 4434a15a 2023-06-22 thomas echo -n > $testroot/stdout.expected
1990 4434a15a 2023-06-22 thomas cmp -s $testroot/stdout $testroot/stdout.expected
1992 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1993 4434a15a 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1994 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1995 4434a15a 2023-06-22 thomas return 1
1998 4434a15a 2023-06-22 thomas echo -n "got: work tree's current branch refs/remotes/origin/master " \
1999 4434a15a 2023-06-22 thomas > $testroot/stderr.expected
2000 4434a15a 2023-06-22 thomas echo -n 'is outside the "refs/heads/" reference namespace; ' \
2001 4434a15a 2023-06-22 thomas >> $testroot/stderr.expected
2002 4434a15a 2023-06-22 thomas echo -n "update -b required: will not commit to a branch " \
2003 4434a15a 2023-06-22 thomas >> $testroot/stderr.expected
2004 4434a15a 2023-06-22 thomas echo 'outside the "refs/heads/" reference namespace' \
2005 4434a15a 2023-06-22 thomas >> $testroot/stderr.expected
2007 4434a15a 2023-06-22 thomas cmp -s $testroot/stderr $testroot/stderr.expected
2009 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
2010 4434a15a 2023-06-22 thomas diff -u $testroot/stderr.expected $testroot/stderr
2012 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
2015 10604dce 2021-09-24 thomas test_parseargs "$@"
2016 10604dce 2021-09-24 thomas run_test test_merge_basic
2017 2b72f32d 2023-06-22 thomas run_test test_merge_forward
2018 31009ade 2023-07-05 thomas run_test test_merge_forward_commit
2019 31009ade 2023-07-05 thomas run_test test_merge_forward_interrupt
2020 2b72f32d 2023-06-22 thomas run_test test_merge_backward
2021 10604dce 2021-09-24 thomas run_test test_merge_continue
2022 fe3f264b 2023-06-08 thomas run_test test_merge_continue_new_commit
2023 10604dce 2021-09-24 thomas run_test test_merge_abort
2024 10604dce 2021-09-24 thomas run_test test_merge_in_progress
2025 10604dce 2021-09-24 thomas run_test test_merge_path_prefix
2026 10604dce 2021-09-24 thomas run_test test_merge_missing_file
2027 2d7ce510 2021-09-24 thomas run_test test_merge_no_op
2028 768705e3 2021-09-27 thomas run_test test_merge_imported_branch
2029 ba34626b 2021-09-27 thomas run_test test_merge_interrupt
2030 a2c162eb 2022-10-30 thomas run_test test_merge_umask
2031 b16f1832 2023-02-21 thomas run_test test_merge_gitconfig_author
2032 4434a15a 2023-06-22 thomas run_test test_merge_fetched_branch
2033 4434a15a 2023-06-22 thomas run_test test_merge_fetched_branch_remote