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 10604dce 2021-09-24 thomas echo "C alpha" > $testroot/stdout.expected
717 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
718 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
719 10604dce 2021-09-24 thomas echo "M gamma/delta" >> $testroot/stdout.expected
720 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
721 fc414659 2022-04-16 thomas ret=$?
722 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
723 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
724 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
725 10604dce 2021-09-24 thomas return 1
726 10604dce 2021-09-24 thomas fi
727 10604dce 2021-09-24 thomas
728 10604dce 2021-09-24 thomas echo '<<<<<<<' > $testroot/content.expected
729 10604dce 2021-09-24 thomas echo "modified alpha on master" >> $testroot/content.expected
730 10604dce 2021-09-24 thomas echo "||||||| 3-way merge base: commit $commit0" \
731 10604dce 2021-09-24 thomas >> $testroot/content.expected
732 10604dce 2021-09-24 thomas echo "alpha" >> $testroot/content.expected
733 10604dce 2021-09-24 thomas echo "=======" >> $testroot/content.expected
734 10604dce 2021-09-24 thomas echo "modified alpha on branch" >> $testroot/content.expected
735 10604dce 2021-09-24 thomas echo ">>>>>>> merged change: commit $branch_commit3" \
736 10604dce 2021-09-24 thomas >> $testroot/content.expected
737 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
738 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
739 fc414659 2022-04-16 thomas ret=$?
740 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
741 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
742 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
743 10604dce 2021-09-24 thomas return 1
744 10604dce 2021-09-24 thomas fi
745 10604dce 2021-09-24 thomas
746 10604dce 2021-09-24 thomas # resolve the conflict
747 10604dce 2021-09-24 thomas echo "modified alpha by both branches" > $testroot/wt/alpha
748 10604dce 2021-09-24 thomas
749 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge -c > $testroot/stdout)
750 fc414659 2022-04-16 thomas ret=$?
751 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
752 10604dce 2021-09-24 thomas echo "got merge failed unexpectedly" >&2
753 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
754 10604dce 2021-09-24 thomas return 1
755 10604dce 2021-09-24 thomas fi
756 10604dce 2021-09-24 thomas
757 10604dce 2021-09-24 thomas local merge_commit=`git_show_head $testroot/repo`
758 10604dce 2021-09-24 thomas
759 ae1e948a 2021-09-28 thomas echo "M alpha" > $testroot/stdout.expected
760 ae1e948a 2021-09-28 thomas echo "D beta" >> $testroot/stdout.expected
761 ae1e948a 2021-09-28 thomas echo "A epsilon/new" >> $testroot/stdout.expected
762 ae1e948a 2021-09-28 thomas echo "M gamma/delta" >> $testroot/stdout.expected
763 10604dce 2021-09-24 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
764 ae1e948a 2021-09-28 thomas >> $testroot/stdout.expected
765 10604dce 2021-09-24 thomas echo $merge_commit >> $testroot/stdout.expected
766 10604dce 2021-09-24 thomas
767 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
768 fc414659 2022-04-16 thomas ret=$?
769 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
770 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
771 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
772 10604dce 2021-09-24 thomas return 1
773 10604dce 2021-09-24 thomas fi
774 10604dce 2021-09-24 thomas
775 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/content.expected
776 10604dce 2021-09-24 thomas cat $testroot/wt/gamma/delta > $testroot/content
777 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
778 fc414659 2022-04-16 thomas ret=$?
779 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
780 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
781 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
782 10604dce 2021-09-24 thomas return 1
783 10604dce 2021-09-24 thomas fi
784 10604dce 2021-09-24 thomas
785 10604dce 2021-09-24 thomas echo "modified alpha by both branches" > $testroot/content.expected
786 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
787 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
788 fc414659 2022-04-16 thomas ret=$?
789 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
790 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
791 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
792 10604dce 2021-09-24 thomas return 1
793 10604dce 2021-09-24 thomas fi
794 10604dce 2021-09-24 thomas
795 10604dce 2021-09-24 thomas if [ -e $testroot/wt/beta ]; then
796 10604dce 2021-09-24 thomas echo "removed file beta still exists on disk" >&2
797 10604dce 2021-09-24 thomas test_done "$testroot" "1"
798 10604dce 2021-09-24 thomas return 1
799 10604dce 2021-09-24 thomas fi
800 10604dce 2021-09-24 thomas
801 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/content.expected
802 10604dce 2021-09-24 thomas cat $testroot/wt/epsilon/new > $testroot/content
803 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
804 fc414659 2022-04-16 thomas ret=$?
805 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
806 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
807 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
808 10604dce 2021-09-24 thomas return 1
809 10604dce 2021-09-24 thomas fi
810 10604dce 2021-09-24 thomas
811 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
812 10604dce 2021-09-24 thomas
813 10604dce 2021-09-24 thomas echo -n > $testroot/stdout.expected
814 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
815 fc414659 2022-04-16 thomas ret=$?
816 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
817 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
818 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
819 10604dce 2021-09-24 thomas return 1
820 10604dce 2021-09-24 thomas fi
821 10604dce 2021-09-24 thomas
822 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
823 10604dce 2021-09-24 thomas echo "commit $merge_commit (master)" > $testroot/stdout.expected
824 10604dce 2021-09-24 thomas echo "commit $master_commit" >> $testroot/stdout.expected
825 10604dce 2021-09-24 thomas echo "commit $commit0" >> $testroot/stdout.expected
826 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
827 fc414659 2022-04-16 thomas ret=$?
828 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
829 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
830 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
831 10604dce 2021-09-24 thomas return 1
832 10604dce 2021-09-24 thomas fi
833 10604dce 2021-09-24 thomas
834 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > $testroot/stdout)
835 10604dce 2021-09-24 thomas
836 10604dce 2021-09-24 thomas echo 'Already up-to-date' > $testroot/stdout.expected
837 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
838 fc414659 2022-04-16 thomas ret=$?
839 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
840 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
841 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
842 10604dce 2021-09-24 thomas return 1
843 10604dce 2021-09-24 thomas fi
844 10604dce 2021-09-24 thomas
845 10604dce 2021-09-24 thomas # We should have created a merge commit with two parents.
846 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
847 10604dce 2021-09-24 thomas echo "parent 1: $master_commit" > $testroot/stdout.expected
848 10604dce 2021-09-24 thomas echo "parent 2: $branch_commit3" >> $testroot/stdout.expected
849 fe3f264b 2023-06-08 thomas cmp -s $testroot/stdout.expected $testroot/stdout
850 fe3f264b 2023-06-08 thomas ret=$?
851 fe3f264b 2023-06-08 thomas if [ $ret -ne 0 ]; then
852 fe3f264b 2023-06-08 thomas diff -u $testroot/stdout.expected $testroot/stdout
853 fe3f264b 2023-06-08 thomas fi
854 fe3f264b 2023-06-08 thomas test_done "$testroot" "$ret"
855 fe3f264b 2023-06-08 thomas }
856 fe3f264b 2023-06-08 thomas
857 fe3f264b 2023-06-08 thomas test_merge_continue_new_commit() {
858 fe3f264b 2023-06-08 thomas # "got merge -c" should refuse to run if the current branch tip has
859 fe3f264b 2023-06-08 thomas # changed since the merge was started, to avoid clobbering the changes.
860 fe3f264b 2023-06-08 thomas local testroot=`test_init merge_continue_new_commit`
861 fe3f264b 2023-06-08 thomas
862 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
863 fe3f264b 2023-06-08 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
864 fe3f264b 2023-06-08 thomas git_commit $testroot/repo -m "committing to delta on newbranch"
865 fe3f264b 2023-06-08 thomas
866 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q master
867 fe3f264b 2023-06-08 thomas echo "modified alpha on master" > $testroot/repo/alpha
868 fe3f264b 2023-06-08 thomas git_commit $testroot/repo -m "committing to alpha on master"
869 fe3f264b 2023-06-08 thomas
870 fe3f264b 2023-06-08 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
871 fe3f264b 2023-06-08 thomas ret=$?
872 fe3f264b 2023-06-08 thomas if [ $ret -ne 0 ]; then
873 fe3f264b 2023-06-08 thomas echo "got checkout failed unexpectedly" >&2
874 fe3f264b 2023-06-08 thomas test_done "$testroot" "$ret"
875 fe3f264b 2023-06-08 thomas return 1
876 fe3f264b 2023-06-08 thomas fi
877 fe3f264b 2023-06-08 thomas
878 fe3f264b 2023-06-08 thomas (cd $testroot/wt && got merge -n newbranch >/dev/null)
879 fe3f264b 2023-06-08 thomas ret=$?
880 fe3f264b 2023-06-08 thomas if [ $ret -ne 0 ]; then
881 fe3f264b 2023-06-08 thomas echo "got merge failed unexpectedly" >&2
882 fe3f264b 2023-06-08 thomas test_done "$testroot" "$ret"
883 fe3f264b 2023-06-08 thomas return 1
884 fe3f264b 2023-06-08 thomas fi
885 fe3f264b 2023-06-08 thomas
886 fe3f264b 2023-06-08 thomas echo "modified alpha again on master" > $testroot/repo/alpha
887 fe3f264b 2023-06-08 thomas git_commit $testroot/repo -m "committing to alpha on master again"
888 fe3f264b 2023-06-08 thomas
889 fe3f264b 2023-06-08 thomas (cd $testroot/wt && got merge -c > $testroot/stdout 2> $testroot/stderr)
890 fe3f264b 2023-06-08 thomas ret=$?
891 fe3f264b 2023-06-08 thomas if [ $ret -eq 0 ]; then
892 fe3f264b 2023-06-08 thomas echo "got merge succeeded unexpectedly" >&2
893 fe3f264b 2023-06-08 thomas test_done "$testroot" "1"
894 fe3f264b 2023-06-08 thomas return 1
895 fe3f264b 2023-06-08 thomas fi
896 fe3f264b 2023-06-08 thomas
897 fe3f264b 2023-06-08 thomas echo -n > $testroot/stdout.expected
898 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
899 fc414659 2022-04-16 thomas ret=$?
900 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
901 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
902 fe3f264b 2023-06-08 thomas test_done "$testroot" "$ret"
903 fe3f264b 2023-06-08 thomas return 1
904 fe3f264b 2023-06-08 thomas fi
905 fe3f264b 2023-06-08 thomas
906 fe3f264b 2023-06-08 thomas echo -n "got: merging cannot proceed because the work tree is no " \
907 fe3f264b 2023-06-08 thomas > $testroot/stderr.expected
908 fe3f264b 2023-06-08 thomas echo "longer up-to-date; merge must be aborted and retried" \
909 fe3f264b 2023-06-08 thomas >> $testroot/stderr.expected
910 fe3f264b 2023-06-08 thomas cmp -s $testroot/stderr.expected $testroot/stderr
911 fe3f264b 2023-06-08 thomas ret=$?
912 fe3f264b 2023-06-08 thomas if [ $ret -ne 0 ]; then
913 fe3f264b 2023-06-08 thomas diff -u $testroot/stderr.expected $testroot/stderr
914 10604dce 2021-09-24 thomas fi
915 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
916 10604dce 2021-09-24 thomas }
917 10604dce 2021-09-24 thomas
918 10604dce 2021-09-24 thomas test_merge_abort() {
919 10604dce 2021-09-24 thomas local testroot=`test_init merge_abort`
920 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
921 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
922 10604dce 2021-09-24 thomas
923 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
924 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
925 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to delta on newbranch"
926 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
927 10604dce 2021-09-24 thomas
928 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
929 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
930 10604dce 2021-09-24 thomas local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
931 d1e03b8c 2023-10-08 thomas git -C $testroot/repo rm -q beta
932 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "removing beta on newbranch"
933 10604dce 2021-09-24 thomas local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
934 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/repo/epsilon/new
935 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add epsilon/new
936 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding new file on newbranch"
937 10604dce 2021-09-24 thomas local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
938 d1e03b8c 2023-10-08 thomas (cd $testroot/repo && ln -s alpha symlink)
939 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add symlink
940 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding symlink on newbranch"
941 10604dce 2021-09-24 thomas local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
942 10604dce 2021-09-24 thomas
943 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
944 fc414659 2022-04-16 thomas ret=$?
945 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
946 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
947 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
948 10604dce 2021-09-24 thomas return 1
949 10604dce 2021-09-24 thomas fi
950 d52bac28 2021-10-08 thomas
951 d52bac28 2021-10-08 thomas # unrelated unversioned file in work tree
952 d52bac28 2021-10-08 thomas touch $testroot/wt/unversioned-file
953 10604dce 2021-09-24 thomas
954 10604dce 2021-09-24 thomas # create a conflicting commit
955 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q master
956 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
957 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
958 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
959 10604dce 2021-09-24 thomas
960 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
961 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
962 fc414659 2022-04-16 thomas ret=$?
963 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
964 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
965 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
966 10604dce 2021-09-24 thomas return 1
967 10604dce 2021-09-24 thomas fi
968 10604dce 2021-09-24 thomas
969 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
970 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
971 fc414659 2022-04-16 thomas ret=$?
972 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
973 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
974 10604dce 2021-09-24 thomas test_done "$testroot" "1"
975 10604dce 2021-09-24 thomas return 1
976 10604dce 2021-09-24 thomas fi
977 10604dce 2021-09-24 thomas
978 10604dce 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
979 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
980 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
981 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
982 10604dce 2021-09-24 thomas echo "A symlink" >> $testroot/stdout.expected
983 10604dce 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
984 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
985 fc414659 2022-04-16 thomas ret=$?
986 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
987 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
988 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
989 10604dce 2021-09-24 thomas return 1
990 10604dce 2021-09-24 thomas fi
991 10604dce 2021-09-24 thomas
992 10604dce 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
993 10604dce 2021-09-24 thomas > $testroot/stderr.expected
994 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
995 fc414659 2022-04-16 thomas ret=$?
996 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
997 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
998 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
999 10604dce 2021-09-24 thomas return 1
1000 10604dce 2021-09-24 thomas fi
1001 8641a332 2023-04-14 thomas
1002 8641a332 2023-04-14 thomas # unrelated added file added during conflict resolution
1003 8641a332 2023-04-14 thomas touch $testroot/wt/added-file
1004 8641a332 2023-04-14 thomas (cd $testroot/wt && got add added-file > /dev/null)
1005 10604dce 2021-09-24 thomas
1006 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1007 10604dce 2021-09-24 thomas
1008 8641a332 2023-04-14 thomas echo "A added-file" > $testroot/stdout.expected
1009 8641a332 2023-04-14 thomas echo "C alpha" >> $testroot/stdout.expected
1010 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
1011 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
1012 10604dce 2021-09-24 thomas echo "M gamma/delta" >> $testroot/stdout.expected
1013 10604dce 2021-09-24 thomas echo "A symlink" >> $testroot/stdout.expected
1014 d52bac28 2021-10-08 thomas echo "? unversioned-file" >> $testroot/stdout.expected
1015 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1016 fc414659 2022-04-16 thomas ret=$?
1017 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1018 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1019 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1020 10604dce 2021-09-24 thomas return 1
1021 10604dce 2021-09-24 thomas fi
1022 10604dce 2021-09-24 thomas
1023 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge -a > $testroot/stdout)
1024 fc414659 2022-04-16 thomas ret=$?
1025 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1026 10604dce 2021-09-24 thomas echo "got merge failed unexpectedly" >&2
1027 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1028 10604dce 2021-09-24 thomas return 1
1029 10604dce 2021-09-24 thomas fi
1030 10604dce 2021-09-24 thomas
1031 8641a332 2023-04-14 thomas echo "R added-file" > $testroot/stdout.expected
1032 8641a332 2023-04-14 thomas echo "R alpha" >> $testroot/stdout.expected
1033 10604dce 2021-09-24 thomas echo "R beta" >> $testroot/stdout.expected
1034 10604dce 2021-09-24 thomas echo "R epsilon/new" >> $testroot/stdout.expected
1035 10604dce 2021-09-24 thomas echo "R gamma/delta" >> $testroot/stdout.expected
1036 10604dce 2021-09-24 thomas echo "R symlink" >> $testroot/stdout.expected
1037 8641a332 2023-04-14 thomas echo "G added-file" >> $testroot/stdout.expected
1038 10604dce 2021-09-24 thomas echo "Merge of refs/heads/newbranch aborted" \
1039 10604dce 2021-09-24 thomas >> $testroot/stdout.expected
1040 10604dce 2021-09-24 thomas
1041 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1042 fc414659 2022-04-16 thomas ret=$?
1043 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1044 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1045 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1046 10604dce 2021-09-24 thomas return 1
1047 10604dce 2021-09-24 thomas fi
1048 10604dce 2021-09-24 thomas
1049 10604dce 2021-09-24 thomas echo "delta" > $testroot/content.expected
1050 10604dce 2021-09-24 thomas cat $testroot/wt/gamma/delta > $testroot/content
1051 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
1052 fc414659 2022-04-16 thomas ret=$?
1053 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1054 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
1055 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1056 10604dce 2021-09-24 thomas return 1
1057 10604dce 2021-09-24 thomas fi
1058 10604dce 2021-09-24 thomas
1059 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/content.expected
1060 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
1061 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
1062 fc414659 2022-04-16 thomas ret=$?
1063 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1064 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
1065 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1066 10604dce 2021-09-24 thomas return 1
1067 10604dce 2021-09-24 thomas fi
1068 10604dce 2021-09-24 thomas
1069 10604dce 2021-09-24 thomas echo "beta" > $testroot/content.expected
1070 10604dce 2021-09-24 thomas cat $testroot/wt/beta > $testroot/content
1071 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
1072 fc414659 2022-04-16 thomas ret=$?
1073 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1074 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
1075 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1076 10604dce 2021-09-24 thomas return 1
1077 10604dce 2021-09-24 thomas fi
1078 10604dce 2021-09-24 thomas
1079 10604dce 2021-09-24 thomas if [ -e $testroot/wt/epsilon/new ]; then
1080 10604dce 2021-09-24 thomas echo "reverted file epsilon/new still exists on disk" >&2
1081 10604dce 2021-09-24 thomas test_done "$testroot" "1"
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/symlink ]; then
1086 10604dce 2021-09-24 thomas echo "reverted symlink 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 (cd $testroot/wt && got status > $testroot/stdout)
1092 10604dce 2021-09-24 thomas
1093 8641a332 2023-04-14 thomas echo "? added-file" > $testroot/stdout.expected
1094 8641a332 2023-04-14 thomas echo "? unversioned-file" >> $testroot/stdout.expected
1095 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1096 fc414659 2022-04-16 thomas ret=$?
1097 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1098 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1099 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1100 10604dce 2021-09-24 thomas return 1
1101 10604dce 2021-09-24 thomas fi
1102 10604dce 2021-09-24 thomas
1103 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1104 10604dce 2021-09-24 thomas echo "commit $master_commit (master)" > $testroot/stdout.expected
1105 10604dce 2021-09-24 thomas echo "commit $commit0" >> $testroot/stdout.expected
1106 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1107 fc414659 2022-04-16 thomas ret=$?
1108 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1109 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1110 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1111 10604dce 2021-09-24 thomas return 1
1112 10604dce 2021-09-24 thomas fi
1113 10604dce 2021-09-24 thomas
1114 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > $testroot/stdout)
1115 10604dce 2021-09-24 thomas
1116 10604dce 2021-09-24 thomas echo 'Already up-to-date' > $testroot/stdout.expected
1117 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1118 fc414659 2022-04-16 thomas ret=$?
1119 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1120 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1121 10604dce 2021-09-24 thomas fi
1122 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1123 10604dce 2021-09-24 thomas }
1124 10604dce 2021-09-24 thomas
1125 10604dce 2021-09-24 thomas test_merge_in_progress() {
1126 10604dce 2021-09-24 thomas local testroot=`test_init merge_in_progress`
1127 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
1128 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1129 10604dce 2021-09-24 thomas
1130 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
1131 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
1132 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
1133 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1134 10604dce 2021-09-24 thomas
1135 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
1136 fc414659 2022-04-16 thomas ret=$?
1137 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1138 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
1139 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1140 10604dce 2021-09-24 thomas return 1
1141 10604dce 2021-09-24 thomas fi
1142 10604dce 2021-09-24 thomas
1143 10604dce 2021-09-24 thomas # create a conflicting commit
1144 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q master
1145 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
1146 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
1147 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
1148 10604dce 2021-09-24 thomas
1149 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
1150 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
1151 fc414659 2022-04-16 thomas ret=$?
1152 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1153 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
1154 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1155 10604dce 2021-09-24 thomas return 1
1156 10604dce 2021-09-24 thomas fi
1157 10604dce 2021-09-24 thomas
1158 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
1159 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
1160 fc414659 2022-04-16 thomas ret=$?
1161 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
1162 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
1163 10604dce 2021-09-24 thomas test_done "$testroot" "1"
1164 10604dce 2021-09-24 thomas return 1
1165 10604dce 2021-09-24 thomas fi
1166 10604dce 2021-09-24 thomas
1167 10604dce 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
1168 10604dce 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1169 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1170 fc414659 2022-04-16 thomas ret=$?
1171 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1172 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1173 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1174 10604dce 2021-09-24 thomas return 1
1175 10604dce 2021-09-24 thomas fi
1176 10604dce 2021-09-24 thomas
1177 10604dce 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
1178 10604dce 2021-09-24 thomas > $testroot/stderr.expected
1179 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1180 fc414659 2022-04-16 thomas ret=$?
1181 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1182 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1183 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1184 10604dce 2021-09-24 thomas return 1
1185 10604dce 2021-09-24 thomas fi
1186 10604dce 2021-09-24 thomas
1187 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1188 10604dce 2021-09-24 thomas
1189 10604dce 2021-09-24 thomas echo "C alpha" > $testroot/stdout.expected
1190 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1191 fc414659 2022-04-16 thomas ret=$?
1192 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1193 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1194 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1195 10604dce 2021-09-24 thomas return 1
1196 10604dce 2021-09-24 thomas fi
1197 10604dce 2021-09-24 thomas
1198 10604dce 2021-09-24 thomas for cmd in update commit histedit "rebase newbranch" \
1199 d8a7bd7d 2023-06-01 thomas "integrate newbranch" "merge newbranch" "stage alpha"; do
1200 10604dce 2021-09-24 thomas (cd $testroot/wt && got $cmd > $testroot/stdout \
1201 10604dce 2021-09-24 thomas 2> $testroot/stderr)
1202 d8a7bd7d 2023-06-01 thomas ret=$?
1203 d8a7bd7d 2023-06-01 thomas if [ $ret -eq 0 ]; then
1204 d8a7bd7d 2023-06-01 thomas echo "got $cmd succeeded unexpectedly" >&2
1205 d8a7bd7d 2023-06-01 thomas test_done "$testroot" "1"
1206 d8a7bd7d 2023-06-01 thomas return 1
1207 d8a7bd7d 2023-06-01 thomas fi
1208 10604dce 2021-09-24 thomas
1209 10604dce 2021-09-24 thomas echo -n > $testroot/stdout.expected
1210 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1211 fc414659 2022-04-16 thomas ret=$?
1212 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1213 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1214 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1215 10604dce 2021-09-24 thomas return 1
1216 10604dce 2021-09-24 thomas fi
1217 10604dce 2021-09-24 thomas
1218 10604dce 2021-09-24 thomas echo -n "got: a merge operation is in progress in this " \
1219 10604dce 2021-09-24 thomas > $testroot/stderr.expected
1220 10604dce 2021-09-24 thomas echo "work tree and must be continued or aborted first" \
1221 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
1222 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1223 fc414659 2022-04-16 thomas ret=$?
1224 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1225 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1226 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1227 10604dce 2021-09-24 thomas return 1
1228 10604dce 2021-09-24 thomas fi
1229 10604dce 2021-09-24 thomas done
1230 10604dce 2021-09-24 thomas
1231 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1232 10604dce 2021-09-24 thomas }
1233 10604dce 2021-09-24 thomas
1234 10604dce 2021-09-24 thomas test_merge_path_prefix() {
1235 10604dce 2021-09-24 thomas local testroot=`test_init merge_path_prefix`
1236 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
1237 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1238 10604dce 2021-09-24 thomas
1239 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
1240 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
1241 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
1242 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1243 10604dce 2021-09-24 thomas
1244 10604dce 2021-09-24 thomas got checkout -p epsilon -b master $testroot/repo $testroot/wt \
1245 10604dce 2021-09-24 thomas > /dev/null
1246 fc414659 2022-04-16 thomas ret=$?
1247 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1248 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
1249 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1250 10604dce 2021-09-24 thomas return 1
1251 10604dce 2021-09-24 thomas fi
1252 10604dce 2021-09-24 thomas
1253 10604dce 2021-09-24 thomas # create a conflicting commit
1254 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q master
1255 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
1256 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
1257 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
1258 10604dce 2021-09-24 thomas
1259 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
1260 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
1261 fc414659 2022-04-16 thomas ret=$?
1262 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1263 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
1264 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1265 10604dce 2021-09-24 thomas return 1
1266 10604dce 2021-09-24 thomas fi
1267 10604dce 2021-09-24 thomas
1268 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
1269 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
1270 fc414659 2022-04-16 thomas ret=$?
1271 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
1272 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
1273 10604dce 2021-09-24 thomas test_done "$testroot" "1"
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 echo -n "got: cannot merge branch which contains changes outside " \
1278 10604dce 2021-09-24 thomas > $testroot/stderr.expected
1279 10604dce 2021-09-24 thomas echo "of this work tree's path prefix" >> $testroot/stderr.expected
1280 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1281 fc414659 2022-04-16 thomas ret=$?
1282 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1283 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1284 10604dce 2021-09-24 thomas fi
1285 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1286 10604dce 2021-09-24 thomas }
1287 10604dce 2021-09-24 thomas
1288 10604dce 2021-09-24 thomas test_merge_missing_file() {
1289 10604dce 2021-09-24 thomas local testroot=`test_init merge_missing_file`
1290 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
1291 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1292 10604dce 2021-09-24 thomas
1293 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
1294 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
1295 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
1296 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha and delta"
1297 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1298 10604dce 2021-09-24 thomas
1299 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
1300 fc414659 2022-04-16 thomas ret=$?
1301 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1302 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
1303 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1304 10604dce 2021-09-24 thomas return 1
1305 10604dce 2021-09-24 thomas fi
1306 10604dce 2021-09-24 thomas
1307 10604dce 2021-09-24 thomas # create a conflicting commit which renames alpha
1308 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q master
1309 d1e03b8c 2023-10-08 thomas git -C $testroot/repo mv alpha epsilon/alpha-moved
1310 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "moving alpha on master"
1311 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
1312 10604dce 2021-09-24 thomas
1313 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
1314 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
1315 fc414659 2022-04-16 thomas ret=$?
1316 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1317 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
1318 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1319 10604dce 2021-09-24 thomas return 1
1320 10604dce 2021-09-24 thomas fi
1321 10604dce 2021-09-24 thomas
1322 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
1323 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
1324 fc414659 2022-04-16 thomas ret=$?
1325 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
1326 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
1327 10604dce 2021-09-24 thomas test_done "$testroot" "1"
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 echo "! alpha" > $testroot/stdout.expected
1332 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
1333 0ef68859 2021-09-28 thomas echo -n "Files which had incoming changes but could not be found " \
1334 0ef68859 2021-09-28 thomas >> $testroot/stdout.expected
1335 0ef68859 2021-09-28 thomas echo "in the work tree: 1" >> $testroot/stdout.expected
1336 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1337 fc414659 2022-04-16 thomas ret=$?
1338 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1339 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1340 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1341 10604dce 2021-09-24 thomas return 1
1342 10604dce 2021-09-24 thomas fi
1343 10604dce 2021-09-24 thomas
1344 ba162991 2021-09-28 thomas echo -n "got: changes destined for some files " \
1345 10604dce 2021-09-24 thomas > $testroot/stderr.expected
1346 10604dce 2021-09-24 thomas echo -n "were not yet merged and should be merged manually if " \
1347 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
1348 10604dce 2021-09-24 thomas echo "required before the merge operation is continued" \
1349 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
1350 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1351 fc414659 2022-04-16 thomas ret=$?
1352 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1353 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1354 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1355 10604dce 2021-09-24 thomas return 1
1356 10604dce 2021-09-24 thomas fi
1357 10604dce 2021-09-24 thomas
1358 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1359 10604dce 2021-09-24 thomas
1360 10604dce 2021-09-24 thomas echo "M gamma/delta" > $testroot/stdout.expected
1361 2d7ce510 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1362 fc414659 2022-04-16 thomas ret=$?
1363 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1364 2d7ce510 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1365 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1366 2d7ce510 2021-09-24 thomas return 1
1367 2d7ce510 2021-09-24 thomas fi
1368 2d7ce510 2021-09-24 thomas
1369 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1370 2d7ce510 2021-09-24 thomas }
1371 2d7ce510 2021-09-24 thomas
1372 2d7ce510 2021-09-24 thomas test_merge_no_op() {
1373 2d7ce510 2021-09-24 thomas local testroot=`test_init merge_no_op`
1374 2d7ce510 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
1375 2d7ce510 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1376 2d7ce510 2021-09-24 thomas
1377 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
1378 2d7ce510 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
1379 2d7ce510 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
1380 1678610c 2023-04-22 thomas local branch_commit=`git_show_branch_head $testroot/repo newbranch`
1381 2d7ce510 2021-09-24 thomas
1382 2d7ce510 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
1383 fc414659 2022-04-16 thomas ret=$?
1384 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1385 2d7ce510 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
1386 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1387 2d7ce510 2021-09-24 thomas return 1
1388 2d7ce510 2021-09-24 thomas fi
1389 2d7ce510 2021-09-24 thomas
1390 2d7ce510 2021-09-24 thomas # create a conflicting commit
1391 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q master
1392 2d7ce510 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
1393 2d7ce510 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
1394 2d7ce510 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
1395 2d7ce510 2021-09-24 thomas
1396 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
1397 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
1398 fc414659 2022-04-16 thomas ret=$?
1399 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1400 2d7ce510 2021-09-24 thomas echo "got update failed unexpectedly" >&2
1401 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1402 2d7ce510 2021-09-24 thomas return 1
1403 2d7ce510 2021-09-24 thomas fi
1404 2d7ce510 2021-09-24 thomas
1405 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
1406 2d7ce510 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
1407 fc414659 2022-04-16 thomas ret=$?
1408 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
1409 2d7ce510 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
1410 2d7ce510 2021-09-24 thomas test_done "$testroot" "1"
1411 2d7ce510 2021-09-24 thomas return 1
1412 2d7ce510 2021-09-24 thomas fi
1413 2d7ce510 2021-09-24 thomas
1414 2d7ce510 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
1415 2d7ce510 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1416 2d7ce510 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1417 fc414659 2022-04-16 thomas ret=$?
1418 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1419 2d7ce510 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1420 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1421 2d7ce510 2021-09-24 thomas return 1
1422 2d7ce510 2021-09-24 thomas fi
1423 2d7ce510 2021-09-24 thomas
1424 2d7ce510 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
1425 2d7ce510 2021-09-24 thomas > $testroot/stderr.expected
1426 2d7ce510 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1427 fc414659 2022-04-16 thomas ret=$?
1428 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1429 2d7ce510 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1430 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1431 2d7ce510 2021-09-24 thomas return 1
1432 2d7ce510 2021-09-24 thomas fi
1433 2d7ce510 2021-09-24 thomas
1434 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1435 2d7ce510 2021-09-24 thomas
1436 2d7ce510 2021-09-24 thomas echo "C alpha" > $testroot/stdout.expected
1437 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1438 fc414659 2022-04-16 thomas ret=$?
1439 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1440 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1441 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1442 10604dce 2021-09-24 thomas return 1
1443 10604dce 2021-09-24 thomas fi
1444 10604dce 2021-09-24 thomas
1445 2d7ce510 2021-09-24 thomas # resolve the conflict by reverting all changes; now it is no-op merge
1446 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got revert alpha > /dev/null)
1447 fc414659 2022-04-16 thomas ret=$?
1448 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1449 2d7ce510 2021-09-24 thomas echo "got revert failed unexpectedly" >&2
1450 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1451 2d7ce510 2021-09-24 thomas return 1
1452 2d7ce510 2021-09-24 thomas fi
1453 2d7ce510 2021-09-24 thomas
1454 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got merge -c > $testroot/stdout \
1455 2d7ce510 2021-09-24 thomas 2> $testroot/stderr)
1456 fc414659 2022-04-16 thomas ret=$?
1457 1678610c 2023-04-22 thomas if [ $ret -ne 0 ]; then
1458 1678610c 2023-04-22 thomas echo "got merge failed unexpectedly" >&2
1459 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1460 2d7ce510 2021-09-24 thomas return 1
1461 2d7ce510 2021-09-24 thomas fi
1462 2d7ce510 2021-09-24 thomas
1463 1678610c 2023-04-22 thomas echo -n '' > $testroot/stderr.expected
1464 2d7ce510 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1465 fc414659 2022-04-16 thomas ret=$?
1466 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1467 2d7ce510 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1468 1678610c 2023-04-22 thomas test_done "$testroot" "$ret"
1469 1678610c 2023-04-22 thomas return 1
1470 1678610c 2023-04-22 thomas fi
1471 1678610c 2023-04-22 thomas
1472 1678610c 2023-04-22 thomas local merge_commit=`git_show_head $testroot/repo`
1473 1678610c 2023-04-22 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1474 1678610c 2023-04-22 thomas > $testroot/stdout.expected
1475 1678610c 2023-04-22 thomas echo $merge_commit >> $testroot/stdout.expected
1476 1678610c 2023-04-22 thomas
1477 1678610c 2023-04-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1478 1678610c 2023-04-22 thomas ret=$?
1479 1678610c 2023-04-22 thomas if [ $ret -ne 0 ]; then
1480 1678610c 2023-04-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1481 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1482 2d7ce510 2021-09-24 thomas return 1
1483 2d7ce510 2021-09-24 thomas fi
1484 2d7ce510 2021-09-24 thomas
1485 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1486 2d7ce510 2021-09-24 thomas
1487 2d7ce510 2021-09-24 thomas echo -n "" > $testroot/stdout.expected
1488 768705e3 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1489 fc414659 2022-04-16 thomas ret=$?
1490 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1491 768705e3 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1492 1678610c 2023-04-22 thomas test_done "$testroot" "$ret"
1493 1678610c 2023-04-22 thomas return 1
1494 768705e3 2021-09-27 thomas fi
1495 1678610c 2023-04-22 thomas
1496 1678610c 2023-04-22 thomas # We should have created a merge commit with two parents.
1497 1678610c 2023-04-22 thomas got log -r $testroot/repo -l1 -c $merge_commit | grep ^parent \
1498 1678610c 2023-04-22 thomas > $testroot/stdout
1499 1678610c 2023-04-22 thomas echo "parent 1: $master_commit" > $testroot/stdout.expected
1500 1678610c 2023-04-22 thomas echo "parent 2: $branch_commit" >> $testroot/stdout.expected
1501 1678610c 2023-04-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1502 1678610c 2023-04-22 thomas ret=$?
1503 1678610c 2023-04-22 thomas if [ $ret -ne 0 ]; then
1504 1678610c 2023-04-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1505 1678610c 2023-04-22 thomas fi
1506 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1507 768705e3 2021-09-27 thomas }
1508 768705e3 2021-09-27 thomas
1509 768705e3 2021-09-27 thomas test_merge_imported_branch() {
1510 768705e3 2021-09-27 thomas local testroot=`test_init merge_import`
1511 768705e3 2021-09-27 thomas local commit0=`git_show_head $testroot/repo`
1512 768705e3 2021-09-27 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1513 768705e3 2021-09-27 thomas
1514 768705e3 2021-09-27 thomas # import a new sub-tree to the 'files' branch such that
1515 768705e3 2021-09-27 thomas # none of the files added here collide with existing ones
1516 768705e3 2021-09-27 thomas mkdir -p $testroot/tree/there
1517 768705e3 2021-09-27 thomas mkdir -p $testroot/tree/be/lots
1518 768705e3 2021-09-27 thomas mkdir -p $testroot/tree/files
1519 768705e3 2021-09-27 thomas echo "there should" > $testroot/tree/there/should
1520 768705e3 2021-09-27 thomas echo "be lots of" > $testroot/tree/be/lots/of
1521 768705e3 2021-09-27 thomas echo "files here" > $testroot/tree/files/here
1522 768705e3 2021-09-27 thomas got import -r $testroot/repo -b files -m 'import files' \
1523 768705e3 2021-09-27 thomas $testroot/tree > /dev/null
1524 768705e3 2021-09-27 thomas
1525 768705e3 2021-09-27 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
1526 fc414659 2022-04-16 thomas ret=$?
1527 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1528 768705e3 2021-09-27 thomas echo "got checkout failed unexpectedly" >&2
1529 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1530 768705e3 2021-09-27 thomas return 1
1531 768705e3 2021-09-27 thomas fi
1532 768705e3 2021-09-27 thomas
1533 768705e3 2021-09-27 thomas (cd $testroot/wt && got merge files > $testroot/stdout)
1534 fc414659 2022-04-16 thomas ret=$?
1535 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1536 768705e3 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1537 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1538 768705e3 2021-09-27 thomas return 1
1539 768705e3 2021-09-27 thomas fi
1540 768705e3 2021-09-27 thomas
1541 768705e3 2021-09-27 thomas local merge_commit0=`git_show_head $testroot/repo`
1542 768705e3 2021-09-27 thomas cat > $testroot/stdout.expected <<EOF
1543 768705e3 2021-09-27 thomas A be/lots/of
1544 768705e3 2021-09-27 thomas A files/here
1545 768705e3 2021-09-27 thomas A there/should
1546 768705e3 2021-09-27 thomas Merged refs/heads/files into refs/heads/master: $merge_commit0
1547 768705e3 2021-09-27 thomas EOF
1548 768705e3 2021-09-27 thomas cmp -s $testroot/stdout.expected $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 diff -u $testroot/stdout.expected $testroot/stdout
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 # try to merge again while no new changes are available
1557 768705e3 2021-09-27 thomas (cd $testroot/wt && got merge files > $testroot/stdout)
1558 fc414659 2022-04-16 thomas ret=$?
1559 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1560 768705e3 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1561 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1562 768705e3 2021-09-27 thomas return 1
1563 768705e3 2021-09-27 thomas fi
1564 768705e3 2021-09-27 thomas echo "Already up-to-date" > $testroot/stdout.expected
1565 2d7ce510 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1566 fc414659 2022-04-16 thomas ret=$?
1567 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1568 2d7ce510 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1569 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1570 768705e3 2021-09-27 thomas return 1
1571 2d7ce510 2021-09-24 thomas fi
1572 768705e3 2021-09-27 thomas
1573 768705e3 2021-09-27 thomas # update the 'files' branch
1574 d1e03b8c 2023-10-08 thomas git -C $testroot/repo reset -q --hard master
1575 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q files
1576 768705e3 2021-09-27 thomas echo "indeed" > $testroot/repo/indeed
1577 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add indeed
1578 768705e3 2021-09-27 thomas git_commit $testroot/repo -m "adding another file indeed"
1579 768705e3 2021-09-27 thomas echo "be lots and lots of" > $testroot/repo/be/lots/of
1580 768705e3 2021-09-27 thomas git_commit $testroot/repo -m "lots of changes"
1581 768705e3 2021-09-27 thomas
1582 768705e3 2021-09-27 thomas (cd $testroot/wt && got update > /dev/null)
1583 fc414659 2022-04-16 thomas ret=$?
1584 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1585 768705e3 2021-09-27 thomas echo "got update failed unexpectedly" >&2
1586 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1587 768705e3 2021-09-27 thomas return 1
1588 768705e3 2021-09-27 thomas fi
1589 768705e3 2021-09-27 thomas
1590 768705e3 2021-09-27 thomas # we should now be able to merge more changes from files branch
1591 768705e3 2021-09-27 thomas (cd $testroot/wt && got merge files > $testroot/stdout)
1592 fc414659 2022-04-16 thomas ret=$?
1593 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1594 768705e3 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1595 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1596 768705e3 2021-09-27 thomas return 1
1597 768705e3 2021-09-27 thomas fi
1598 768705e3 2021-09-27 thomas
1599 768705e3 2021-09-27 thomas local merge_commit1=`git_show_branch_head $testroot/repo master`
1600 768705e3 2021-09-27 thomas cat > $testroot/stdout.expected <<EOF
1601 768705e3 2021-09-27 thomas G be/lots/of
1602 768705e3 2021-09-27 thomas A indeed
1603 768705e3 2021-09-27 thomas Merged refs/heads/files into refs/heads/master: $merge_commit1
1604 768705e3 2021-09-27 thomas EOF
1605 768705e3 2021-09-27 thomas
1606 768705e3 2021-09-27 thomas cmp -s $testroot/stdout.expected $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 diff -u $testroot/stdout.expected $testroot/stdout
1610 768705e3 2021-09-27 thomas fi
1611 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1612 10604dce 2021-09-24 thomas }
1613 ba34626b 2021-09-27 thomas
1614 ba34626b 2021-09-27 thomas test_merge_interrupt() {
1615 ba34626b 2021-09-27 thomas local testroot=`test_init merge_interrupt`
1616 ba34626b 2021-09-27 thomas local commit0=`git_show_head $testroot/repo`
1617 ba34626b 2021-09-27 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1618 ba34626b 2021-09-27 thomas
1619 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
1620 ba34626b 2021-09-27 thomas echo "modified alpha on branch" > $testroot/repo/alpha
1621 ba34626b 2021-09-27 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
1622 ba34626b 2021-09-27 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1623 ba34626b 2021-09-27 thomas
1624 ba34626b 2021-09-27 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
1625 fc414659 2022-04-16 thomas ret=$?
1626 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1627 ba34626b 2021-09-27 thomas echo "got checkout failed unexpectedly" >&2
1628 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1629 ba34626b 2021-09-27 thomas return 1
1630 ba34626b 2021-09-27 thomas fi
1631 ba34626b 2021-09-27 thomas
1632 ba34626b 2021-09-27 thomas # create a non-conflicting commit
1633 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q master
1634 ba34626b 2021-09-27 thomas echo "modified beta on master" > $testroot/repo/beta
1635 ba34626b 2021-09-27 thomas git_commit $testroot/repo -m "committing to beta on master"
1636 ba34626b 2021-09-27 thomas local master_commit=`git_show_head $testroot/repo`
1637 10604dce 2021-09-24 thomas
1638 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
1639 ba34626b 2021-09-27 thomas (cd $testroot/wt && got update > /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 update 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 (cd $testroot/wt && got merge -n newbranch \
1648 ba34626b 2021-09-27 thomas > $testroot/stdout 2> $testroot/stderr)
1649 fc414659 2022-04-16 thomas ret=$?
1650 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1651 ba34626b 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1652 ba34626b 2021-09-27 thomas test_done "$testroot" "1"
1653 ba34626b 2021-09-27 thomas return 1
1654 ba34626b 2021-09-27 thomas fi
1655 ba34626b 2021-09-27 thomas
1656 ba34626b 2021-09-27 thomas echo "G alpha" > $testroot/stdout.expected
1657 ba34626b 2021-09-27 thomas echo "Merge of refs/heads/newbranch interrupted on request" \
1658 ba34626b 2021-09-27 thomas >> $testroot/stdout.expected
1659 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1660 fc414659 2022-04-16 thomas ret=$?
1661 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1662 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1663 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1664 ba34626b 2021-09-27 thomas return 1
1665 ba34626b 2021-09-27 thomas fi
1666 ba34626b 2021-09-27 thomas
1667 ba34626b 2021-09-27 thomas (cd $testroot/wt && got status > $testroot/stdout)
1668 ba34626b 2021-09-27 thomas
1669 ba34626b 2021-09-27 thomas echo "M alpha" > $testroot/stdout.expected
1670 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1671 fc414659 2022-04-16 thomas ret=$?
1672 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1673 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1674 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1675 ba34626b 2021-09-27 thomas return 1
1676 ba34626b 2021-09-27 thomas fi
1677 ba34626b 2021-09-27 thomas
1678 ba34626b 2021-09-27 thomas echo "modified alpha on branch" > $testroot/content.expected
1679 ba34626b 2021-09-27 thomas cat $testroot/wt/alpha > $testroot/content
1680 ba34626b 2021-09-27 thomas cmp -s $testroot/content.expected $testroot/content
1681 fc414659 2022-04-16 thomas ret=$?
1682 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1683 ba34626b 2021-09-27 thomas diff -u $testroot/content.expected $testroot/content
1684 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1685 ba34626b 2021-09-27 thomas return 1
1686 ba34626b 2021-09-27 thomas fi
1687 ba34626b 2021-09-27 thomas
1688 ba34626b 2021-09-27 thomas # adjust merge result
1689 ba34626b 2021-09-27 thomas echo "adjusted merge result" > $testroot/wt/alpha
1690 ba34626b 2021-09-27 thomas
1691 ba34626b 2021-09-27 thomas # continue the merge
1692 ba34626b 2021-09-27 thomas (cd $testroot/wt && got merge -c > $testroot/stdout)
1693 fc414659 2022-04-16 thomas ret=$?
1694 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1695 ba34626b 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1696 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1697 ba34626b 2021-09-27 thomas return 1
1698 ba34626b 2021-09-27 thomas fi
1699 ba34626b 2021-09-27 thomas
1700 ba34626b 2021-09-27 thomas local merge_commit=`git_show_head $testroot/repo`
1701 ba34626b 2021-09-27 thomas
1702 ae1e948a 2021-09-28 thomas echo "M alpha" > $testroot/stdout.expected
1703 ba34626b 2021-09-27 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1704 ae1e948a 2021-09-28 thomas >> $testroot/stdout.expected
1705 ba34626b 2021-09-27 thomas echo $merge_commit >> $testroot/stdout.expected
1706 ba34626b 2021-09-27 thomas
1707 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1708 fc414659 2022-04-16 thomas ret=$?
1709 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1710 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1711 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1712 ba34626b 2021-09-27 thomas return 1
1713 ba34626b 2021-09-27 thomas fi
1714 ba34626b 2021-09-27 thomas
1715 ba34626b 2021-09-27 thomas (cd $testroot/wt && got status > $testroot/stdout)
1716 ba34626b 2021-09-27 thomas
1717 ba34626b 2021-09-27 thomas echo -n > $testroot/stdout.expected
1718 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1719 fc414659 2022-04-16 thomas ret=$?
1720 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1721 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1722 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1723 ba34626b 2021-09-27 thomas return 1
1724 ba34626b 2021-09-27 thomas fi
1725 ba34626b 2021-09-27 thomas
1726 ba34626b 2021-09-27 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1727 ba34626b 2021-09-27 thomas echo "commit $merge_commit (master)" > $testroot/stdout.expected
1728 ba34626b 2021-09-27 thomas echo "commit $master_commit" >> $testroot/stdout.expected
1729 ba34626b 2021-09-27 thomas echo "commit $commit0" >> $testroot/stdout.expected
1730 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1731 fc414659 2022-04-16 thomas ret=$?
1732 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1733 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1734 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1735 ba34626b 2021-09-27 thomas return 1
1736 ba34626b 2021-09-27 thomas fi
1737 ba34626b 2021-09-27 thomas
1738 ba34626b 2021-09-27 thomas (cd $testroot/wt && got update > $testroot/stdout)
1739 ba34626b 2021-09-27 thomas
1740 ba34626b 2021-09-27 thomas echo 'Already up-to-date' > $testroot/stdout.expected
1741 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1742 fc414659 2022-04-16 thomas ret=$?
1743 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1744 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1745 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1746 ba34626b 2021-09-27 thomas return 1
1747 ba34626b 2021-09-27 thomas fi
1748 ba34626b 2021-09-27 thomas
1749 ba34626b 2021-09-27 thomas # We should have created a merge commit with two parents.
1750 ba34626b 2021-09-27 thomas (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
1751 ba34626b 2021-09-27 thomas echo "parent 1: $master_commit" > $testroot/stdout.expected
1752 ba34626b 2021-09-27 thomas echo "parent 2: $branch_commit0" >> $testroot/stdout.expected
1753 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1754 fc414659 2022-04-16 thomas ret=$?
1755 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1756 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1757 ba34626b 2021-09-27 thomas fi
1758 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1759 a2c162eb 2022-10-30 thomas }
1760 a2c162eb 2022-10-30 thomas
1761 a2c162eb 2022-10-30 thomas test_merge_umask() {
1762 a2c162eb 2022-10-30 thomas local testroot=`test_init merge_umask`
1763 a2c162eb 2022-10-30 thomas
1764 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
1765 a2c162eb 2022-10-30 thomas echo "modified alpha on branch" >$testroot/repo/alpha
1766 a2c162eb 2022-10-30 thomas git_commit "$testroot/repo" -m "committing alpha on newbranch"
1767 a2c162eb 2022-10-30 thomas echo "modified delta on branch" >$testroot/repo/gamma/delta
1768 a2c162eb 2022-10-30 thomas git_commit "$testroot/repo" -m "committing delta on newbranch"
1769 a2c162eb 2022-10-30 thomas
1770 a2c162eb 2022-10-30 thomas # diverge from newbranch
1771 d1e03b8c 2023-10-08 thomas git -C "$testroot/repo" checkout -q master
1772 a2c162eb 2022-10-30 thomas echo "modified beta on master" >$testroot/repo/beta
1773 a2c162eb 2022-10-30 thomas git_commit "$testroot/repo" -m "committing zeto no master"
1774 a2c162eb 2022-10-30 thomas
1775 a2c162eb 2022-10-30 thomas got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1776 a2c162eb 2022-10-30 thomas
1777 a2c162eb 2022-10-30 thomas # using a subshell to avoid clobbering global umask
1778 a2c162eb 2022-10-30 thomas (umask 077 && cd "$testroot/wt" && got merge newbranch) >/dev/null
1779 a2c162eb 2022-10-30 thomas
1780 a2c162eb 2022-10-30 thomas for f in alpha gamma/delta; do
1781 a2c162eb 2022-10-30 thomas ls -l "$testroot/wt/$f" | grep -q ^-rw-------
1782 a2c162eb 2022-10-30 thomas if [ $? -ne 0 ]; then
1783 a2c162eb 2022-10-30 thomas echo "$f is not 0600 after merge" >&2
1784 a2c162eb 2022-10-30 thomas ls -l "$testroot/wt/$f" >&2
1785 a2c162eb 2022-10-30 thomas test_done "$testroot" 1
1786 a2c162eb 2022-10-30 thomas fi
1787 a2c162eb 2022-10-30 thomas done
1788 a2c162eb 2022-10-30 thomas
1789 a2c162eb 2022-10-30 thomas test_done "$testroot" 0
1790 ba34626b 2021-09-27 thomas }
1791 b16f1832 2023-02-21 thomas
1792 b16f1832 2023-02-21 thomas test_merge_gitconfig_author() {
1793 b16f1832 2023-02-21 thomas local testroot=`test_init merge_gitconfig_author`
1794 b16f1832 2023-02-21 thomas
1795 d1e03b8c 2023-10-08 thomas git -C $testroot/repo config user.name 'Flan Luck'
1796 d1e03b8c 2023-10-08 thomas git -C $testroot/repo config user.email 'flan_luck@openbsd.org'
1797 b16f1832 2023-02-21 thomas
1798 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
1799 b16f1832 2023-02-21 thomas echo "modified alpha on branch" >$testroot/repo/alpha
1800 b16f1832 2023-02-21 thomas git_commit "$testroot/repo" -m "committing alpha on newbranch"
1801 b16f1832 2023-02-21 thomas echo "modified delta on branch" >$testroot/repo/gamma/delta
1802 b16f1832 2023-02-21 thomas git_commit "$testroot/repo" -m "committing delta on newbranch"
1803 ba34626b 2021-09-27 thomas
1804 b16f1832 2023-02-21 thomas # diverge from newbranch
1805 d1e03b8c 2023-10-08 thomas git -C "$testroot/repo" checkout -q master
1806 b16f1832 2023-02-21 thomas echo "modified beta on master" >$testroot/repo/beta
1807 b16f1832 2023-02-21 thomas git_commit "$testroot/repo" -m "committing zeto no master"
1808 b16f1832 2023-02-21 thomas
1809 b16f1832 2023-02-21 thomas got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1810 b16f1832 2023-02-21 thomas
1811 b16f1832 2023-02-21 thomas # unset in a subshell to avoid affecting our environment
1812 b16f1832 2023-02-21 thomas (unset GOT_IGNORE_GITCONFIG && cd $testroot/wt && \
1813 b16f1832 2023-02-21 thomas got merge newbranch > /dev/null)
1814 b16f1832 2023-02-21 thomas
1815 b16f1832 2023-02-21 thomas (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
1816 b16f1832 2023-02-21 thomas ret=$?
1817 b16f1832 2023-02-21 thomas if [ $ret -ne 0 ]; then
1818 b16f1832 2023-02-21 thomas test_done "$testroot" "$ret"
1819 b16f1832 2023-02-21 thomas return 1
1820 b16f1832 2023-02-21 thomas fi
1821 b16f1832 2023-02-21 thomas
1822 b16f1832 2023-02-21 thomas echo "from: Flan Luck <flan_luck@openbsd.org>" \
1823 b16f1832 2023-02-21 thomas > $testroot/stdout.expected
1824 b16f1832 2023-02-21 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1825 b16f1832 2023-02-21 thomas ret=$?
1826 b16f1832 2023-02-21 thomas if [ $ret -ne 0 ]; then
1827 b16f1832 2023-02-21 thomas diff -u $testroot/stdout.expected $testroot/stdout
1828 b16f1832 2023-02-21 thomas fi
1829 b16f1832 2023-02-21 thomas test_done "$testroot" "$ret"
1830 b16f1832 2023-02-21 thomas }
1831 4434a15a 2023-06-22 thomas
1832 4434a15a 2023-06-22 thomas test_merge_fetched_branch() {
1833 4434a15a 2023-06-22 thomas local testroot=`test_init merge_fetched_branch`
1834 4434a15a 2023-06-22 thomas local testurl=ssh://127.0.0.1/$testroot
1835 4434a15a 2023-06-22 thomas local commit_id=`git_show_head $testroot/repo`
1836 4434a15a 2023-06-22 thomas
1837 4434a15a 2023-06-22 thomas got clone -q $testurl/repo $testroot/repo-clone
1838 4434a15a 2023-06-22 thomas ret=$?
1839 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1840 4434a15a 2023-06-22 thomas echo "got clone command failed unexpectedly" >&2
1841 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1842 4434a15a 2023-06-22 thomas return 1
1843 4434a15a 2023-06-22 thomas fi
1844 b16f1832 2023-02-21 thomas
1845 4434a15a 2023-06-22 thomas echo "modified alpha" > $testroot/repo/alpha
1846 4434a15a 2023-06-22 thomas git_commit $testroot/repo -m "modified alpha"
1847 4434a15a 2023-06-22 thomas local commit_id2=`git_show_head $testroot/repo`
1848 4434a15a 2023-06-22 thomas
1849 4434a15a 2023-06-22 thomas got fetch -q -r $testroot/repo-clone > $testroot/stdout
1850 4434a15a 2023-06-22 thomas ret=$?
1851 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1852 4434a15a 2023-06-22 thomas echo "got fetch command failed unexpectedly" >&2
1853 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1854 4434a15a 2023-06-22 thomas return 1
1855 4434a15a 2023-06-22 thomas fi
1856 4434a15a 2023-06-22 thomas
1857 4434a15a 2023-06-22 thomas echo -n > $testroot/stdout.expected
1858 4434a15a 2023-06-22 thomas
1859 4434a15a 2023-06-22 thomas cmp -s $testroot/stdout $testroot/stdout.expected
1860 4434a15a 2023-06-22 thomas ret=$?
1861 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1862 4434a15a 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1863 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1864 4434a15a 2023-06-22 thomas return 1
1865 4434a15a 2023-06-22 thomas fi
1866 4434a15a 2023-06-22 thomas
1867 4434a15a 2023-06-22 thomas got ref -l -r $testroot/repo-clone > $testroot/stdout
1868 4434a15a 2023-06-22 thomas
1869 4434a15a 2023-06-22 thomas echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1870 4434a15a 2023-06-22 thomas echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1871 4434a15a 2023-06-22 thomas echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1872 4434a15a 2023-06-22 thomas >> $testroot/stdout.expected
1873 4434a15a 2023-06-22 thomas echo "refs/remotes/origin/master: $commit_id2" \
1874 4434a15a 2023-06-22 thomas >> $testroot/stdout.expected
1875 4434a15a 2023-06-22 thomas
1876 4434a15a 2023-06-22 thomas cmp -s $testroot/stdout $testroot/stdout.expected
1877 4434a15a 2023-06-22 thomas ret=$?
1878 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1879 4434a15a 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1880 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1881 4434a15a 2023-06-22 thomas return 1
1882 4434a15a 2023-06-22 thomas fi
1883 4434a15a 2023-06-22 thomas
1884 4434a15a 2023-06-22 thomas got checkout $testroot/repo-clone $testroot/wt > /dev/null
1885 4434a15a 2023-06-22 thomas
1886 4434a15a 2023-06-22 thomas echo "modified beta" > $testroot/wt/beta
1887 4434a15a 2023-06-22 thomas (cd $testroot/wt && got commit -m "modified beta" > /dev/null)
1888 4434a15a 2023-06-22 thomas local commit_id3=`git_show_head $testroot/repo-clone`
1889 4434a15a 2023-06-22 thomas
1890 4434a15a 2023-06-22 thomas (cd $testroot/wt && got update > /dev/null)
1891 4434a15a 2023-06-22 thomas (cd $testroot/wt && got merge origin/master > $testroot/stdout)
1892 4434a15a 2023-06-22 thomas local merge_commit_id=`git_show_head $testroot/repo-clone`
1893 4434a15a 2023-06-22 thomas
1894 4434a15a 2023-06-22 thomas cat > $testroot/stdout.expected <<EOF
1895 4434a15a 2023-06-22 thomas G alpha
1896 4434a15a 2023-06-22 thomas Merged refs/remotes/origin/master into refs/heads/master: $merge_commit_id
1897 4434a15a 2023-06-22 thomas EOF
1898 4434a15a 2023-06-22 thomas
1899 4434a15a 2023-06-22 thomas cmp -s $testroot/stdout $testroot/stdout.expected
1900 4434a15a 2023-06-22 thomas ret=$?
1901 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1902 4434a15a 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1903 4434a15a 2023-06-22 thomas fi
1904 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1905 4434a15a 2023-06-22 thomas }
1906 4434a15a 2023-06-22 thomas
1907 4434a15a 2023-06-22 thomas test_merge_fetched_branch_remote() {
1908 4434a15a 2023-06-22 thomas local testroot=`test_init merge_fetched_branch_remote`
1909 4434a15a 2023-06-22 thomas local testurl=ssh://127.0.0.1/$testroot
1910 4434a15a 2023-06-22 thomas local commit_id=`git_show_head $testroot/repo`
1911 4434a15a 2023-06-22 thomas
1912 4434a15a 2023-06-22 thomas got clone -q $testurl/repo $testroot/repo-clone
1913 4434a15a 2023-06-22 thomas ret=$?
1914 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1915 4434a15a 2023-06-22 thomas echo "got clone command failed unexpectedly" >&2
1916 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1917 4434a15a 2023-06-22 thomas return 1
1918 4434a15a 2023-06-22 thomas fi
1919 4434a15a 2023-06-22 thomas
1920 4434a15a 2023-06-22 thomas echo "modified alpha" > $testroot/repo/alpha
1921 4434a15a 2023-06-22 thomas git_commit $testroot/repo -m "modified alpha"
1922 4434a15a 2023-06-22 thomas local commit_id2=`git_show_head $testroot/repo`
1923 4434a15a 2023-06-22 thomas
1924 4434a15a 2023-06-22 thomas got fetch -q -r $testroot/repo-clone > $testroot/stdout
1925 4434a15a 2023-06-22 thomas ret=$?
1926 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1927 4434a15a 2023-06-22 thomas echo "got fetch command failed unexpectedly" >&2
1928 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1929 4434a15a 2023-06-22 thomas return 1
1930 4434a15a 2023-06-22 thomas fi
1931 4434a15a 2023-06-22 thomas
1932 4434a15a 2023-06-22 thomas echo -n > $testroot/stdout.expected
1933 4434a15a 2023-06-22 thomas
1934 4434a15a 2023-06-22 thomas cmp -s $testroot/stdout $testroot/stdout.expected
1935 4434a15a 2023-06-22 thomas ret=$?
1936 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1937 4434a15a 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1938 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1939 4434a15a 2023-06-22 thomas return 1
1940 4434a15a 2023-06-22 thomas fi
1941 4434a15a 2023-06-22 thomas
1942 4434a15a 2023-06-22 thomas got ref -l -r $testroot/repo-clone > $testroot/stdout
1943 4434a15a 2023-06-22 thomas
1944 4434a15a 2023-06-22 thomas echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1945 4434a15a 2023-06-22 thomas echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1946 4434a15a 2023-06-22 thomas echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1947 4434a15a 2023-06-22 thomas >> $testroot/stdout.expected
1948 4434a15a 2023-06-22 thomas echo "refs/remotes/origin/master: $commit_id2" \
1949 4434a15a 2023-06-22 thomas >> $testroot/stdout.expected
1950 4434a15a 2023-06-22 thomas
1951 4434a15a 2023-06-22 thomas cmp -s $testroot/stdout $testroot/stdout.expected
1952 4434a15a 2023-06-22 thomas ret=$?
1953 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1954 4434a15a 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1955 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1956 4434a15a 2023-06-22 thomas return 1
1957 4434a15a 2023-06-22 thomas fi
1958 4434a15a 2023-06-22 thomas
1959 4434a15a 2023-06-22 thomas got checkout $testroot/repo-clone $testroot/wt > /dev/null
1960 4434a15a 2023-06-22 thomas
1961 4434a15a 2023-06-22 thomas echo "modified beta" > $testroot/wt/beta
1962 4434a15a 2023-06-22 thomas (cd $testroot/wt && got commit -m "modified beta" > /dev/null)
1963 4434a15a 2023-06-22 thomas local commit_id3=`git_show_head $testroot/repo-clone`
1964 4434a15a 2023-06-22 thomas
1965 4434a15a 2023-06-22 thomas (cd $testroot/wt && got update -b origin/master > /dev/null)
1966 4434a15a 2023-06-22 thomas (cd $testroot/wt && got merge master > \
1967 4434a15a 2023-06-22 thomas $testroot/stdout 2> $testroot/stderr)
1968 4434a15a 2023-06-22 thomas local merge_commit_id=`git_show_head $testroot/repo-clone`
1969 4434a15a 2023-06-22 thomas
1970 4434a15a 2023-06-22 thomas echo -n > $testroot/stdout.expected
1971 4434a15a 2023-06-22 thomas
1972 4434a15a 2023-06-22 thomas cmp -s $testroot/stdout $testroot/stdout.expected
1973 4434a15a 2023-06-22 thomas ret=$?
1974 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1975 4434a15a 2023-06-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1976 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1977 4434a15a 2023-06-22 thomas return 1
1978 4434a15a 2023-06-22 thomas fi
1979 4434a15a 2023-06-22 thomas
1980 4434a15a 2023-06-22 thomas echo -n "got: work tree's current branch refs/remotes/origin/master " \
1981 4434a15a 2023-06-22 thomas > $testroot/stderr.expected
1982 4434a15a 2023-06-22 thomas echo -n 'is outside the "refs/heads/" reference namespace; ' \
1983 4434a15a 2023-06-22 thomas >> $testroot/stderr.expected
1984 4434a15a 2023-06-22 thomas echo -n "update -b required: will not commit to a branch " \
1985 4434a15a 2023-06-22 thomas >> $testroot/stderr.expected
1986 4434a15a 2023-06-22 thomas echo 'outside the "refs/heads/" reference namespace' \
1987 4434a15a 2023-06-22 thomas >> $testroot/stderr.expected
1988 4434a15a 2023-06-22 thomas
1989 4434a15a 2023-06-22 thomas cmp -s $testroot/stderr $testroot/stderr.expected
1990 4434a15a 2023-06-22 thomas ret=$?
1991 4434a15a 2023-06-22 thomas if [ $ret -ne 0 ]; then
1992 4434a15a 2023-06-22 thomas diff -u $testroot/stderr.expected $testroot/stderr
1993 4434a15a 2023-06-22 thomas fi
1994 4434a15a 2023-06-22 thomas test_done "$testroot" "$ret"
1995 4434a15a 2023-06-22 thomas }
1996 4434a15a 2023-06-22 thomas
1997 10604dce 2021-09-24 thomas test_parseargs "$@"
1998 10604dce 2021-09-24 thomas run_test test_merge_basic
1999 2b72f32d 2023-06-22 thomas run_test test_merge_forward
2000 31009ade 2023-07-05 thomas run_test test_merge_forward_commit
2001 31009ade 2023-07-05 thomas run_test test_merge_forward_interrupt
2002 2b72f32d 2023-06-22 thomas run_test test_merge_backward
2003 10604dce 2021-09-24 thomas run_test test_merge_continue
2004 fe3f264b 2023-06-08 thomas run_test test_merge_continue_new_commit
2005 10604dce 2021-09-24 thomas run_test test_merge_abort
2006 10604dce 2021-09-24 thomas run_test test_merge_in_progress
2007 10604dce 2021-09-24 thomas run_test test_merge_path_prefix
2008 10604dce 2021-09-24 thomas run_test test_merge_missing_file
2009 2d7ce510 2021-09-24 thomas run_test test_merge_no_op
2010 768705e3 2021-09-27 thomas run_test test_merge_imported_branch
2011 ba34626b 2021-09-27 thomas run_test test_merge_interrupt
2012 a2c162eb 2022-10-30 thomas run_test test_merge_umask
2013 b16f1832 2023-02-21 thomas run_test test_merge_gitconfig_author
2014 4434a15a 2023-06-22 thomas run_test test_merge_fetched_branch
2015 4434a15a 2023-06-22 thomas run_test test_merge_fetched_branch_remote