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