Blame


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