Blame


1 10604dce 2021-09-24 thomas #!/bin/sh
2 10604dce 2021-09-24 thomas #
3 10604dce 2021-09-24 thomas # Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
4 10604dce 2021-09-24 thomas #
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.
8 10604dce 2021-09-24 thomas #
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.
16 10604dce 2021-09-24 thomas
17 10604dce 2021-09-24 thomas . ./common.sh
18 10604dce 2021-09-24 thomas
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`
23 10604dce 2021-09-24 thomas
24 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
25 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
26 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to delta on newbranch"
27 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
28 10604dce 2021-09-24 thomas
29 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
30 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
31 10604dce 2021-09-24 thomas local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
32 10604dce 2021-09-24 thomas (cd $testroot/repo && git rm -q beta)
33 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "removing beta on newbranch"
34 10604dce 2021-09-24 thomas local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
35 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/repo/epsilon/new
36 10604dce 2021-09-24 thomas (cd $testroot/repo && git add epsilon/new)
37 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding new file on newbranch"
38 10604dce 2021-09-24 thomas local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
39 10604dce 2021-09-24 thomas (cd $testroot/repo && ln -s alpha symlink && git add symlink)
40 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding symlink on newbranch"
41 10604dce 2021-09-24 thomas local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
42 ace90326 2021-09-27 thomas (cd $testroot/repo && ln -sf .got/bar dotgotbar.link)
43 ace90326 2021-09-27 thomas (cd $testroot/repo && git add dotgotbar.link)
44 ace90326 2021-09-27 thomas git_commit $testroot/repo -m "adding a bad symlink on newbranch"
45 ace90326 2021-09-27 thomas local branch_commit5=`git_show_branch_head $testroot/repo newbranch`
46 10604dce 2021-09-24 thomas
47 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
48 fc414659 2022-04-16 thomas ret=$?
49 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
50 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
51 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
52 10604dce 2021-09-24 thomas return 1
53 10604dce 2021-09-24 thomas fi
54 10604dce 2021-09-24 thomas
55 2b72f32d 2023-06-22 thomas # create a divergent commit
56 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
57 10604dce 2021-09-24 thomas echo "modified zeta on master" > $testroot/repo/epsilon/zeta
58 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to zeta on master"
59 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
60 10604dce 2021-09-24 thomas
61 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
62 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
63 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
64 fc414659 2022-04-16 thomas ret=$?
65 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
66 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
67 0b477035 2023-06-22 thomas test_done "$testroot" "1"
68 10604dce 2021-09-24 thomas return 1
69 10604dce 2021-09-24 thomas fi
70 10604dce 2021-09-24 thomas echo -n "got: work tree must be updated before it can be used " \
71 10604dce 2021-09-24 thomas > $testroot/stderr.expected
72 10604dce 2021-09-24 thomas echo "to merge a branch" >> $testroot/stderr.expected
73 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
74 fc414659 2022-04-16 thomas ret=$?
75 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
76 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
77 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
78 10604dce 2021-09-24 thomas return 1
79 10604dce 2021-09-24 thomas fi
80 10604dce 2021-09-24 thomas
81 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
82 fc414659 2022-04-16 thomas ret=$?
83 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
84 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
85 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
86 10604dce 2021-09-24 thomas return 1
87 10604dce 2021-09-24 thomas fi
88 10604dce 2021-09-24 thomas
89 b6b86fd1 2022-08-30 thomas # must not use a mixed-commit work tree with 'got merge'
90 10604dce 2021-09-24 thomas (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
91 fc414659 2022-04-16 thomas ret=$?
92 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
93 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
94 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
95 10604dce 2021-09-24 thomas return 1
96 10604dce 2021-09-24 thomas fi
97 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
98 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
99 fc414659 2022-04-16 thomas ret=$?
100 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
101 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
102 0b477035 2023-06-22 thomas test_done "$testroot" "1"
103 10604dce 2021-09-24 thomas return 1
104 10604dce 2021-09-24 thomas fi
105 10604dce 2021-09-24 thomas echo -n "got: work tree contains files from multiple base commits; " \
106 10604dce 2021-09-24 thomas > $testroot/stderr.expected
107 10604dce 2021-09-24 thomas echo "the entire work tree must be updated first" \
108 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
109 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
110 fc414659 2022-04-16 thomas ret=$?
111 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
112 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
113 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
114 10604dce 2021-09-24 thomas return 1
115 10604dce 2021-09-24 thomas fi
116 10604dce 2021-09-24 thomas
117 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
118 fc414659 2022-04-16 thomas ret=$?
119 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
120 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
121 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
122 10604dce 2021-09-24 thomas return 1
123 10604dce 2021-09-24 thomas fi
124 10604dce 2021-09-24 thomas
125 b6b86fd1 2022-08-30 thomas # must not have staged files with 'got merge'
126 10604dce 2021-09-24 thomas echo "modified file alpha" > $testroot/wt/alpha
127 10604dce 2021-09-24 thomas (cd $testroot/wt && got stage alpha > /dev/null)
128 fc414659 2022-04-16 thomas ret=$?
129 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
130 10604dce 2021-09-24 thomas echo "got stage failed unexpectedly" >&2
131 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
132 10604dce 2021-09-24 thomas return 1
133 10604dce 2021-09-24 thomas fi
134 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
135 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
136 fc414659 2022-04-16 thomas ret=$?
137 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
138 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
139 0b477035 2023-06-22 thomas test_done "$testroot" "1"
140 10604dce 2021-09-24 thomas return 1
141 10604dce 2021-09-24 thomas fi
142 10604dce 2021-09-24 thomas echo "got: alpha: file is staged" > $testroot/stderr.expected
143 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
144 fc414659 2022-04-16 thomas ret=$?
145 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
146 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
147 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
148 10604dce 2021-09-24 thomas return 1
149 10604dce 2021-09-24 thomas fi
150 10604dce 2021-09-24 thomas (cd $testroot/wt && got unstage alpha > /dev/null)
151 fc414659 2022-04-16 thomas ret=$?
152 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
153 10604dce 2021-09-24 thomas echo "got unstage failed unexpectedly" >&2
154 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
155 10604dce 2021-09-24 thomas return 1
156 10604dce 2021-09-24 thomas fi
157 10604dce 2021-09-24 thomas
158 b6b86fd1 2022-08-30 thomas # must not have local changes with 'got merge'
159 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
160 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
161 fc414659 2022-04-16 thomas ret=$?
162 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
163 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
164 0b477035 2023-06-22 thomas test_done "$testroot" "1"
165 10604dce 2021-09-24 thomas return 1
166 10604dce 2021-09-24 thomas fi
167 10604dce 2021-09-24 thomas echo -n "got: work tree contains local changes; " \
168 10604dce 2021-09-24 thomas > $testroot/stderr.expected
169 10604dce 2021-09-24 thomas echo "these changes must be committed or reverted first" \
170 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
171 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
172 fc414659 2022-04-16 thomas ret=$?
173 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
174 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
175 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
176 10604dce 2021-09-24 thomas return 1
177 10604dce 2021-09-24 thomas fi
178 10604dce 2021-09-24 thomas
179 10604dce 2021-09-24 thomas (cd $testroot/wt && got revert alpha > /dev/null)
180 fc414659 2022-04-16 thomas ret=$?
181 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
182 10604dce 2021-09-24 thomas echo "got revert failed unexpectedly" >&2
183 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
184 10604dce 2021-09-24 thomas return 1
185 10604dce 2021-09-24 thomas fi
186 10604dce 2021-09-24 thomas
187 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch > $testroot/stdout)
188 fc414659 2022-04-16 thomas ret=$?
189 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
190 10604dce 2021-09-24 thomas echo "got merge failed unexpectedly" >&2
191 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
192 10604dce 2021-09-24 thomas return 1
193 10604dce 2021-09-24 thomas fi
194 10604dce 2021-09-24 thomas
195 10604dce 2021-09-24 thomas local merge_commit=`git_show_head $testroot/repo`
196 10604dce 2021-09-24 thomas
197 10604dce 2021-09-24 thomas echo "G alpha" >> $testroot/stdout.expected
198 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
199 ace90326 2021-09-27 thomas echo "A dotgotbar.link" >> $testroot/stdout.expected
200 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
201 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
202 10604dce 2021-09-24 thomas echo "A symlink" >> $testroot/stdout.expected
203 10604dce 2021-09-24 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
204 10604dce 2021-09-24 thomas >> $testroot/stdout.expected
205 10604dce 2021-09-24 thomas echo $merge_commit >> $testroot/stdout.expected
206 10604dce 2021-09-24 thomas
207 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
208 fc414659 2022-04-16 thomas ret=$?
209 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
210 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
211 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
212 10604dce 2021-09-24 thomas return 1
213 10604dce 2021-09-24 thomas fi
214 10604dce 2021-09-24 thomas
215 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/content.expected
216 10604dce 2021-09-24 thomas cat $testroot/wt/gamma/delta > $testroot/content
217 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
218 fc414659 2022-04-16 thomas ret=$?
219 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
220 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
221 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
222 10604dce 2021-09-24 thomas return 1
223 10604dce 2021-09-24 thomas fi
224 10604dce 2021-09-24 thomas
225 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/content.expected
226 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
227 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
228 fc414659 2022-04-16 thomas ret=$?
229 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
230 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
231 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
232 10604dce 2021-09-24 thomas return 1
233 10604dce 2021-09-24 thomas fi
234 10604dce 2021-09-24 thomas
235 10604dce 2021-09-24 thomas if [ -e $testroot/wt/beta ]; then
236 10604dce 2021-09-24 thomas echo "removed file beta still exists on disk" >&2
237 10604dce 2021-09-24 thomas test_done "$testroot" "1"
238 10604dce 2021-09-24 thomas return 1
239 10604dce 2021-09-24 thomas fi
240 10604dce 2021-09-24 thomas
241 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/content.expected
242 10604dce 2021-09-24 thomas cat $testroot/wt/epsilon/new > $testroot/content
243 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
244 fc414659 2022-04-16 thomas ret=$?
245 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
246 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
247 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
248 10604dce 2021-09-24 thomas return 1
249 10604dce 2021-09-24 thomas fi
250 10604dce 2021-09-24 thomas
251 ace90326 2021-09-27 thomas if [ ! -h $testroot/wt/dotgotbar.link ]; then
252 ace90326 2021-09-27 thomas echo "dotgotbar.link is not a symlink"
253 ace90326 2021-09-27 thomas test_done "$testroot" "1"
254 ace90326 2021-09-27 thomas return 1
255 ace90326 2021-09-27 thomas fi
256 ace90326 2021-09-27 thomas
257 10604dce 2021-09-24 thomas readlink $testroot/wt/symlink > $testroot/stdout
258 10604dce 2021-09-24 thomas echo "alpha" > $testroot/stdout.expected
259 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
260 fc414659 2022-04-16 thomas ret=$?
261 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
262 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
263 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
264 10604dce 2021-09-24 thomas return 1
265 10604dce 2021-09-24 thomas fi
266 10604dce 2021-09-24 thomas
267 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
268 10604dce 2021-09-24 thomas
269 10604dce 2021-09-24 thomas echo -n > $testroot/stdout.expected
270 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
271 fc414659 2022-04-16 thomas ret=$?
272 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
273 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
274 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
275 10604dce 2021-09-24 thomas return 1
276 10604dce 2021-09-24 thomas fi
277 10604dce 2021-09-24 thomas
278 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
279 10604dce 2021-09-24 thomas echo "commit $merge_commit (master)" > $testroot/stdout.expected
280 10604dce 2021-09-24 thomas echo "commit $master_commit" >> $testroot/stdout.expected
281 10604dce 2021-09-24 thomas echo "commit $commit0" >> $testroot/stdout.expected
282 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
283 fc414659 2022-04-16 thomas ret=$?
284 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
285 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
286 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
287 10604dce 2021-09-24 thomas return 1
288 10604dce 2021-09-24 thomas fi
289 10604dce 2021-09-24 thomas
290 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > $testroot/stdout)
291 10604dce 2021-09-24 thomas
292 ace90326 2021-09-27 thomas echo 'U dotgotbar.link' > $testroot/stdout.expected
293 ace90326 2021-09-27 thomas echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
294 ace90326 2021-09-27 thomas git_show_head $testroot/repo >> $testroot/stdout.expected
295 ace90326 2021-09-27 thomas echo >> $testroot/stdout.expected
296 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
297 fc414659 2022-04-16 thomas ret=$?
298 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
299 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
300 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
301 10604dce 2021-09-24 thomas return 1
302 10604dce 2021-09-24 thomas fi
303 10604dce 2021-09-24 thomas
304 ace90326 2021-09-27 thomas # update has changed the bad symlink into a regular file
305 ace90326 2021-09-27 thomas if [ -h $testroot/wt/dotgotbar.link ]; then
306 ace90326 2021-09-27 thomas echo "dotgotbar.link is a symlink"
307 ace90326 2021-09-27 thomas test_done "$testroot" "1"
308 ace90326 2021-09-27 thomas return 1
309 ace90326 2021-09-27 thomas fi
310 ace90326 2021-09-27 thomas
311 10604dce 2021-09-24 thomas # We should have created a merge commit with two parents.
312 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
313 10604dce 2021-09-24 thomas echo "parent 1: $master_commit" > $testroot/stdout.expected
314 ace90326 2021-09-27 thomas echo "parent 2: $branch_commit5" >> $testroot/stdout.expected
315 ace90326 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
316 fc414659 2022-04-16 thomas ret=$?
317 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
318 ace90326 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
319 ace90326 2021-09-27 thomas test_done "$testroot" "$ret"
320 ace90326 2021-09-27 thomas return 1
321 ace90326 2021-09-27 thomas fi
322 ace90326 2021-09-27 thomas
323 ace90326 2021-09-27 thomas got tree -r $testroot/repo -c $merge_commit -R > $testroot/stdout
324 fc414659 2022-04-16 thomas ret=$?
325 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
326 ace90326 2021-09-27 thomas echo "got tree failed unexpectedly" >&2
327 ace90326 2021-09-27 thomas test_done "$testroot" "$ret"
328 ace90326 2021-09-27 thomas return 1
329 ace90326 2021-09-27 thomas fi
330 ace90326 2021-09-27 thomas
331 ace90326 2021-09-27 thomas # bad symlink dotgotbar.link appears as a symlink in the merge commit:
332 ace90326 2021-09-27 thomas cat > $testroot/stdout.expected <<EOF
333 ace90326 2021-09-27 thomas alpha
334 ace90326 2021-09-27 thomas dotgotbar.link@ -> .got/bar
335 ace90326 2021-09-27 thomas epsilon/
336 ace90326 2021-09-27 thomas epsilon/new
337 ace90326 2021-09-27 thomas epsilon/zeta
338 ace90326 2021-09-27 thomas gamma/
339 ace90326 2021-09-27 thomas gamma/delta
340 ace90326 2021-09-27 thomas symlink@ -> alpha
341 ace90326 2021-09-27 thomas EOF
342 2b72f32d 2023-06-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
343 2b72f32d 2023-06-22 thomas ret=$?
344 2b72f32d 2023-06-22 thomas if [ $ret -ne 0 ]; then
345 2b72f32d 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
346 2b72f32d 2023-06-22 thomas fi
347 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
348 2b72f32d 2023-06-22 thomas }
349 2b72f32d 2023-06-22 thomas
350 2b72f32d 2023-06-22 thomas test_merge_forward() {
351 2b72f32d 2023-06-22 thomas local testroot=`test_init merge_forward`
352 2b72f32d 2023-06-22 thomas local commit0=`git_show_head $testroot/repo`
353 2b72f32d 2023-06-22 thomas
354 2b72f32d 2023-06-22 thomas # Create a commit before branching, which will be used to help test
355 2b72f32d 2023-06-22 thomas # preconditions for "got merge".
356 2b72f32d 2023-06-22 thomas echo "modified alpha" > $testroot/repo/alpha
357 2b72f32d 2023-06-22 thomas git_commit $testroot/repo -m "common commit"
358 2b72f32d 2023-06-22 thomas local commit1=`git_show_head $testroot/repo`
359 2b72f32d 2023-06-22 thomas
360 2b72f32d 2023-06-22 thomas (cd $testroot/repo && git checkout -q -b newbranch)
361 2b72f32d 2023-06-22 thomas echo "modified beta on branch" > $testroot/repo/beta
362 2b72f32d 2023-06-22 thomas git_commit $testroot/repo -m "committing to beta on newbranch"
363 2b72f32d 2023-06-22 thomas local commit2=`git_show_head $testroot/repo`
364 2b72f32d 2023-06-22 thomas
365 2b72f32d 2023-06-22 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
366 2b72f32d 2023-06-22 thomas ret=$?
367 2b72f32d 2023-06-22 thomas if [ $ret -ne 0 ]; then
368 2b72f32d 2023-06-22 thomas echo "got checkout failed unexpectedly" >&2
369 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
370 2b72f32d 2023-06-22 thomas return 1
371 2b72f32d 2023-06-22 thomas fi
372 2b72f32d 2023-06-22 thomas
373 2b72f32d 2023-06-22 thomas # must not use a mixed-commit work tree with 'got merge'
374 2b72f32d 2023-06-22 thomas (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
375 2b72f32d 2023-06-22 thomas ret=$?
376 2b72f32d 2023-06-22 thomas if [ $ret -ne 0 ]; then
377 2b72f32d 2023-06-22 thomas echo "got update failed unexpectedly" >&2
378 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
379 2b72f32d 2023-06-22 thomas return 1
380 2b72f32d 2023-06-22 thomas fi
381 2b72f32d 2023-06-22 thomas (cd $testroot/wt && got merge newbranch \
382 2b72f32d 2023-06-22 thomas > $testroot/stdout 2> $testroot/stderr)
383 2b72f32d 2023-06-22 thomas ret=$?
384 2b72f32d 2023-06-22 thomas if [ $ret -eq 0 ]; then
385 2b72f32d 2023-06-22 thomas echo "got merge succeeded unexpectedly" >&2
386 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
387 2b72f32d 2023-06-22 thomas return 1
388 2b72f32d 2023-06-22 thomas fi
389 2b72f32d 2023-06-22 thomas echo -n "got: work tree contains files from multiple base commits; " \
390 2b72f32d 2023-06-22 thomas > $testroot/stderr.expected
391 2b72f32d 2023-06-22 thomas echo "the entire work tree must be updated first" \
392 2b72f32d 2023-06-22 thomas >> $testroot/stderr.expected
393 2b72f32d 2023-06-22 thomas cmp -s $testroot/stderr.expected $testroot/stderr
394 2b72f32d 2023-06-22 thomas ret=$?
395 2b72f32d 2023-06-22 thomas if [ $ret -ne 0 ]; then
396 2b72f32d 2023-06-22 thomas diff -u $testroot/stderr.expected $testroot/stderr
397 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
398 2b72f32d 2023-06-22 thomas return 1
399 2b72f32d 2023-06-22 thomas fi
400 2b72f32d 2023-06-22 thomas
401 2b72f32d 2023-06-22 thomas (cd $testroot/wt && got update > /dev/null)
402 2b72f32d 2023-06-22 thomas ret=$?
403 2b72f32d 2023-06-22 thomas if [ $ret -ne 0 ]; then
404 2b72f32d 2023-06-22 thomas echo "got update failed unexpectedly" >&2
405 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
406 2b72f32d 2023-06-22 thomas return 1
407 2b72f32d 2023-06-22 thomas fi
408 2b72f32d 2023-06-22 thomas
409 2b72f32d 2023-06-22 thomas # 'got merge -n' refuses to fast-forward
410 2b72f32d 2023-06-22 thomas (cd $testroot/wt && got merge -n newbranch \
411 2b72f32d 2023-06-22 thomas > $testroot/stdout 2> $testroot/stderr)
412 2b72f32d 2023-06-22 thomas ret=$?
413 2b72f32d 2023-06-22 thomas if [ $ret -eq 0 ]; then
414 2b72f32d 2023-06-22 thomas echo "got merge succeeded unexpectedly" >&2
415 2b72f32d 2023-06-22 thomas test_done "$testroot" "1"
416 2b72f32d 2023-06-22 thomas return 1
417 2b72f32d 2023-06-22 thomas fi
418 0619bbce 2023-06-22 thomas
419 0619bbce 2023-06-22 thomas echo -n "got: there are no changes to merge since " \
420 0619bbce 2023-06-22 thomas > $testroot/stderr.expected
421 0619bbce 2023-06-22 thomas echo -n "refs/heads/newbranch is already based on " \
422 2b72f32d 2023-06-22 thomas >> $testroot/stderr.expected
423 0619bbce 2023-06-22 thomas echo -n "refs/heads/master; merge cannot be interrupted " \
424 0619bbce 2023-06-22 thomas >> $testroot/stderr.expected
425 0619bbce 2023-06-22 thomas echo "for amending; -n: option cannot be used" \
426 0619bbce 2023-06-22 thomas >> $testroot/stderr.expected
427 0619bbce 2023-06-22 thomas
428 2b72f32d 2023-06-22 thomas cmp -s $testroot/stderr.expected $testroot/stderr
429 2b72f32d 2023-06-22 thomas ret=$?
430 2b72f32d 2023-06-22 thomas if [ $ret -ne 0 ]; then
431 2b72f32d 2023-06-22 thomas diff -u $testroot/stderr.expected $testroot/stderr
432 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
433 2b72f32d 2023-06-22 thomas return 1
434 2b72f32d 2023-06-22 thomas fi
435 2b72f32d 2023-06-22 thomas
436 2b72f32d 2023-06-22 thomas (cd $testroot/wt && got merge newbranch \
437 2b72f32d 2023-06-22 thomas > $testroot/stdout 2> $testroot/stderr)
438 2b72f32d 2023-06-22 thomas ret=$?
439 2b72f32d 2023-06-22 thomas if [ $ret -ne 0 ]; then
440 2b72f32d 2023-06-22 thomas echo "got merge failed unexpectedly" >&2
441 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
442 2b72f32d 2023-06-22 thomas return 1
443 2b72f32d 2023-06-22 thomas fi
444 2b72f32d 2023-06-22 thomas
445 2b72f32d 2023-06-22 thomas echo "Forwarding refs/heads/master to refs/heads/newbranch" \
446 2b72f32d 2023-06-22 thomas > $testroot/stdout.expected
447 2b72f32d 2023-06-22 thomas echo "U beta" >> $testroot/stdout.expected
448 2b72f32d 2023-06-22 thomas echo "Updated to commit $commit2" \
449 2b72f32d 2023-06-22 thomas >> $testroot/stdout.expected
450 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
451 fc414659 2022-04-16 thomas ret=$?
452 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
453 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
454 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
455 2b72f32d 2023-06-22 thomas return 1
456 10604dce 2021-09-24 thomas fi
457 2b72f32d 2023-06-22 thomas
458 2b72f32d 2023-06-22 thomas (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
459 2b72f32d 2023-06-22 thomas echo -n "commit $commit2 " > $testroot/stdout.expected
460 2b72f32d 2023-06-22 thomas echo "(master, newbranch)" >> $testroot/stdout.expected
461 2b72f32d 2023-06-22 thomas echo "commit $commit1" >> $testroot/stdout.expected
462 2b72f32d 2023-06-22 thomas echo "commit $commit0" >> $testroot/stdout.expected
463 31009ade 2023-07-05 thomas cmp -s $testroot/stdout.expected $testroot/stdout
464 31009ade 2023-07-05 thomas ret=$?
465 31009ade 2023-07-05 thomas if [ $ret -ne 0 ]; then
466 31009ade 2023-07-05 thomas diff -u $testroot/stdout.expected $testroot/stdout
467 31009ade 2023-07-05 thomas test_done "$testroot" "$ret"
468 31009ade 2023-07-05 thomas return 1
469 31009ade 2023-07-05 thomas fi
470 31009ade 2023-07-05 thomas test_done "$testroot" "$ret"
471 31009ade 2023-07-05 thomas }
472 31009ade 2023-07-05 thomas
473 31009ade 2023-07-05 thomas test_merge_forward_commit() {
474 31009ade 2023-07-05 thomas local testroot=`test_init merge_forward_commit`
475 31009ade 2023-07-05 thomas local commit0=`git_show_head $testroot/repo`
476 31009ade 2023-07-05 thomas
477 31009ade 2023-07-05 thomas (cd $testroot/repo && git checkout -q -b newbranch)
478 31009ade 2023-07-05 thomas echo "modified alpha on branch" > $testroot/repo/alpha
479 31009ade 2023-07-05 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
480 31009ade 2023-07-05 thomas local commit1=`git_show_head $testroot/repo`
481 31009ade 2023-07-05 thomas
482 31009ade 2023-07-05 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
483 31009ade 2023-07-05 thomas ret=$?
484 31009ade 2023-07-05 thomas if [ $ret -ne 0 ]; then
485 31009ade 2023-07-05 thomas echo "got checkout failed unexpectedly" >&2
486 31009ade 2023-07-05 thomas test_done "$testroot" "$ret"
487 31009ade 2023-07-05 thomas return 1
488 31009ade 2023-07-05 thomas fi
489 31009ade 2023-07-05 thomas
490 31009ade 2023-07-05 thomas (cd $testroot/wt && got merge -M newbranch > $testroot/stdout)
491 31009ade 2023-07-05 thomas ret=$?
492 31009ade 2023-07-05 thomas if [ $ret -ne 0 ]; then
493 31009ade 2023-07-05 thomas echo "got merge failed unexpectedly" >&2
494 31009ade 2023-07-05 thomas test_done "$testroot" "$ret"
495 31009ade 2023-07-05 thomas return 1
496 31009ade 2023-07-05 thomas fi
497 31009ade 2023-07-05 thomas
498 31009ade 2023-07-05 thomas local merge_commit=`git_show_branch_head $testroot/repo master`
499 31009ade 2023-07-05 thomas
500 31009ade 2023-07-05 thomas echo "G alpha" >> $testroot/stdout.expected
501 31009ade 2023-07-05 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
502 31009ade 2023-07-05 thomas >> $testroot/stdout.expected
503 31009ade 2023-07-05 thomas echo $merge_commit >> $testroot/stdout.expected
504 31009ade 2023-07-05 thomas
505 31009ade 2023-07-05 thomas cmp -s $testroot/stdout.expected $testroot/stdout
506 31009ade 2023-07-05 thomas ret=$?
507 31009ade 2023-07-05 thomas if [ $ret -ne 0 ]; then
508 31009ade 2023-07-05 thomas diff -u $testroot/stdout.expected $testroot/stdout
509 31009ade 2023-07-05 thomas test_done "$testroot" "$ret"
510 31009ade 2023-07-05 thomas return 1
511 31009ade 2023-07-05 thomas fi
512 31009ade 2023-07-05 thomas
513 31009ade 2023-07-05 thomas # We should have created a merge commit with two parents.
514 31009ade 2023-07-05 thomas (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
515 31009ade 2023-07-05 thomas echo "parent 1: $commit0" > $testroot/stdout.expected
516 31009ade 2023-07-05 thomas echo "parent 2: $commit1" >> $testroot/stdout.expected
517 31009ade 2023-07-05 thomas cmp -s $testroot/stdout.expected $testroot/stdout
518 31009ade 2023-07-05 thomas ret=$?
519 31009ade 2023-07-05 thomas if [ $ret -ne 0 ]; then
520 31009ade 2023-07-05 thomas diff -u $testroot/stdout.expected $testroot/stdout
521 31009ade 2023-07-05 thomas test_done "$testroot" "$ret"
522 31009ade 2023-07-05 thomas return 1
523 31009ade 2023-07-05 thomas fi
524 31009ade 2023-07-05 thomas
525 31009ade 2023-07-05 thomas test_done "$testroot" "$ret"
526 31009ade 2023-07-05 thomas }
527 31009ade 2023-07-05 thomas
528 31009ade 2023-07-05 thomas test_merge_forward_interrupt() {
529 31009ade 2023-07-05 thomas # Test -M and -n options together.
530 31009ade 2023-07-05 thomas local testroot=`test_init merge_forward_commit`
531 31009ade 2023-07-05 thomas local commit0=`git_show_head $testroot/repo`
532 31009ade 2023-07-05 thomas
533 31009ade 2023-07-05 thomas (cd $testroot/repo && git checkout -q -b newbranch)
534 31009ade 2023-07-05 thomas echo "modified alpha on branch" > $testroot/repo/alpha
535 31009ade 2023-07-05 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
536 31009ade 2023-07-05 thomas local commit1=`git_show_head $testroot/repo`
537 31009ade 2023-07-05 thomas
538 31009ade 2023-07-05 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
539 31009ade 2023-07-05 thomas ret=$?
540 31009ade 2023-07-05 thomas if [ $ret -ne 0 ]; then
541 31009ade 2023-07-05 thomas echo "got checkout failed unexpectedly" >&2
542 31009ade 2023-07-05 thomas test_done "$testroot" "$ret"
543 31009ade 2023-07-05 thomas return 1
544 31009ade 2023-07-05 thomas fi
545 31009ade 2023-07-05 thomas
546 31009ade 2023-07-05 thomas (cd $testroot/wt && got merge -M -n newbranch > $testroot/stdout)
547 31009ade 2023-07-05 thomas ret=$?
548 31009ade 2023-07-05 thomas if [ $ret -ne 0 ]; then
549 31009ade 2023-07-05 thomas echo "got merge failed unexpectedly" >&2
550 31009ade 2023-07-05 thomas test_done "$testroot" "$ret"
551 31009ade 2023-07-05 thomas return 1
552 31009ade 2023-07-05 thomas fi
553 31009ade 2023-07-05 thomas
554 31009ade 2023-07-05 thomas echo "G alpha" > $testroot/stdout.expected
555 31009ade 2023-07-05 thomas echo "Merge of refs/heads/newbranch interrupted on request" \
556 31009ade 2023-07-05 thomas >> $testroot/stdout.expected
557 31009ade 2023-07-05 thomas cmp -s $testroot/stdout.expected $testroot/stdout
558 31009ade 2023-07-05 thomas ret=$?
559 31009ade 2023-07-05 thomas if [ $ret -ne 0 ]; then
560 31009ade 2023-07-05 thomas diff -u $testroot/stdout.expected $testroot/stdout
561 31009ade 2023-07-05 thomas test_done "$testroot" "$ret"
562 31009ade 2023-07-05 thomas return 1
563 31009ade 2023-07-05 thomas fi
564 31009ade 2023-07-05 thomas
565 31009ade 2023-07-05 thomas # Continue the merge.
566 31009ade 2023-07-05 thomas (cd $testroot/wt && got merge -c > $testroot/stdout)
567 31009ade 2023-07-05 thomas ret=$?
568 31009ade 2023-07-05 thomas if [ $ret -ne 0 ]; then
569 31009ade 2023-07-05 thomas echo "got merge failed unexpectedly" >&2
570 31009ade 2023-07-05 thomas test_done "$testroot" "$ret"
571 31009ade 2023-07-05 thomas return 1
572 31009ade 2023-07-05 thomas fi
573 31009ade 2023-07-05 thomas
574 31009ade 2023-07-05 thomas local merge_commit=`git_show_branch_head $testroot/repo master`
575 31009ade 2023-07-05 thomas
576 31009ade 2023-07-05 thomas echo "M alpha" > $testroot/stdout.expected
577 31009ade 2023-07-05 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
578 31009ade 2023-07-05 thomas >> $testroot/stdout.expected
579 31009ade 2023-07-05 thomas echo $merge_commit >> $testroot/stdout.expected
580 31009ade 2023-07-05 thomas
581 2b72f32d 2023-06-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
582 2b72f32d 2023-06-22 thomas ret=$?
583 2b72f32d 2023-06-22 thomas if [ $ret -ne 0 ]; then
584 2b72f32d 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
585 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
586 2b72f32d 2023-06-22 thomas return 1
587 2b72f32d 2023-06-22 thomas fi
588 31009ade 2023-07-05 thomas
589 31009ade 2023-07-05 thomas # We should have created a merge commit with two parents.
590 31009ade 2023-07-05 thomas (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
591 31009ade 2023-07-05 thomas echo "parent 1: $commit0" > $testroot/stdout.expected
592 31009ade 2023-07-05 thomas echo "parent 2: $commit1" >> $testroot/stdout.expected
593 31009ade 2023-07-05 thomas cmp -s $testroot/stdout.expected $testroot/stdout
594 31009ade 2023-07-05 thomas ret=$?
595 31009ade 2023-07-05 thomas if [ $ret -ne 0 ]; then
596 31009ade 2023-07-05 thomas diff -u $testroot/stdout.expected $testroot/stdout
597 31009ade 2023-07-05 thomas fi
598 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
599 2b72f32d 2023-06-22 thomas }
600 2b72f32d 2023-06-22 thomas
601 2b72f32d 2023-06-22 thomas test_merge_backward() {
602 2b72f32d 2023-06-22 thomas local testroot=`test_init merge_backward`
603 2b72f32d 2023-06-22 thomas local commit0=`git_show_head $testroot/repo`
604 2b72f32d 2023-06-22 thomas
605 2b72f32d 2023-06-22 thomas (cd $testroot/repo && git checkout -q -b newbranch)
606 2b72f32d 2023-06-22 thomas (cd $testroot/repo && git checkout -q master)
607 2b72f32d 2023-06-22 thomas echo "modified alpha on master" > $testroot/repo/alpha
608 2b72f32d 2023-06-22 thomas git_commit $testroot/repo -m "committing to alpha on master"
609 2b72f32d 2023-06-22 thomas
610 2b72f32d 2023-06-22 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
611 2b72f32d 2023-06-22 thomas ret=$?
612 2b72f32d 2023-06-22 thomas if [ $ret -ne 0 ]; then
613 2b72f32d 2023-06-22 thomas echo "got checkout failed unexpectedly" >&2
614 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
615 2b72f32d 2023-06-22 thomas return 1
616 2b72f32d 2023-06-22 thomas fi
617 2b72f32d 2023-06-22 thomas
618 2b72f32d 2023-06-22 thomas (cd $testroot/wt && got merge newbranch \
619 2b72f32d 2023-06-22 thomas > $testroot/stdout 2> $testroot/stderr)
620 2b72f32d 2023-06-22 thomas ret=$?
621 2b72f32d 2023-06-22 thomas if [ $ret -ne 0 ]; then
622 2b72f32d 2023-06-22 thomas echo "got merge failed unexpectedly" >&2
623 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
624 2b72f32d 2023-06-22 thomas return 1
625 2b72f32d 2023-06-22 thomas fi
626 2b72f32d 2023-06-22 thomas echo "Already up-to-date" > $testroot/stdout.expected
627 2b72f32d 2023-06-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
628 2b72f32d 2023-06-22 thomas ret=$?
629 2b72f32d 2023-06-22 thomas if [ $ret -ne 0 ]; then
630 2b72f32d 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
631 2b72f32d 2023-06-22 thomas test_done "$testroot" "$ret"
632 2b72f32d 2023-06-22 thomas return 1
633 2b72f32d 2023-06-22 thomas fi
634 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
635 10604dce 2021-09-24 thomas }
636 10604dce 2021-09-24 thomas
637 10604dce 2021-09-24 thomas test_merge_continue() {
638 10604dce 2021-09-24 thomas local testroot=`test_init merge_continue`
639 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
640 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
641 10604dce 2021-09-24 thomas
642 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
643 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
644 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to delta on newbranch"
645 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
646 10604dce 2021-09-24 thomas
647 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
648 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
649 10604dce 2021-09-24 thomas local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
650 10604dce 2021-09-24 thomas (cd $testroot/repo && git rm -q beta)
651 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "removing beta on newbranch"
652 10604dce 2021-09-24 thomas local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
653 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/repo/epsilon/new
654 10604dce 2021-09-24 thomas (cd $testroot/repo && git add epsilon/new)
655 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding new file on newbranch"
656 10604dce 2021-09-24 thomas local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
657 10604dce 2021-09-24 thomas
658 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
659 fc414659 2022-04-16 thomas ret=$?
660 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
661 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
662 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
663 10604dce 2021-09-24 thomas return 1
664 10604dce 2021-09-24 thomas fi
665 10604dce 2021-09-24 thomas
666 10604dce 2021-09-24 thomas # create a conflicting commit
667 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
668 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
669 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
670 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
671 10604dce 2021-09-24 thomas
672 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
673 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
674 fc414659 2022-04-16 thomas ret=$?
675 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
676 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
677 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
678 10604dce 2021-09-24 thomas return 1
679 10604dce 2021-09-24 thomas fi
680 10604dce 2021-09-24 thomas
681 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
682 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
683 fc414659 2022-04-16 thomas ret=$?
684 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
685 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
686 10604dce 2021-09-24 thomas test_done "$testroot" "1"
687 10604dce 2021-09-24 thomas return 1
688 10604dce 2021-09-24 thomas fi
689 10604dce 2021-09-24 thomas
690 10604dce 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
691 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
692 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
693 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
694 10604dce 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
695 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
696 fc414659 2022-04-16 thomas ret=$?
697 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
698 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
699 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
700 10604dce 2021-09-24 thomas return 1
701 10604dce 2021-09-24 thomas fi
702 10604dce 2021-09-24 thomas
703 10604dce 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
704 10604dce 2021-09-24 thomas > $testroot/stderr.expected
705 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
706 fc414659 2022-04-16 thomas ret=$?
707 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
708 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
709 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
710 10604dce 2021-09-24 thomas return 1
711 10604dce 2021-09-24 thomas fi
712 10604dce 2021-09-24 thomas
713 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
714 10604dce 2021-09-24 thomas
715 10604dce 2021-09-24 thomas echo "C alpha" > $testroot/stdout.expected
716 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
717 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
718 10604dce 2021-09-24 thomas echo "M gamma/delta" >> $testroot/stdout.expected
719 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
720 fc414659 2022-04-16 thomas ret=$?
721 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
722 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
723 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
724 10604dce 2021-09-24 thomas return 1
725 10604dce 2021-09-24 thomas fi
726 10604dce 2021-09-24 thomas
727 10604dce 2021-09-24 thomas echo '<<<<<<<' > $testroot/content.expected
728 10604dce 2021-09-24 thomas echo "modified alpha on master" >> $testroot/content.expected
729 10604dce 2021-09-24 thomas echo "||||||| 3-way merge base: commit $commit0" \
730 10604dce 2021-09-24 thomas >> $testroot/content.expected
731 10604dce 2021-09-24 thomas echo "alpha" >> $testroot/content.expected
732 10604dce 2021-09-24 thomas echo "=======" >> $testroot/content.expected
733 10604dce 2021-09-24 thomas echo "modified alpha on branch" >> $testroot/content.expected
734 10604dce 2021-09-24 thomas echo ">>>>>>> merged change: commit $branch_commit3" \
735 10604dce 2021-09-24 thomas >> $testroot/content.expected
736 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
737 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
738 fc414659 2022-04-16 thomas ret=$?
739 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
740 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
741 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
742 10604dce 2021-09-24 thomas return 1
743 10604dce 2021-09-24 thomas fi
744 10604dce 2021-09-24 thomas
745 10604dce 2021-09-24 thomas # resolve the conflict
746 10604dce 2021-09-24 thomas echo "modified alpha by both branches" > $testroot/wt/alpha
747 10604dce 2021-09-24 thomas
748 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge -c > $testroot/stdout)
749 fc414659 2022-04-16 thomas ret=$?
750 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
751 10604dce 2021-09-24 thomas echo "got merge failed unexpectedly" >&2
752 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
753 10604dce 2021-09-24 thomas return 1
754 10604dce 2021-09-24 thomas fi
755 10604dce 2021-09-24 thomas
756 10604dce 2021-09-24 thomas local merge_commit=`git_show_head $testroot/repo`
757 10604dce 2021-09-24 thomas
758 ae1e948a 2021-09-28 thomas echo "M alpha" > $testroot/stdout.expected
759 ae1e948a 2021-09-28 thomas echo "D beta" >> $testroot/stdout.expected
760 ae1e948a 2021-09-28 thomas echo "A epsilon/new" >> $testroot/stdout.expected
761 ae1e948a 2021-09-28 thomas echo "M gamma/delta" >> $testroot/stdout.expected
762 10604dce 2021-09-24 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
763 ae1e948a 2021-09-28 thomas >> $testroot/stdout.expected
764 10604dce 2021-09-24 thomas echo $merge_commit >> $testroot/stdout.expected
765 10604dce 2021-09-24 thomas
766 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
767 fc414659 2022-04-16 thomas ret=$?
768 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
769 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
770 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
771 10604dce 2021-09-24 thomas return 1
772 10604dce 2021-09-24 thomas fi
773 10604dce 2021-09-24 thomas
774 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/content.expected
775 10604dce 2021-09-24 thomas cat $testroot/wt/gamma/delta > $testroot/content
776 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
777 fc414659 2022-04-16 thomas ret=$?
778 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
779 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
780 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
781 10604dce 2021-09-24 thomas return 1
782 10604dce 2021-09-24 thomas fi
783 10604dce 2021-09-24 thomas
784 10604dce 2021-09-24 thomas echo "modified alpha by both branches" > $testroot/content.expected
785 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
786 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
787 fc414659 2022-04-16 thomas ret=$?
788 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
789 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
790 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
791 10604dce 2021-09-24 thomas return 1
792 10604dce 2021-09-24 thomas fi
793 10604dce 2021-09-24 thomas
794 10604dce 2021-09-24 thomas if [ -e $testroot/wt/beta ]; then
795 10604dce 2021-09-24 thomas echo "removed file beta still exists on disk" >&2
796 10604dce 2021-09-24 thomas test_done "$testroot" "1"
797 10604dce 2021-09-24 thomas return 1
798 10604dce 2021-09-24 thomas fi
799 10604dce 2021-09-24 thomas
800 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/content.expected
801 10604dce 2021-09-24 thomas cat $testroot/wt/epsilon/new > $testroot/content
802 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
803 fc414659 2022-04-16 thomas ret=$?
804 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
805 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
806 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
807 10604dce 2021-09-24 thomas return 1
808 10604dce 2021-09-24 thomas fi
809 10604dce 2021-09-24 thomas
810 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
811 10604dce 2021-09-24 thomas
812 10604dce 2021-09-24 thomas echo -n > $testroot/stdout.expected
813 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
814 fc414659 2022-04-16 thomas ret=$?
815 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
816 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
817 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
818 10604dce 2021-09-24 thomas return 1
819 10604dce 2021-09-24 thomas fi
820 10604dce 2021-09-24 thomas
821 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
822 10604dce 2021-09-24 thomas echo "commit $merge_commit (master)" > $testroot/stdout.expected
823 10604dce 2021-09-24 thomas echo "commit $master_commit" >> $testroot/stdout.expected
824 10604dce 2021-09-24 thomas echo "commit $commit0" >> $testroot/stdout.expected
825 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
826 fc414659 2022-04-16 thomas ret=$?
827 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
828 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
829 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
830 10604dce 2021-09-24 thomas return 1
831 10604dce 2021-09-24 thomas fi
832 10604dce 2021-09-24 thomas
833 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > $testroot/stdout)
834 10604dce 2021-09-24 thomas
835 10604dce 2021-09-24 thomas echo 'Already up-to-date' > $testroot/stdout.expected
836 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
837 fc414659 2022-04-16 thomas ret=$?
838 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
839 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
840 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
841 10604dce 2021-09-24 thomas return 1
842 10604dce 2021-09-24 thomas fi
843 10604dce 2021-09-24 thomas
844 10604dce 2021-09-24 thomas # We should have created a merge commit with two parents.
845 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
846 10604dce 2021-09-24 thomas echo "parent 1: $master_commit" > $testroot/stdout.expected
847 10604dce 2021-09-24 thomas echo "parent 2: $branch_commit3" >> $testroot/stdout.expected
848 fe3f264b 2023-06-08 thomas cmp -s $testroot/stdout.expected $testroot/stdout
849 fe3f264b 2023-06-08 thomas ret=$?
850 fe3f264b 2023-06-08 thomas if [ $ret -ne 0 ]; then
851 fe3f264b 2023-06-08 thomas diff -u $testroot/stdout.expected $testroot/stdout
852 fe3f264b 2023-06-08 thomas fi
853 fe3f264b 2023-06-08 thomas test_done "$testroot" "$ret"
854 fe3f264b 2023-06-08 thomas }
855 fe3f264b 2023-06-08 thomas
856 fe3f264b 2023-06-08 thomas test_merge_continue_new_commit() {
857 fe3f264b 2023-06-08 thomas # "got merge -c" should refuse to run if the current branch tip has
858 fe3f264b 2023-06-08 thomas # changed since the merge was started, to avoid clobbering the changes.
859 fe3f264b 2023-06-08 thomas local testroot=`test_init merge_continue_new_commit`
860 fe3f264b 2023-06-08 thomas
861 fe3f264b 2023-06-08 thomas (cd $testroot/repo && git checkout -q -b newbranch)
862 fe3f264b 2023-06-08 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
863 fe3f264b 2023-06-08 thomas git_commit $testroot/repo -m "committing to delta on newbranch"
864 fe3f264b 2023-06-08 thomas
865 fe3f264b 2023-06-08 thomas (cd $testroot/repo && git checkout -q master)
866 fe3f264b 2023-06-08 thomas echo "modified alpha on master" > $testroot/repo/alpha
867 fe3f264b 2023-06-08 thomas git_commit $testroot/repo -m "committing to alpha on master"
868 fe3f264b 2023-06-08 thomas
869 fe3f264b 2023-06-08 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
870 fe3f264b 2023-06-08 thomas ret=$?
871 fe3f264b 2023-06-08 thomas if [ $ret -ne 0 ]; then
872 fe3f264b 2023-06-08 thomas echo "got checkout failed unexpectedly" >&2
873 fe3f264b 2023-06-08 thomas test_done "$testroot" "$ret"
874 fe3f264b 2023-06-08 thomas return 1
875 fe3f264b 2023-06-08 thomas fi
876 fe3f264b 2023-06-08 thomas
877 fe3f264b 2023-06-08 thomas (cd $testroot/wt && got merge -n newbranch >/dev/null)
878 fe3f264b 2023-06-08 thomas ret=$?
879 fe3f264b 2023-06-08 thomas if [ $ret -ne 0 ]; then
880 fe3f264b 2023-06-08 thomas echo "got merge failed unexpectedly" >&2
881 fe3f264b 2023-06-08 thomas test_done "$testroot" "$ret"
882 fe3f264b 2023-06-08 thomas return 1
883 fe3f264b 2023-06-08 thomas fi
884 fe3f264b 2023-06-08 thomas
885 fe3f264b 2023-06-08 thomas echo "modified alpha again on master" > $testroot/repo/alpha
886 fe3f264b 2023-06-08 thomas git_commit $testroot/repo -m "committing to alpha on master again"
887 fe3f264b 2023-06-08 thomas
888 fe3f264b 2023-06-08 thomas (cd $testroot/wt && got merge -c > $testroot/stdout 2> $testroot/stderr)
889 fe3f264b 2023-06-08 thomas ret=$?
890 fe3f264b 2023-06-08 thomas if [ $ret -eq 0 ]; then
891 fe3f264b 2023-06-08 thomas echo "got merge succeeded unexpectedly" >&2
892 fe3f264b 2023-06-08 thomas test_done "$testroot" "1"
893 fe3f264b 2023-06-08 thomas return 1
894 fe3f264b 2023-06-08 thomas fi
895 fe3f264b 2023-06-08 thomas
896 fe3f264b 2023-06-08 thomas echo -n > $testroot/stdout.expected
897 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
898 fc414659 2022-04-16 thomas ret=$?
899 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
900 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
901 fe3f264b 2023-06-08 thomas test_done "$testroot" "$ret"
902 fe3f264b 2023-06-08 thomas return 1
903 fe3f264b 2023-06-08 thomas fi
904 fe3f264b 2023-06-08 thomas
905 fe3f264b 2023-06-08 thomas echo -n "got: merging cannot proceed because the work tree is no " \
906 fe3f264b 2023-06-08 thomas > $testroot/stderr.expected
907 fe3f264b 2023-06-08 thomas echo "longer up-to-date; merge must be aborted and retried" \
908 fe3f264b 2023-06-08 thomas >> $testroot/stderr.expected
909 fe3f264b 2023-06-08 thomas cmp -s $testroot/stderr.expected $testroot/stderr
910 fe3f264b 2023-06-08 thomas ret=$?
911 fe3f264b 2023-06-08 thomas if [ $ret -ne 0 ]; then
912 fe3f264b 2023-06-08 thomas diff -u $testroot/stderr.expected $testroot/stderr
913 10604dce 2021-09-24 thomas fi
914 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
915 10604dce 2021-09-24 thomas }
916 10604dce 2021-09-24 thomas
917 10604dce 2021-09-24 thomas test_merge_abort() {
918 10604dce 2021-09-24 thomas local testroot=`test_init merge_abort`
919 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
920 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
921 10604dce 2021-09-24 thomas
922 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
923 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
924 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to delta on newbranch"
925 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
926 10604dce 2021-09-24 thomas
927 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
928 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
929 10604dce 2021-09-24 thomas local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
930 10604dce 2021-09-24 thomas (cd $testroot/repo && git rm -q beta)
931 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "removing beta on newbranch"
932 10604dce 2021-09-24 thomas local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
933 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/repo/epsilon/new
934 10604dce 2021-09-24 thomas (cd $testroot/repo && git add epsilon/new)
935 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding new file on newbranch"
936 10604dce 2021-09-24 thomas local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
937 10604dce 2021-09-24 thomas (cd $testroot/repo && ln -s alpha symlink && git add symlink)
938 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding symlink on newbranch"
939 10604dce 2021-09-24 thomas local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
940 10604dce 2021-09-24 thomas
941 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
942 fc414659 2022-04-16 thomas ret=$?
943 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
944 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
945 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
946 10604dce 2021-09-24 thomas return 1
947 10604dce 2021-09-24 thomas fi
948 d52bac28 2021-10-08 thomas
949 d52bac28 2021-10-08 thomas # unrelated unversioned file in work tree
950 d52bac28 2021-10-08 thomas touch $testroot/wt/unversioned-file
951 10604dce 2021-09-24 thomas
952 10604dce 2021-09-24 thomas # create a conflicting commit
953 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
954 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
955 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
956 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
957 10604dce 2021-09-24 thomas
958 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
959 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
960 fc414659 2022-04-16 thomas ret=$?
961 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
962 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
963 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
964 10604dce 2021-09-24 thomas return 1
965 10604dce 2021-09-24 thomas fi
966 10604dce 2021-09-24 thomas
967 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
968 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
969 fc414659 2022-04-16 thomas ret=$?
970 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
971 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
972 10604dce 2021-09-24 thomas test_done "$testroot" "1"
973 10604dce 2021-09-24 thomas return 1
974 10604dce 2021-09-24 thomas fi
975 10604dce 2021-09-24 thomas
976 10604dce 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
977 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
978 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
979 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
980 10604dce 2021-09-24 thomas echo "A symlink" >> $testroot/stdout.expected
981 10604dce 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
982 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
983 fc414659 2022-04-16 thomas ret=$?
984 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
985 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
986 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
987 10604dce 2021-09-24 thomas return 1
988 10604dce 2021-09-24 thomas fi
989 10604dce 2021-09-24 thomas
990 10604dce 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
991 10604dce 2021-09-24 thomas > $testroot/stderr.expected
992 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
993 fc414659 2022-04-16 thomas ret=$?
994 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
995 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
996 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
997 10604dce 2021-09-24 thomas return 1
998 10604dce 2021-09-24 thomas fi
999 8641a332 2023-04-14 thomas
1000 8641a332 2023-04-14 thomas # unrelated added file added during conflict resolution
1001 8641a332 2023-04-14 thomas touch $testroot/wt/added-file
1002 8641a332 2023-04-14 thomas (cd $testroot/wt && got add added-file > /dev/null)
1003 10604dce 2021-09-24 thomas
1004 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1005 10604dce 2021-09-24 thomas
1006 8641a332 2023-04-14 thomas echo "A added-file" > $testroot/stdout.expected
1007 8641a332 2023-04-14 thomas echo "C alpha" >> $testroot/stdout.expected
1008 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
1009 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
1010 10604dce 2021-09-24 thomas echo "M gamma/delta" >> $testroot/stdout.expected
1011 10604dce 2021-09-24 thomas echo "A symlink" >> $testroot/stdout.expected
1012 d52bac28 2021-10-08 thomas echo "? unversioned-file" >> $testroot/stdout.expected
1013 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1014 fc414659 2022-04-16 thomas ret=$?
1015 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1016 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1017 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1018 10604dce 2021-09-24 thomas return 1
1019 10604dce 2021-09-24 thomas fi
1020 10604dce 2021-09-24 thomas
1021 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge -a > $testroot/stdout)
1022 fc414659 2022-04-16 thomas ret=$?
1023 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1024 10604dce 2021-09-24 thomas echo "got merge failed unexpectedly" >&2
1025 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1026 10604dce 2021-09-24 thomas return 1
1027 10604dce 2021-09-24 thomas fi
1028 10604dce 2021-09-24 thomas
1029 8641a332 2023-04-14 thomas echo "R added-file" > $testroot/stdout.expected
1030 8641a332 2023-04-14 thomas echo "R alpha" >> $testroot/stdout.expected
1031 10604dce 2021-09-24 thomas echo "R beta" >> $testroot/stdout.expected
1032 10604dce 2021-09-24 thomas echo "R epsilon/new" >> $testroot/stdout.expected
1033 10604dce 2021-09-24 thomas echo "R gamma/delta" >> $testroot/stdout.expected
1034 10604dce 2021-09-24 thomas echo "R symlink" >> $testroot/stdout.expected
1035 8641a332 2023-04-14 thomas echo "G added-file" >> $testroot/stdout.expected
1036 10604dce 2021-09-24 thomas echo "Merge of refs/heads/newbranch aborted" \
1037 10604dce 2021-09-24 thomas >> $testroot/stdout.expected
1038 10604dce 2021-09-24 thomas
1039 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1040 fc414659 2022-04-16 thomas ret=$?
1041 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1042 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1043 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1044 10604dce 2021-09-24 thomas return 1
1045 10604dce 2021-09-24 thomas fi
1046 10604dce 2021-09-24 thomas
1047 10604dce 2021-09-24 thomas echo "delta" > $testroot/content.expected
1048 10604dce 2021-09-24 thomas cat $testroot/wt/gamma/delta > $testroot/content
1049 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
1050 fc414659 2022-04-16 thomas ret=$?
1051 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1052 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
1053 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1054 10604dce 2021-09-24 thomas return 1
1055 10604dce 2021-09-24 thomas fi
1056 10604dce 2021-09-24 thomas
1057 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/content.expected
1058 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
1059 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
1060 fc414659 2022-04-16 thomas ret=$?
1061 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1062 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
1063 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1064 10604dce 2021-09-24 thomas return 1
1065 10604dce 2021-09-24 thomas fi
1066 10604dce 2021-09-24 thomas
1067 10604dce 2021-09-24 thomas echo "beta" > $testroot/content.expected
1068 10604dce 2021-09-24 thomas cat $testroot/wt/beta > $testroot/content
1069 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
1070 fc414659 2022-04-16 thomas ret=$?
1071 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1072 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
1073 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1074 10604dce 2021-09-24 thomas return 1
1075 10604dce 2021-09-24 thomas fi
1076 10604dce 2021-09-24 thomas
1077 10604dce 2021-09-24 thomas if [ -e $testroot/wt/epsilon/new ]; then
1078 10604dce 2021-09-24 thomas echo "reverted file epsilon/new still exists on disk" >&2
1079 10604dce 2021-09-24 thomas test_done "$testroot" "1"
1080 10604dce 2021-09-24 thomas return 1
1081 10604dce 2021-09-24 thomas fi
1082 10604dce 2021-09-24 thomas
1083 10604dce 2021-09-24 thomas if [ -e $testroot/wt/symlink ]; then
1084 10604dce 2021-09-24 thomas echo "reverted symlink still exists on disk" >&2
1085 10604dce 2021-09-24 thomas test_done "$testroot" "1"
1086 10604dce 2021-09-24 thomas return 1
1087 10604dce 2021-09-24 thomas fi
1088 10604dce 2021-09-24 thomas
1089 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1090 10604dce 2021-09-24 thomas
1091 8641a332 2023-04-14 thomas echo "? added-file" > $testroot/stdout.expected
1092 8641a332 2023-04-14 thomas echo "? unversioned-file" >> $testroot/stdout.expected
1093 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1094 fc414659 2022-04-16 thomas ret=$?
1095 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1096 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1097 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1098 10604dce 2021-09-24 thomas return 1
1099 10604dce 2021-09-24 thomas fi
1100 10604dce 2021-09-24 thomas
1101 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1102 10604dce 2021-09-24 thomas echo "commit $master_commit (master)" > $testroot/stdout.expected
1103 10604dce 2021-09-24 thomas echo "commit $commit0" >> $testroot/stdout.expected
1104 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1105 fc414659 2022-04-16 thomas ret=$?
1106 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1107 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1108 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1109 10604dce 2021-09-24 thomas return 1
1110 10604dce 2021-09-24 thomas fi
1111 10604dce 2021-09-24 thomas
1112 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > $testroot/stdout)
1113 10604dce 2021-09-24 thomas
1114 10604dce 2021-09-24 thomas echo 'Already up-to-date' > $testroot/stdout.expected
1115 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1116 fc414659 2022-04-16 thomas ret=$?
1117 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1118 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1119 10604dce 2021-09-24 thomas fi
1120 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1121 10604dce 2021-09-24 thomas }
1122 10604dce 2021-09-24 thomas
1123 10604dce 2021-09-24 thomas test_merge_in_progress() {
1124 10604dce 2021-09-24 thomas local testroot=`test_init merge_in_progress`
1125 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
1126 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1127 10604dce 2021-09-24 thomas
1128 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
1129 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
1130 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
1131 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1132 10604dce 2021-09-24 thomas
1133 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
1134 fc414659 2022-04-16 thomas ret=$?
1135 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1136 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
1137 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1138 10604dce 2021-09-24 thomas return 1
1139 10604dce 2021-09-24 thomas fi
1140 10604dce 2021-09-24 thomas
1141 10604dce 2021-09-24 thomas # create a conflicting commit
1142 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
1143 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
1144 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
1145 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
1146 10604dce 2021-09-24 thomas
1147 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
1148 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
1149 fc414659 2022-04-16 thomas ret=$?
1150 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1151 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
1152 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1153 10604dce 2021-09-24 thomas return 1
1154 10604dce 2021-09-24 thomas fi
1155 10604dce 2021-09-24 thomas
1156 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
1157 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
1158 fc414659 2022-04-16 thomas ret=$?
1159 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
1160 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
1161 10604dce 2021-09-24 thomas test_done "$testroot" "1"
1162 10604dce 2021-09-24 thomas return 1
1163 10604dce 2021-09-24 thomas fi
1164 10604dce 2021-09-24 thomas
1165 10604dce 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
1166 10604dce 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1167 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1168 fc414659 2022-04-16 thomas ret=$?
1169 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1170 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1171 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1172 10604dce 2021-09-24 thomas return 1
1173 10604dce 2021-09-24 thomas fi
1174 10604dce 2021-09-24 thomas
1175 10604dce 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
1176 10604dce 2021-09-24 thomas > $testroot/stderr.expected
1177 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1178 fc414659 2022-04-16 thomas ret=$?
1179 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1180 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1181 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1182 10604dce 2021-09-24 thomas return 1
1183 10604dce 2021-09-24 thomas fi
1184 10604dce 2021-09-24 thomas
1185 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1186 10604dce 2021-09-24 thomas
1187 10604dce 2021-09-24 thomas echo "C alpha" > $testroot/stdout.expected
1188 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1189 fc414659 2022-04-16 thomas ret=$?
1190 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1191 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1192 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1193 10604dce 2021-09-24 thomas return 1
1194 10604dce 2021-09-24 thomas fi
1195 10604dce 2021-09-24 thomas
1196 10604dce 2021-09-24 thomas for cmd in update commit histedit "rebase newbranch" \
1197 d8a7bd7d 2023-06-01 thomas "integrate newbranch" "merge newbranch" "stage alpha"; do
1198 10604dce 2021-09-24 thomas (cd $testroot/wt && got $cmd > $testroot/stdout \
1199 10604dce 2021-09-24 thomas 2> $testroot/stderr)
1200 d8a7bd7d 2023-06-01 thomas ret=$?
1201 d8a7bd7d 2023-06-01 thomas if [ $ret -eq 0 ]; then
1202 d8a7bd7d 2023-06-01 thomas echo "got $cmd succeeded unexpectedly" >&2
1203 d8a7bd7d 2023-06-01 thomas test_done "$testroot" "1"
1204 d8a7bd7d 2023-06-01 thomas return 1
1205 d8a7bd7d 2023-06-01 thomas fi
1206 10604dce 2021-09-24 thomas
1207 10604dce 2021-09-24 thomas echo -n > $testroot/stdout.expected
1208 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1209 fc414659 2022-04-16 thomas ret=$?
1210 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1211 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1212 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1213 10604dce 2021-09-24 thomas return 1
1214 10604dce 2021-09-24 thomas fi
1215 10604dce 2021-09-24 thomas
1216 10604dce 2021-09-24 thomas echo -n "got: a merge operation is in progress in this " \
1217 10604dce 2021-09-24 thomas > $testroot/stderr.expected
1218 10604dce 2021-09-24 thomas echo "work tree and must be continued or aborted first" \
1219 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
1220 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1221 fc414659 2022-04-16 thomas ret=$?
1222 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1223 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1224 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1225 10604dce 2021-09-24 thomas return 1
1226 10604dce 2021-09-24 thomas fi
1227 10604dce 2021-09-24 thomas done
1228 10604dce 2021-09-24 thomas
1229 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1230 10604dce 2021-09-24 thomas }
1231 10604dce 2021-09-24 thomas
1232 10604dce 2021-09-24 thomas test_merge_path_prefix() {
1233 10604dce 2021-09-24 thomas local testroot=`test_init merge_path_prefix`
1234 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
1235 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1236 10604dce 2021-09-24 thomas
1237 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
1238 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
1239 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
1240 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1241 10604dce 2021-09-24 thomas
1242 10604dce 2021-09-24 thomas got checkout -p epsilon -b master $testroot/repo $testroot/wt \
1243 10604dce 2021-09-24 thomas > /dev/null
1244 fc414659 2022-04-16 thomas ret=$?
1245 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1246 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
1247 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1248 10604dce 2021-09-24 thomas return 1
1249 10604dce 2021-09-24 thomas fi
1250 10604dce 2021-09-24 thomas
1251 10604dce 2021-09-24 thomas # create a conflicting commit
1252 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
1253 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
1254 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
1255 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
1256 10604dce 2021-09-24 thomas
1257 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
1258 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
1259 fc414659 2022-04-16 thomas ret=$?
1260 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1261 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
1262 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1263 10604dce 2021-09-24 thomas return 1
1264 10604dce 2021-09-24 thomas fi
1265 10604dce 2021-09-24 thomas
1266 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
1267 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
1268 fc414659 2022-04-16 thomas ret=$?
1269 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
1270 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
1271 10604dce 2021-09-24 thomas test_done "$testroot" "1"
1272 10604dce 2021-09-24 thomas return 1
1273 10604dce 2021-09-24 thomas fi
1274 10604dce 2021-09-24 thomas
1275 10604dce 2021-09-24 thomas echo -n "got: cannot merge branch which contains changes outside " \
1276 10604dce 2021-09-24 thomas > $testroot/stderr.expected
1277 10604dce 2021-09-24 thomas echo "of this work tree's path prefix" >> $testroot/stderr.expected
1278 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1279 fc414659 2022-04-16 thomas ret=$?
1280 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1281 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1282 10604dce 2021-09-24 thomas fi
1283 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1284 10604dce 2021-09-24 thomas }
1285 10604dce 2021-09-24 thomas
1286 10604dce 2021-09-24 thomas test_merge_missing_file() {
1287 10604dce 2021-09-24 thomas local testroot=`test_init merge_missing_file`
1288 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
1289 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1290 10604dce 2021-09-24 thomas
1291 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
1292 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
1293 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
1294 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha and delta"
1295 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1296 10604dce 2021-09-24 thomas
1297 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
1298 fc414659 2022-04-16 thomas ret=$?
1299 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1300 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
1301 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1302 10604dce 2021-09-24 thomas return 1
1303 10604dce 2021-09-24 thomas fi
1304 10604dce 2021-09-24 thomas
1305 10604dce 2021-09-24 thomas # create a conflicting commit which renames alpha
1306 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
1307 10604dce 2021-09-24 thomas (cd $testroot/repo && git mv alpha epsilon/alpha-moved)
1308 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "moving alpha on master"
1309 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
1310 10604dce 2021-09-24 thomas
1311 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
1312 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
1313 fc414659 2022-04-16 thomas ret=$?
1314 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1315 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
1316 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1317 10604dce 2021-09-24 thomas return 1
1318 10604dce 2021-09-24 thomas fi
1319 10604dce 2021-09-24 thomas
1320 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
1321 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
1322 fc414659 2022-04-16 thomas ret=$?
1323 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
1324 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
1325 10604dce 2021-09-24 thomas test_done "$testroot" "1"
1326 10604dce 2021-09-24 thomas return 1
1327 10604dce 2021-09-24 thomas fi
1328 10604dce 2021-09-24 thomas
1329 10604dce 2021-09-24 thomas echo "! alpha" > $testroot/stdout.expected
1330 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
1331 0ef68859 2021-09-28 thomas echo -n "Files which had incoming changes but could not be found " \
1332 0ef68859 2021-09-28 thomas >> $testroot/stdout.expected
1333 0ef68859 2021-09-28 thomas echo "in the work tree: 1" >> $testroot/stdout.expected
1334 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1335 fc414659 2022-04-16 thomas ret=$?
1336 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1337 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1338 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1339 10604dce 2021-09-24 thomas return 1
1340 10604dce 2021-09-24 thomas fi
1341 10604dce 2021-09-24 thomas
1342 ba162991 2021-09-28 thomas echo -n "got: changes destined for some files " \
1343 10604dce 2021-09-24 thomas > $testroot/stderr.expected
1344 10604dce 2021-09-24 thomas echo -n "were not yet merged and should be merged manually if " \
1345 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
1346 10604dce 2021-09-24 thomas echo "required before the merge operation is continued" \
1347 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
1348 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1349 fc414659 2022-04-16 thomas ret=$?
1350 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1351 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1352 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1353 10604dce 2021-09-24 thomas return 1
1354 10604dce 2021-09-24 thomas fi
1355 10604dce 2021-09-24 thomas
1356 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1357 10604dce 2021-09-24 thomas
1358 10604dce 2021-09-24 thomas echo "M gamma/delta" > $testroot/stdout.expected
1359 2d7ce510 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1360 fc414659 2022-04-16 thomas ret=$?
1361 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1362 2d7ce510 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1363 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1364 2d7ce510 2021-09-24 thomas return 1
1365 2d7ce510 2021-09-24 thomas fi
1366 2d7ce510 2021-09-24 thomas
1367 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1368 2d7ce510 2021-09-24 thomas }
1369 2d7ce510 2021-09-24 thomas
1370 2d7ce510 2021-09-24 thomas test_merge_no_op() {
1371 2d7ce510 2021-09-24 thomas local testroot=`test_init merge_no_op`
1372 2d7ce510 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
1373 2d7ce510 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1374 2d7ce510 2021-09-24 thomas
1375 2d7ce510 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
1376 2d7ce510 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
1377 2d7ce510 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
1378 1678610c 2023-04-22 thomas local branch_commit=`git_show_branch_head $testroot/repo newbranch`
1379 2d7ce510 2021-09-24 thomas
1380 2d7ce510 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
1381 fc414659 2022-04-16 thomas ret=$?
1382 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1383 2d7ce510 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
1384 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1385 2d7ce510 2021-09-24 thomas return 1
1386 2d7ce510 2021-09-24 thomas fi
1387 2d7ce510 2021-09-24 thomas
1388 2d7ce510 2021-09-24 thomas # create a conflicting commit
1389 2d7ce510 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
1390 2d7ce510 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
1391 2d7ce510 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
1392 2d7ce510 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
1393 2d7ce510 2021-09-24 thomas
1394 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
1395 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
1396 fc414659 2022-04-16 thomas ret=$?
1397 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1398 2d7ce510 2021-09-24 thomas echo "got update failed unexpectedly" >&2
1399 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1400 2d7ce510 2021-09-24 thomas return 1
1401 2d7ce510 2021-09-24 thomas fi
1402 2d7ce510 2021-09-24 thomas
1403 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
1404 2d7ce510 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
1405 fc414659 2022-04-16 thomas ret=$?
1406 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
1407 2d7ce510 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
1408 2d7ce510 2021-09-24 thomas test_done "$testroot" "1"
1409 2d7ce510 2021-09-24 thomas return 1
1410 2d7ce510 2021-09-24 thomas fi
1411 2d7ce510 2021-09-24 thomas
1412 2d7ce510 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
1413 2d7ce510 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1414 2d7ce510 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1415 fc414659 2022-04-16 thomas ret=$?
1416 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1417 2d7ce510 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1418 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1419 2d7ce510 2021-09-24 thomas return 1
1420 2d7ce510 2021-09-24 thomas fi
1421 2d7ce510 2021-09-24 thomas
1422 2d7ce510 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
1423 2d7ce510 2021-09-24 thomas > $testroot/stderr.expected
1424 2d7ce510 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1425 fc414659 2022-04-16 thomas ret=$?
1426 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1427 2d7ce510 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1428 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1429 2d7ce510 2021-09-24 thomas return 1
1430 2d7ce510 2021-09-24 thomas fi
1431 2d7ce510 2021-09-24 thomas
1432 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1433 2d7ce510 2021-09-24 thomas
1434 2d7ce510 2021-09-24 thomas echo "C alpha" > $testroot/stdout.expected
1435 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1436 fc414659 2022-04-16 thomas ret=$?
1437 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1438 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1439 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1440 10604dce 2021-09-24 thomas return 1
1441 10604dce 2021-09-24 thomas fi
1442 10604dce 2021-09-24 thomas
1443 2d7ce510 2021-09-24 thomas # resolve the conflict by reverting all changes; now it is no-op merge
1444 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got revert alpha > /dev/null)
1445 fc414659 2022-04-16 thomas ret=$?
1446 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1447 2d7ce510 2021-09-24 thomas echo "got revert failed unexpectedly" >&2
1448 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1449 2d7ce510 2021-09-24 thomas return 1
1450 2d7ce510 2021-09-24 thomas fi
1451 2d7ce510 2021-09-24 thomas
1452 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got merge -c > $testroot/stdout \
1453 2d7ce510 2021-09-24 thomas 2> $testroot/stderr)
1454 fc414659 2022-04-16 thomas ret=$?
1455 1678610c 2023-04-22 thomas if [ $ret -ne 0 ]; then
1456 1678610c 2023-04-22 thomas echo "got merge failed unexpectedly" >&2
1457 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1458 2d7ce510 2021-09-24 thomas return 1
1459 2d7ce510 2021-09-24 thomas fi
1460 2d7ce510 2021-09-24 thomas
1461 1678610c 2023-04-22 thomas echo -n '' > $testroot/stderr.expected
1462 2d7ce510 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1463 fc414659 2022-04-16 thomas ret=$?
1464 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1465 2d7ce510 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1466 1678610c 2023-04-22 thomas test_done "$testroot" "$ret"
1467 1678610c 2023-04-22 thomas return 1
1468 1678610c 2023-04-22 thomas fi
1469 1678610c 2023-04-22 thomas
1470 1678610c 2023-04-22 thomas local merge_commit=`git_show_head $testroot/repo`
1471 1678610c 2023-04-22 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1472 1678610c 2023-04-22 thomas > $testroot/stdout.expected
1473 1678610c 2023-04-22 thomas echo $merge_commit >> $testroot/stdout.expected
1474 1678610c 2023-04-22 thomas
1475 1678610c 2023-04-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1476 1678610c 2023-04-22 thomas ret=$?
1477 1678610c 2023-04-22 thomas if [ $ret -ne 0 ]; then
1478 1678610c 2023-04-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1479 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1480 2d7ce510 2021-09-24 thomas return 1
1481 2d7ce510 2021-09-24 thomas fi
1482 2d7ce510 2021-09-24 thomas
1483 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1484 2d7ce510 2021-09-24 thomas
1485 2d7ce510 2021-09-24 thomas echo -n "" > $testroot/stdout.expected
1486 768705e3 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1487 fc414659 2022-04-16 thomas ret=$?
1488 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1489 768705e3 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1490 1678610c 2023-04-22 thomas test_done "$testroot" "$ret"
1491 1678610c 2023-04-22 thomas return 1
1492 768705e3 2021-09-27 thomas fi
1493 1678610c 2023-04-22 thomas
1494 1678610c 2023-04-22 thomas # We should have created a merge commit with two parents.
1495 1678610c 2023-04-22 thomas got log -r $testroot/repo -l1 -c $merge_commit | grep ^parent \
1496 1678610c 2023-04-22 thomas > $testroot/stdout
1497 1678610c 2023-04-22 thomas echo "parent 1: $master_commit" > $testroot/stdout.expected
1498 1678610c 2023-04-22 thomas echo "parent 2: $branch_commit" >> $testroot/stdout.expected
1499 1678610c 2023-04-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1500 1678610c 2023-04-22 thomas ret=$?
1501 1678610c 2023-04-22 thomas if [ $ret -ne 0 ]; then
1502 1678610c 2023-04-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1503 1678610c 2023-04-22 thomas fi
1504 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1505 768705e3 2021-09-27 thomas }
1506 768705e3 2021-09-27 thomas
1507 768705e3 2021-09-27 thomas test_merge_imported_branch() {
1508 768705e3 2021-09-27 thomas local testroot=`test_init merge_import`
1509 768705e3 2021-09-27 thomas local commit0=`git_show_head $testroot/repo`
1510 768705e3 2021-09-27 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1511 768705e3 2021-09-27 thomas
1512 768705e3 2021-09-27 thomas # import a new sub-tree to the 'files' branch such that
1513 768705e3 2021-09-27 thomas # none of the files added here collide with existing ones
1514 768705e3 2021-09-27 thomas mkdir -p $testroot/tree/there
1515 768705e3 2021-09-27 thomas mkdir -p $testroot/tree/be/lots
1516 768705e3 2021-09-27 thomas mkdir -p $testroot/tree/files
1517 768705e3 2021-09-27 thomas echo "there should" > $testroot/tree/there/should
1518 768705e3 2021-09-27 thomas echo "be lots of" > $testroot/tree/be/lots/of
1519 768705e3 2021-09-27 thomas echo "files here" > $testroot/tree/files/here
1520 768705e3 2021-09-27 thomas got import -r $testroot/repo -b files -m 'import files' \
1521 768705e3 2021-09-27 thomas $testroot/tree > /dev/null
1522 768705e3 2021-09-27 thomas
1523 768705e3 2021-09-27 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
1524 fc414659 2022-04-16 thomas ret=$?
1525 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1526 768705e3 2021-09-27 thomas echo "got checkout failed unexpectedly" >&2
1527 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1528 768705e3 2021-09-27 thomas return 1
1529 768705e3 2021-09-27 thomas fi
1530 768705e3 2021-09-27 thomas
1531 768705e3 2021-09-27 thomas (cd $testroot/wt && got merge files > $testroot/stdout)
1532 fc414659 2022-04-16 thomas ret=$?
1533 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1534 768705e3 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1535 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1536 768705e3 2021-09-27 thomas return 1
1537 768705e3 2021-09-27 thomas fi
1538 768705e3 2021-09-27 thomas
1539 768705e3 2021-09-27 thomas local merge_commit0=`git_show_head $testroot/repo`
1540 768705e3 2021-09-27 thomas cat > $testroot/stdout.expected <<EOF
1541 768705e3 2021-09-27 thomas A be/lots/of
1542 768705e3 2021-09-27 thomas A files/here
1543 768705e3 2021-09-27 thomas A there/should
1544 768705e3 2021-09-27 thomas Merged refs/heads/files into refs/heads/master: $merge_commit0
1545 768705e3 2021-09-27 thomas EOF
1546 768705e3 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1547 fc414659 2022-04-16 thomas ret=$?
1548 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1549 768705e3 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1550 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1551 768705e3 2021-09-27 thomas return 1
1552 768705e3 2021-09-27 thomas fi
1553 768705e3 2021-09-27 thomas
1554 768705e3 2021-09-27 thomas # try to merge again while no new changes are available
1555 768705e3 2021-09-27 thomas (cd $testroot/wt && got merge files > $testroot/stdout)
1556 fc414659 2022-04-16 thomas ret=$?
1557 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1558 768705e3 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1559 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1560 768705e3 2021-09-27 thomas return 1
1561 768705e3 2021-09-27 thomas fi
1562 768705e3 2021-09-27 thomas echo "Already up-to-date" > $testroot/stdout.expected
1563 2d7ce510 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1564 fc414659 2022-04-16 thomas ret=$?
1565 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1566 2d7ce510 2021-09-24 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
1569 2d7ce510 2021-09-24 thomas fi
1570 768705e3 2021-09-27 thomas
1571 768705e3 2021-09-27 thomas # update the 'files' branch
1572 768705e3 2021-09-27 thomas (cd $testroot/repo && git reset -q --hard master)
1573 768705e3 2021-09-27 thomas (cd $testroot/repo && git checkout -q files)
1574 768705e3 2021-09-27 thomas echo "indeed" > $testroot/repo/indeed
1575 768705e3 2021-09-27 thomas (cd $testroot/repo && git add indeed)
1576 768705e3 2021-09-27 thomas git_commit $testroot/repo -m "adding another file indeed"
1577 768705e3 2021-09-27 thomas echo "be lots and lots of" > $testroot/repo/be/lots/of
1578 768705e3 2021-09-27 thomas git_commit $testroot/repo -m "lots of changes"
1579 768705e3 2021-09-27 thomas
1580 768705e3 2021-09-27 thomas (cd $testroot/wt && got update > /dev/null)
1581 fc414659 2022-04-16 thomas ret=$?
1582 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1583 768705e3 2021-09-27 thomas echo "got update failed unexpectedly" >&2
1584 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1585 768705e3 2021-09-27 thomas return 1
1586 768705e3 2021-09-27 thomas fi
1587 768705e3 2021-09-27 thomas
1588 768705e3 2021-09-27 thomas # we should now be able to merge more changes from files branch
1589 768705e3 2021-09-27 thomas (cd $testroot/wt && got merge files > $testroot/stdout)
1590 fc414659 2022-04-16 thomas ret=$?
1591 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1592 768705e3 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1593 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1594 768705e3 2021-09-27 thomas return 1
1595 768705e3 2021-09-27 thomas fi
1596 768705e3 2021-09-27 thomas
1597 768705e3 2021-09-27 thomas local merge_commit1=`git_show_branch_head $testroot/repo master`
1598 768705e3 2021-09-27 thomas cat > $testroot/stdout.expected <<EOF
1599 768705e3 2021-09-27 thomas G be/lots/of
1600 768705e3 2021-09-27 thomas A indeed
1601 768705e3 2021-09-27 thomas Merged refs/heads/files into refs/heads/master: $merge_commit1
1602 768705e3 2021-09-27 thomas EOF
1603 768705e3 2021-09-27 thomas
1604 768705e3 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1605 fc414659 2022-04-16 thomas ret=$?
1606 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1607 768705e3 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1608 768705e3 2021-09-27 thomas fi
1609 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1610 10604dce 2021-09-24 thomas }
1611 ba34626b 2021-09-27 thomas
1612 ba34626b 2021-09-27 thomas test_merge_interrupt() {
1613 ba34626b 2021-09-27 thomas local testroot=`test_init merge_interrupt`
1614 ba34626b 2021-09-27 thomas local commit0=`git_show_head $testroot/repo`
1615 ba34626b 2021-09-27 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1616 ba34626b 2021-09-27 thomas
1617 ba34626b 2021-09-27 thomas (cd $testroot/repo && git checkout -q -b newbranch)
1618 ba34626b 2021-09-27 thomas echo "modified alpha on branch" > $testroot/repo/alpha
1619 ba34626b 2021-09-27 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
1620 ba34626b 2021-09-27 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1621 ba34626b 2021-09-27 thomas
1622 ba34626b 2021-09-27 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
1623 fc414659 2022-04-16 thomas ret=$?
1624 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1625 ba34626b 2021-09-27 thomas echo "got checkout failed unexpectedly" >&2
1626 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1627 ba34626b 2021-09-27 thomas return 1
1628 ba34626b 2021-09-27 thomas fi
1629 ba34626b 2021-09-27 thomas
1630 ba34626b 2021-09-27 thomas # create a non-conflicting commit
1631 ba34626b 2021-09-27 thomas (cd $testroot/repo && git checkout -q master)
1632 ba34626b 2021-09-27 thomas echo "modified beta on master" > $testroot/repo/beta
1633 ba34626b 2021-09-27 thomas git_commit $testroot/repo -m "committing to beta on master"
1634 ba34626b 2021-09-27 thomas local master_commit=`git_show_head $testroot/repo`
1635 10604dce 2021-09-24 thomas
1636 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
1637 ba34626b 2021-09-27 thomas (cd $testroot/wt && got update > /dev/null)
1638 fc414659 2022-04-16 thomas ret=$?
1639 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1640 ba34626b 2021-09-27 thomas echo "got update failed unexpectedly" >&2
1641 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1642 ba34626b 2021-09-27 thomas return 1
1643 ba34626b 2021-09-27 thomas fi
1644 ba34626b 2021-09-27 thomas
1645 ba34626b 2021-09-27 thomas (cd $testroot/wt && got merge -n newbranch \
1646 ba34626b 2021-09-27 thomas > $testroot/stdout 2> $testroot/stderr)
1647 fc414659 2022-04-16 thomas ret=$?
1648 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1649 ba34626b 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1650 ba34626b 2021-09-27 thomas test_done "$testroot" "1"
1651 ba34626b 2021-09-27 thomas return 1
1652 ba34626b 2021-09-27 thomas fi
1653 ba34626b 2021-09-27 thomas
1654 ba34626b 2021-09-27 thomas echo "G alpha" > $testroot/stdout.expected
1655 ba34626b 2021-09-27 thomas echo "Merge of refs/heads/newbranch interrupted on request" \
1656 ba34626b 2021-09-27 thomas >> $testroot/stdout.expected
1657 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1658 fc414659 2022-04-16 thomas ret=$?
1659 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1660 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1661 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1662 ba34626b 2021-09-27 thomas return 1
1663 ba34626b 2021-09-27 thomas fi
1664 ba34626b 2021-09-27 thomas
1665 ba34626b 2021-09-27 thomas (cd $testroot/wt && got status > $testroot/stdout)
1666 ba34626b 2021-09-27 thomas
1667 ba34626b 2021-09-27 thomas echo "M alpha" > $testroot/stdout.expected
1668 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1669 fc414659 2022-04-16 thomas ret=$?
1670 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1671 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1672 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1673 ba34626b 2021-09-27 thomas return 1
1674 ba34626b 2021-09-27 thomas fi
1675 ba34626b 2021-09-27 thomas
1676 ba34626b 2021-09-27 thomas echo "modified alpha on branch" > $testroot/content.expected
1677 ba34626b 2021-09-27 thomas cat $testroot/wt/alpha > $testroot/content
1678 ba34626b 2021-09-27 thomas cmp -s $testroot/content.expected $testroot/content
1679 fc414659 2022-04-16 thomas ret=$?
1680 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1681 ba34626b 2021-09-27 thomas diff -u $testroot/content.expected $testroot/content
1682 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1683 ba34626b 2021-09-27 thomas return 1
1684 ba34626b 2021-09-27 thomas fi
1685 ba34626b 2021-09-27 thomas
1686 ba34626b 2021-09-27 thomas # adjust merge result
1687 ba34626b 2021-09-27 thomas echo "adjusted merge result" > $testroot/wt/alpha
1688 ba34626b 2021-09-27 thomas
1689 ba34626b 2021-09-27 thomas # continue the merge
1690 ba34626b 2021-09-27 thomas (cd $testroot/wt && got merge -c > $testroot/stdout)
1691 fc414659 2022-04-16 thomas ret=$?
1692 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1693 ba34626b 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1694 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1695 ba34626b 2021-09-27 thomas return 1
1696 ba34626b 2021-09-27 thomas fi
1697 ba34626b 2021-09-27 thomas
1698 ba34626b 2021-09-27 thomas local merge_commit=`git_show_head $testroot/repo`
1699 ba34626b 2021-09-27 thomas
1700 ae1e948a 2021-09-28 thomas echo "M alpha" > $testroot/stdout.expected
1701 ba34626b 2021-09-27 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1702 ae1e948a 2021-09-28 thomas >> $testroot/stdout.expected
1703 ba34626b 2021-09-27 thomas echo $merge_commit >> $testroot/stdout.expected
1704 ba34626b 2021-09-27 thomas
1705 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1706 fc414659 2022-04-16 thomas ret=$?
1707 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1708 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1709 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1710 ba34626b 2021-09-27 thomas return 1
1711 ba34626b 2021-09-27 thomas fi
1712 ba34626b 2021-09-27 thomas
1713 ba34626b 2021-09-27 thomas (cd $testroot/wt && got status > $testroot/stdout)
1714 ba34626b 2021-09-27 thomas
1715 ba34626b 2021-09-27 thomas echo -n > $testroot/stdout.expected
1716 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1717 fc414659 2022-04-16 thomas ret=$?
1718 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1719 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1720 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1721 ba34626b 2021-09-27 thomas return 1
1722 ba34626b 2021-09-27 thomas fi
1723 ba34626b 2021-09-27 thomas
1724 ba34626b 2021-09-27 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1725 ba34626b 2021-09-27 thomas echo "commit $merge_commit (master)" > $testroot/stdout.expected
1726 ba34626b 2021-09-27 thomas echo "commit $master_commit" >> $testroot/stdout.expected
1727 ba34626b 2021-09-27 thomas echo "commit $commit0" >> $testroot/stdout.expected
1728 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1729 fc414659 2022-04-16 thomas ret=$?
1730 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1731 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1732 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1733 ba34626b 2021-09-27 thomas return 1
1734 ba34626b 2021-09-27 thomas fi
1735 ba34626b 2021-09-27 thomas
1736 ba34626b 2021-09-27 thomas (cd $testroot/wt && got update > $testroot/stdout)
1737 ba34626b 2021-09-27 thomas
1738 ba34626b 2021-09-27 thomas echo 'Already up-to-date' > $testroot/stdout.expected
1739 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1740 fc414659 2022-04-16 thomas ret=$?
1741 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1742 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1743 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1744 ba34626b 2021-09-27 thomas return 1
1745 ba34626b 2021-09-27 thomas fi
1746 ba34626b 2021-09-27 thomas
1747 ba34626b 2021-09-27 thomas # We should have created a merge commit with two parents.
1748 ba34626b 2021-09-27 thomas (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
1749 ba34626b 2021-09-27 thomas echo "parent 1: $master_commit" > $testroot/stdout.expected
1750 ba34626b 2021-09-27 thomas echo "parent 2: $branch_commit0" >> $testroot/stdout.expected
1751 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1752 fc414659 2022-04-16 thomas ret=$?
1753 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1754 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1755 ba34626b 2021-09-27 thomas fi
1756 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1757 a2c162eb 2022-10-30 thomas }
1758 a2c162eb 2022-10-30 thomas
1759 a2c162eb 2022-10-30 thomas test_merge_umask() {
1760 a2c162eb 2022-10-30 thomas local testroot=`test_init merge_umask`
1761 a2c162eb 2022-10-30 thomas
1762 a2c162eb 2022-10-30 thomas (cd $testroot/repo && git checkout -q -b newbranch)
1763 a2c162eb 2022-10-30 thomas echo "modified alpha on branch" >$testroot/repo/alpha
1764 a2c162eb 2022-10-30 thomas git_commit "$testroot/repo" -m "committing alpha on newbranch"
1765 a2c162eb 2022-10-30 thomas echo "modified delta on branch" >$testroot/repo/gamma/delta
1766 a2c162eb 2022-10-30 thomas git_commit "$testroot/repo" -m "committing delta on newbranch"
1767 a2c162eb 2022-10-30 thomas
1768 a2c162eb 2022-10-30 thomas # diverge from newbranch
1769 a2c162eb 2022-10-30 thomas (cd "$testroot/repo" && git checkout -q master)
1770 a2c162eb 2022-10-30 thomas echo "modified beta on master" >$testroot/repo/beta
1771 a2c162eb 2022-10-30 thomas git_commit "$testroot/repo" -m "committing zeto no master"
1772 a2c162eb 2022-10-30 thomas
1773 a2c162eb 2022-10-30 thomas got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1774 a2c162eb 2022-10-30 thomas
1775 a2c162eb 2022-10-30 thomas # using a subshell to avoid clobbering global umask
1776 a2c162eb 2022-10-30 thomas (umask 077 && cd "$testroot/wt" && got merge newbranch) >/dev/null
1777 a2c162eb 2022-10-30 thomas
1778 a2c162eb 2022-10-30 thomas for f in alpha gamma/delta; do
1779 a2c162eb 2022-10-30 thomas ls -l "$testroot/wt/$f" | grep -q ^-rw-------
1780 a2c162eb 2022-10-30 thomas if [ $? -ne 0 ]; then
1781 a2c162eb 2022-10-30 thomas echo "$f is not 0600 after merge" >&2
1782 a2c162eb 2022-10-30 thomas ls -l "$testroot/wt/$f" >&2
1783 a2c162eb 2022-10-30 thomas test_done "$testroot" 1
1784 a2c162eb 2022-10-30 thomas fi
1785 a2c162eb 2022-10-30 thomas done
1786 a2c162eb 2022-10-30 thomas
1787 a2c162eb 2022-10-30 thomas test_done "$testroot" 0
1788 ba34626b 2021-09-27 thomas }
1789 b16f1832 2023-02-21 thomas
1790 b16f1832 2023-02-21 thomas test_merge_gitconfig_author() {
1791 b16f1832 2023-02-21 thomas local testroot=`test_init merge_gitconfig_author`
1792 b16f1832 2023-02-21 thomas
1793 b16f1832 2023-02-21 thomas (cd $testroot/repo && git config user.name 'Flan Luck')
1794 b16f1832 2023-02-21 thomas (cd $testroot/repo && git config user.email 'flan_luck@openbsd.org')
1795 b16f1832 2023-02-21 thomas
1796 b16f1832 2023-02-21 thomas (cd $testroot/repo && git checkout -q -b newbranch)
1797 b16f1832 2023-02-21 thomas echo "modified alpha on branch" >$testroot/repo/alpha
1798 b16f1832 2023-02-21 thomas git_commit "$testroot/repo" -m "committing alpha on newbranch"
1799 b16f1832 2023-02-21 thomas echo "modified delta on branch" >$testroot/repo/gamma/delta
1800 b16f1832 2023-02-21 thomas git_commit "$testroot/repo" -m "committing delta on newbranch"
1801 ba34626b 2021-09-27 thomas
1802 b16f1832 2023-02-21 thomas # diverge from newbranch
1803 b16f1832 2023-02-21 thomas (cd "$testroot/repo" && git checkout -q master)
1804 b16f1832 2023-02-21 thomas echo "modified beta on master" >$testroot/repo/beta
1805 b16f1832 2023-02-21 thomas git_commit "$testroot/repo" -m "committing zeto no master"
1806 b16f1832 2023-02-21 thomas
1807 b16f1832 2023-02-21 thomas got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1808 b16f1832 2023-02-21 thomas
1809 b16f1832 2023-02-21 thomas # unset in a subshell to avoid affecting our environment
1810 b16f1832 2023-02-21 thomas (unset GOT_IGNORE_GITCONFIG && cd $testroot/wt && \
1811 b16f1832 2023-02-21 thomas got merge newbranch > /dev/null)
1812 b16f1832 2023-02-21 thomas
1813 b16f1832 2023-02-21 thomas (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
1814 b16f1832 2023-02-21 thomas ret=$?
1815 b16f1832 2023-02-21 thomas if [ $ret -ne 0 ]; then
1816 b16f1832 2023-02-21 thomas test_done "$testroot" "$ret"
1817 b16f1832 2023-02-21 thomas return 1
1818 b16f1832 2023-02-21 thomas fi
1819 b16f1832 2023-02-21 thomas
1820 b16f1832 2023-02-21 thomas echo "from: Flan Luck <flan_luck@openbsd.org>" \
1821 b16f1832 2023-02-21 thomas > $testroot/stdout.expected
1822 b16f1832 2023-02-21 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1823 b16f1832 2023-02-21 thomas ret=$?
1824 b16f1832 2023-02-21 thomas if [ $ret -ne 0 ]; then
1825 b16f1832 2023-02-21 thomas diff -u $testroot/stdout.expected $testroot/stdout
1826 b16f1832 2023-02-21 thomas fi
1827 b16f1832 2023-02-21 thomas test_done "$testroot" "$ret"
1828 b16f1832 2023-02-21 thomas }
1829 4434a15a 2023-06-22 thomas
1830 4434a15a 2023-06-22 thomas test_merge_fetched_branch() {
1831 4434a15a 2023-06-22 thomas local testroot=`test_init merge_fetched_branch`
1832 4434a15a 2023-06-22 thomas local testurl=ssh://127.0.0.1/$testroot
1833 4434a15a 2023-06-22 thomas local commit_id=`git_show_head $testroot/repo`
1834 4434a15a 2023-06-22 thomas
1835 4434a15a 2023-06-22 thomas got clone -q $testurl/repo $testroot/repo-clone
1836 4434a15a 2023-06-22 thomas ret=$?
1837 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1838 4434a15a 2023-06-22 thomas echo "got clone command failed unexpectedly" >&2
1839 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1840 4434a15a 2023-06-22 thomas return 1
1841 4434a15a 2023-06-22 thomas fi
1842 b16f1832 2023-02-21 thomas
1843 4434a15a 2023-06-22 thomas echo "modified alpha" > $testroot/repo/alpha
1844 4434a15a 2023-06-22 thomas git_commit $testroot/repo -m "modified alpha"
1845 4434a15a 2023-06-22 thomas local commit_id2=`git_show_head $testroot/repo`
1846 4434a15a 2023-06-22 thomas
1847 4434a15a 2023-06-22 thomas got fetch -q -r $testroot/repo-clone > $testroot/stdout
1848 4434a15a 2023-06-22 thomas ret=$?
1849 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1850 4434a15a 2023-06-22 thomas echo "got fetch command failed unexpectedly" >&2
1851 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1852 4434a15a 2023-06-22 thomas return 1
1853 4434a15a 2023-06-22 thomas fi
1854 4434a15a 2023-06-22 thomas
1855 4434a15a 2023-06-22 thomas echo -n > $testroot/stdout.expected
1856 4434a15a 2023-06-22 thomas
1857 4434a15a 2023-06-22 thomas cmp -s $testroot/stdout $testroot/stdout.expected
1858 4434a15a 2023-06-22 thomas ret=$?
1859 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1860 4434a15a 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1861 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1862 4434a15a 2023-06-22 thomas return 1
1863 4434a15a 2023-06-22 thomas fi
1864 4434a15a 2023-06-22 thomas
1865 4434a15a 2023-06-22 thomas got ref -l -r $testroot/repo-clone > $testroot/stdout
1866 4434a15a 2023-06-22 thomas
1867 4434a15a 2023-06-22 thomas echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1868 4434a15a 2023-06-22 thomas echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1869 4434a15a 2023-06-22 thomas echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1870 4434a15a 2023-06-22 thomas >> $testroot/stdout.expected
1871 4434a15a 2023-06-22 thomas echo "refs/remotes/origin/master: $commit_id2" \
1872 4434a15a 2023-06-22 thomas >> $testroot/stdout.expected
1873 4434a15a 2023-06-22 thomas
1874 4434a15a 2023-06-22 thomas cmp -s $testroot/stdout $testroot/stdout.expected
1875 4434a15a 2023-06-22 thomas ret=$?
1876 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1877 4434a15a 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1878 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1879 4434a15a 2023-06-22 thomas return 1
1880 4434a15a 2023-06-22 thomas fi
1881 4434a15a 2023-06-22 thomas
1882 4434a15a 2023-06-22 thomas got checkout $testroot/repo-clone $testroot/wt > /dev/null
1883 4434a15a 2023-06-22 thomas
1884 4434a15a 2023-06-22 thomas echo "modified beta" > $testroot/wt/beta
1885 4434a15a 2023-06-22 thomas (cd $testroot/wt && got commit -m "modified beta" > /dev/null)
1886 4434a15a 2023-06-22 thomas local commit_id3=`git_show_head $testroot/repo-clone`
1887 4434a15a 2023-06-22 thomas
1888 4434a15a 2023-06-22 thomas (cd $testroot/wt && got update > /dev/null)
1889 4434a15a 2023-06-22 thomas (cd $testroot/wt && got merge origin/master > $testroot/stdout)
1890 4434a15a 2023-06-22 thomas local merge_commit_id=`git_show_head $testroot/repo-clone`
1891 4434a15a 2023-06-22 thomas
1892 4434a15a 2023-06-22 thomas cat > $testroot/stdout.expected <<EOF
1893 4434a15a 2023-06-22 thomas G alpha
1894 4434a15a 2023-06-22 thomas Merged refs/remotes/origin/master into refs/heads/master: $merge_commit_id
1895 4434a15a 2023-06-22 thomas EOF
1896 4434a15a 2023-06-22 thomas
1897 4434a15a 2023-06-22 thomas cmp -s $testroot/stdout $testroot/stdout.expected
1898 4434a15a 2023-06-22 thomas ret=$?
1899 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1900 4434a15a 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1901 4434a15a 2023-06-22 thomas fi
1902 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1903 4434a15a 2023-06-22 thomas }
1904 4434a15a 2023-06-22 thomas
1905 4434a15a 2023-06-22 thomas test_merge_fetched_branch_remote() {
1906 4434a15a 2023-06-22 thomas local testroot=`test_init merge_fetched_branch_remote`
1907 4434a15a 2023-06-22 thomas local testurl=ssh://127.0.0.1/$testroot
1908 4434a15a 2023-06-22 thomas local commit_id=`git_show_head $testroot/repo`
1909 4434a15a 2023-06-22 thomas
1910 4434a15a 2023-06-22 thomas got clone -q $testurl/repo $testroot/repo-clone
1911 4434a15a 2023-06-22 thomas ret=$?
1912 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1913 4434a15a 2023-06-22 thomas echo "got clone command failed unexpectedly" >&2
1914 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1915 4434a15a 2023-06-22 thomas return 1
1916 4434a15a 2023-06-22 thomas fi
1917 4434a15a 2023-06-22 thomas
1918 4434a15a 2023-06-22 thomas echo "modified alpha" > $testroot/repo/alpha
1919 4434a15a 2023-06-22 thomas git_commit $testroot/repo -m "modified alpha"
1920 4434a15a 2023-06-22 thomas local commit_id2=`git_show_head $testroot/repo`
1921 4434a15a 2023-06-22 thomas
1922 4434a15a 2023-06-22 thomas got fetch -q -r $testroot/repo-clone > $testroot/stdout
1923 4434a15a 2023-06-22 thomas ret=$?
1924 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1925 4434a15a 2023-06-22 thomas echo "got fetch command failed unexpectedly" >&2
1926 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1927 4434a15a 2023-06-22 thomas return 1
1928 4434a15a 2023-06-22 thomas fi
1929 4434a15a 2023-06-22 thomas
1930 4434a15a 2023-06-22 thomas echo -n > $testroot/stdout.expected
1931 4434a15a 2023-06-22 thomas
1932 4434a15a 2023-06-22 thomas cmp -s $testroot/stdout $testroot/stdout.expected
1933 4434a15a 2023-06-22 thomas ret=$?
1934 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1935 4434a15a 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1936 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1937 4434a15a 2023-06-22 thomas return 1
1938 4434a15a 2023-06-22 thomas fi
1939 4434a15a 2023-06-22 thomas
1940 4434a15a 2023-06-22 thomas got ref -l -r $testroot/repo-clone > $testroot/stdout
1941 4434a15a 2023-06-22 thomas
1942 4434a15a 2023-06-22 thomas echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1943 4434a15a 2023-06-22 thomas echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1944 4434a15a 2023-06-22 thomas echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1945 4434a15a 2023-06-22 thomas >> $testroot/stdout.expected
1946 4434a15a 2023-06-22 thomas echo "refs/remotes/origin/master: $commit_id2" \
1947 4434a15a 2023-06-22 thomas >> $testroot/stdout.expected
1948 4434a15a 2023-06-22 thomas
1949 4434a15a 2023-06-22 thomas cmp -s $testroot/stdout $testroot/stdout.expected
1950 4434a15a 2023-06-22 thomas ret=$?
1951 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1952 4434a15a 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1953 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1954 4434a15a 2023-06-22 thomas return 1
1955 4434a15a 2023-06-22 thomas fi
1956 4434a15a 2023-06-22 thomas
1957 4434a15a 2023-06-22 thomas got checkout $testroot/repo-clone $testroot/wt > /dev/null
1958 4434a15a 2023-06-22 thomas
1959 4434a15a 2023-06-22 thomas echo "modified beta" > $testroot/wt/beta
1960 4434a15a 2023-06-22 thomas (cd $testroot/wt && got commit -m "modified beta" > /dev/null)
1961 4434a15a 2023-06-22 thomas local commit_id3=`git_show_head $testroot/repo-clone`
1962 4434a15a 2023-06-22 thomas
1963 4434a15a 2023-06-22 thomas (cd $testroot/wt && got update -b origin/master > /dev/null)
1964 4434a15a 2023-06-22 thomas (cd $testroot/wt && got merge master > \
1965 4434a15a 2023-06-22 thomas $testroot/stdout 2> $testroot/stderr)
1966 4434a15a 2023-06-22 thomas local merge_commit_id=`git_show_head $testroot/repo-clone`
1967 4434a15a 2023-06-22 thomas
1968 4434a15a 2023-06-22 thomas echo -n > $testroot/stdout.expected
1969 4434a15a 2023-06-22 thomas
1970 4434a15a 2023-06-22 thomas cmp -s $testroot/stdout $testroot/stdout.expected
1971 4434a15a 2023-06-22 thomas ret=$?
1972 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1973 4434a15a 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1974 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1975 4434a15a 2023-06-22 thomas return 1
1976 4434a15a 2023-06-22 thomas fi
1977 4434a15a 2023-06-22 thomas
1978 4434a15a 2023-06-22 thomas echo -n "got: work tree's current branch refs/remotes/origin/master " \
1979 4434a15a 2023-06-22 thomas > $testroot/stderr.expected
1980 4434a15a 2023-06-22 thomas echo -n 'is outside the "refs/heads/" reference namespace; ' \
1981 4434a15a 2023-06-22 thomas >> $testroot/stderr.expected
1982 4434a15a 2023-06-22 thomas echo -n "update -b required: will not commit to a branch " \
1983 4434a15a 2023-06-22 thomas >> $testroot/stderr.expected
1984 4434a15a 2023-06-22 thomas echo 'outside the "refs/heads/" reference namespace' \
1985 4434a15a 2023-06-22 thomas >> $testroot/stderr.expected
1986 4434a15a 2023-06-22 thomas
1987 4434a15a 2023-06-22 thomas cmp -s $testroot/stderr $testroot/stderr.expected
1988 4434a15a 2023-06-22 thomas ret=$?
1989 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1990 4434a15a 2023-06-22 thomas diff -u $testroot/stderr.expected $testroot/stderr
1991 4434a15a 2023-06-22 thomas fi
1992 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1993 4434a15a 2023-06-22 thomas }
1994 4434a15a 2023-06-22 thomas
1995 10604dce 2021-09-24 thomas test_parseargs "$@"
1996 10604dce 2021-09-24 thomas run_test test_merge_basic
1997 2b72f32d 2023-06-22 thomas run_test test_merge_forward
1998 31009ade 2023-07-05 thomas run_test test_merge_forward_commit
1999 31009ade 2023-07-05 thomas run_test test_merge_forward_interrupt
2000 2b72f32d 2023-06-22 thomas run_test test_merge_backward
2001 10604dce 2021-09-24 thomas run_test test_merge_continue
2002 fe3f264b 2023-06-08 thomas run_test test_merge_continue_new_commit
2003 10604dce 2021-09-24 thomas run_test test_merge_abort
2004 10604dce 2021-09-24 thomas run_test test_merge_in_progress
2005 10604dce 2021-09-24 thomas run_test test_merge_path_prefix
2006 10604dce 2021-09-24 thomas run_test test_merge_missing_file
2007 2d7ce510 2021-09-24 thomas run_test test_merge_no_op
2008 768705e3 2021-09-27 thomas run_test test_merge_imported_branch
2009 ba34626b 2021-09-27 thomas run_test test_merge_interrupt
2010 a2c162eb 2022-10-30 thomas run_test test_merge_umask
2011 b16f1832 2023-02-21 thomas run_test test_merge_gitconfig_author
2012 4434a15a 2023-06-22 thomas run_test test_merge_fetched_branch
2013 4434a15a 2023-06-22 thomas run_test test_merge_fetched_branch_remote