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 b6b86fd1 2022-08-30 thomas # need a divergant commit on the main branch for 'got merge'
56 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
57 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
58 fc414659 2022-04-16 thomas ret=$?
59 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
60 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
61 10604dce 2021-09-24 thomas test_done "$testroot" "1"
62 10604dce 2021-09-24 thomas return 1
63 10604dce 2021-09-24 thomas fi
64 10604dce 2021-09-24 thomas echo -n "got: cannot create a merge commit because " \
65 10604dce 2021-09-24 thomas > $testroot/stderr.expected
66 10604dce 2021-09-24 thomas echo -n "refs/heads/newbranch is based on refs/heads/master; " \
67 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
68 10604dce 2021-09-24 thomas echo -n "refs/heads/newbranch can be integrated with " \
69 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
70 10604dce 2021-09-24 thomas echo "'got integrate' instead" >> $testroot/stderr.expected
71 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
72 fc414659 2022-04-16 thomas ret=$?
73 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
74 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
75 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
76 10604dce 2021-09-24 thomas return 1
77 10604dce 2021-09-24 thomas fi
78 10604dce 2021-09-24 thomas
79 10604dce 2021-09-24 thomas # create the required dirvergant commit
80 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
81 10604dce 2021-09-24 thomas echo "modified zeta on master" > $testroot/repo/epsilon/zeta
82 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to zeta on master"
83 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
84 10604dce 2021-09-24 thomas
85 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
86 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
87 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
88 fc414659 2022-04-16 thomas ret=$?
89 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
90 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
91 0b477035 2023-06-22 thomas test_done "$testroot" "1"
92 10604dce 2021-09-24 thomas return 1
93 10604dce 2021-09-24 thomas fi
94 10604dce 2021-09-24 thomas echo -n "got: work tree must be updated before it can be used " \
95 10604dce 2021-09-24 thomas > $testroot/stderr.expected
96 10604dce 2021-09-24 thomas echo "to merge a branch" >> $testroot/stderr.expected
97 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
98 fc414659 2022-04-16 thomas ret=$?
99 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
100 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
101 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
102 10604dce 2021-09-24 thomas return 1
103 10604dce 2021-09-24 thomas fi
104 10604dce 2021-09-24 thomas
105 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
106 fc414659 2022-04-16 thomas ret=$?
107 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
108 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
109 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
110 10604dce 2021-09-24 thomas return 1
111 10604dce 2021-09-24 thomas fi
112 10604dce 2021-09-24 thomas
113 b6b86fd1 2022-08-30 thomas # must not use a mixed-commit work tree with 'got merge'
114 10604dce 2021-09-24 thomas (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
115 fc414659 2022-04-16 thomas ret=$?
116 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
117 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
118 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
119 10604dce 2021-09-24 thomas return 1
120 10604dce 2021-09-24 thomas fi
121 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
122 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
123 fc414659 2022-04-16 thomas ret=$?
124 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
125 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
126 0b477035 2023-06-22 thomas test_done "$testroot" "1"
127 10604dce 2021-09-24 thomas return 1
128 10604dce 2021-09-24 thomas fi
129 10604dce 2021-09-24 thomas echo -n "got: work tree contains files from multiple base commits; " \
130 10604dce 2021-09-24 thomas > $testroot/stderr.expected
131 10604dce 2021-09-24 thomas echo "the entire work tree must be updated first" \
132 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
133 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
134 fc414659 2022-04-16 thomas ret=$?
135 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
136 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
137 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
138 10604dce 2021-09-24 thomas return 1
139 10604dce 2021-09-24 thomas fi
140 10604dce 2021-09-24 thomas
141 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
142 fc414659 2022-04-16 thomas ret=$?
143 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
144 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
145 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
146 10604dce 2021-09-24 thomas return 1
147 10604dce 2021-09-24 thomas fi
148 10604dce 2021-09-24 thomas
149 b6b86fd1 2022-08-30 thomas # must not have staged files with 'got merge'
150 10604dce 2021-09-24 thomas echo "modified file alpha" > $testroot/wt/alpha
151 10604dce 2021-09-24 thomas (cd $testroot/wt && got stage alpha > /dev/null)
152 fc414659 2022-04-16 thomas ret=$?
153 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
154 10604dce 2021-09-24 thomas echo "got stage failed unexpectedly" >&2
155 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
156 10604dce 2021-09-24 thomas return 1
157 10604dce 2021-09-24 thomas fi
158 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
159 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
160 fc414659 2022-04-16 thomas ret=$?
161 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
162 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
163 0b477035 2023-06-22 thomas test_done "$testroot" "1"
164 10604dce 2021-09-24 thomas return 1
165 10604dce 2021-09-24 thomas fi
166 10604dce 2021-09-24 thomas echo "got: alpha: file is staged" > $testroot/stderr.expected
167 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
168 fc414659 2022-04-16 thomas ret=$?
169 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
170 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
171 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
172 10604dce 2021-09-24 thomas return 1
173 10604dce 2021-09-24 thomas fi
174 10604dce 2021-09-24 thomas (cd $testroot/wt && got unstage alpha > /dev/null)
175 fc414659 2022-04-16 thomas ret=$?
176 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
177 10604dce 2021-09-24 thomas echo "got unstage failed unexpectedly" >&2
178 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
179 10604dce 2021-09-24 thomas return 1
180 10604dce 2021-09-24 thomas fi
181 10604dce 2021-09-24 thomas
182 b6b86fd1 2022-08-30 thomas # must not have local changes with 'got merge'
183 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
184 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
185 fc414659 2022-04-16 thomas ret=$?
186 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
187 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
188 0b477035 2023-06-22 thomas test_done "$testroot" "1"
189 10604dce 2021-09-24 thomas return 1
190 10604dce 2021-09-24 thomas fi
191 10604dce 2021-09-24 thomas echo -n "got: work tree contains local changes; " \
192 10604dce 2021-09-24 thomas > $testroot/stderr.expected
193 10604dce 2021-09-24 thomas echo "these changes must be committed or reverted first" \
194 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
195 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
196 fc414659 2022-04-16 thomas ret=$?
197 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
198 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
199 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
200 10604dce 2021-09-24 thomas return 1
201 10604dce 2021-09-24 thomas fi
202 10604dce 2021-09-24 thomas
203 10604dce 2021-09-24 thomas (cd $testroot/wt && got revert alpha > /dev/null)
204 fc414659 2022-04-16 thomas ret=$?
205 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
206 10604dce 2021-09-24 thomas echo "got revert failed unexpectedly" >&2
207 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
208 10604dce 2021-09-24 thomas return 1
209 10604dce 2021-09-24 thomas fi
210 10604dce 2021-09-24 thomas
211 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch > $testroot/stdout)
212 fc414659 2022-04-16 thomas ret=$?
213 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
214 10604dce 2021-09-24 thomas echo "got merge failed unexpectedly" >&2
215 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
216 10604dce 2021-09-24 thomas return 1
217 10604dce 2021-09-24 thomas fi
218 10604dce 2021-09-24 thomas
219 10604dce 2021-09-24 thomas local merge_commit=`git_show_head $testroot/repo`
220 10604dce 2021-09-24 thomas
221 10604dce 2021-09-24 thomas echo "G alpha" >> $testroot/stdout.expected
222 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
223 ace90326 2021-09-27 thomas echo "A dotgotbar.link" >> $testroot/stdout.expected
224 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
225 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
226 10604dce 2021-09-24 thomas echo "A symlink" >> $testroot/stdout.expected
227 10604dce 2021-09-24 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
228 10604dce 2021-09-24 thomas >> $testroot/stdout.expected
229 10604dce 2021-09-24 thomas echo $merge_commit >> $testroot/stdout.expected
230 10604dce 2021-09-24 thomas
231 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
232 fc414659 2022-04-16 thomas ret=$?
233 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
234 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
235 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
236 10604dce 2021-09-24 thomas return 1
237 10604dce 2021-09-24 thomas fi
238 10604dce 2021-09-24 thomas
239 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/content.expected
240 10604dce 2021-09-24 thomas cat $testroot/wt/gamma/delta > $testroot/content
241 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
242 fc414659 2022-04-16 thomas ret=$?
243 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
244 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
245 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
246 10604dce 2021-09-24 thomas return 1
247 10604dce 2021-09-24 thomas fi
248 10604dce 2021-09-24 thomas
249 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/content.expected
250 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
251 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
252 fc414659 2022-04-16 thomas ret=$?
253 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
254 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
255 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
256 10604dce 2021-09-24 thomas return 1
257 10604dce 2021-09-24 thomas fi
258 10604dce 2021-09-24 thomas
259 10604dce 2021-09-24 thomas if [ -e $testroot/wt/beta ]; then
260 10604dce 2021-09-24 thomas echo "removed file beta still exists on disk" >&2
261 10604dce 2021-09-24 thomas test_done "$testroot" "1"
262 10604dce 2021-09-24 thomas return 1
263 10604dce 2021-09-24 thomas fi
264 10604dce 2021-09-24 thomas
265 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/content.expected
266 10604dce 2021-09-24 thomas cat $testroot/wt/epsilon/new > $testroot/content
267 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
268 fc414659 2022-04-16 thomas ret=$?
269 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
270 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
271 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
272 10604dce 2021-09-24 thomas return 1
273 10604dce 2021-09-24 thomas fi
274 10604dce 2021-09-24 thomas
275 ace90326 2021-09-27 thomas if [ ! -h $testroot/wt/dotgotbar.link ]; then
276 ace90326 2021-09-27 thomas echo "dotgotbar.link is not a symlink"
277 ace90326 2021-09-27 thomas test_done "$testroot" "1"
278 ace90326 2021-09-27 thomas return 1
279 ace90326 2021-09-27 thomas fi
280 ace90326 2021-09-27 thomas
281 10604dce 2021-09-24 thomas readlink $testroot/wt/symlink > $testroot/stdout
282 10604dce 2021-09-24 thomas echo "alpha" > $testroot/stdout.expected
283 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
284 fc414659 2022-04-16 thomas ret=$?
285 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
286 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
287 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
288 10604dce 2021-09-24 thomas return 1
289 10604dce 2021-09-24 thomas fi
290 10604dce 2021-09-24 thomas
291 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
292 10604dce 2021-09-24 thomas
293 10604dce 2021-09-24 thomas echo -n > $testroot/stdout.expected
294 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
295 fc414659 2022-04-16 thomas ret=$?
296 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
297 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
298 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
299 10604dce 2021-09-24 thomas return 1
300 10604dce 2021-09-24 thomas fi
301 10604dce 2021-09-24 thomas
302 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
303 10604dce 2021-09-24 thomas echo "commit $merge_commit (master)" > $testroot/stdout.expected
304 10604dce 2021-09-24 thomas echo "commit $master_commit" >> $testroot/stdout.expected
305 10604dce 2021-09-24 thomas echo "commit $commit0" >> $testroot/stdout.expected
306 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
307 fc414659 2022-04-16 thomas ret=$?
308 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
309 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
310 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
311 10604dce 2021-09-24 thomas return 1
312 10604dce 2021-09-24 thomas fi
313 10604dce 2021-09-24 thomas
314 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > $testroot/stdout)
315 10604dce 2021-09-24 thomas
316 ace90326 2021-09-27 thomas echo 'U dotgotbar.link' > $testroot/stdout.expected
317 ace90326 2021-09-27 thomas echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
318 ace90326 2021-09-27 thomas git_show_head $testroot/repo >> $testroot/stdout.expected
319 ace90326 2021-09-27 thomas echo >> $testroot/stdout.expected
320 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
321 fc414659 2022-04-16 thomas ret=$?
322 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
323 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
324 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
325 10604dce 2021-09-24 thomas return 1
326 10604dce 2021-09-24 thomas fi
327 10604dce 2021-09-24 thomas
328 ace90326 2021-09-27 thomas # update has changed the bad symlink into a regular file
329 ace90326 2021-09-27 thomas if [ -h $testroot/wt/dotgotbar.link ]; then
330 ace90326 2021-09-27 thomas echo "dotgotbar.link is a symlink"
331 ace90326 2021-09-27 thomas test_done "$testroot" "1"
332 ace90326 2021-09-27 thomas return 1
333 ace90326 2021-09-27 thomas fi
334 ace90326 2021-09-27 thomas
335 10604dce 2021-09-24 thomas # We should have created a merge commit with two parents.
336 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
337 10604dce 2021-09-24 thomas echo "parent 1: $master_commit" > $testroot/stdout.expected
338 ace90326 2021-09-27 thomas echo "parent 2: $branch_commit5" >> $testroot/stdout.expected
339 ace90326 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
340 fc414659 2022-04-16 thomas ret=$?
341 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
342 ace90326 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
343 ace90326 2021-09-27 thomas test_done "$testroot" "$ret"
344 ace90326 2021-09-27 thomas return 1
345 ace90326 2021-09-27 thomas fi
346 ace90326 2021-09-27 thomas
347 ace90326 2021-09-27 thomas got tree -r $testroot/repo -c $merge_commit -R > $testroot/stdout
348 fc414659 2022-04-16 thomas ret=$?
349 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
350 ace90326 2021-09-27 thomas echo "got tree failed unexpectedly" >&2
351 ace90326 2021-09-27 thomas test_done "$testroot" "$ret"
352 ace90326 2021-09-27 thomas return 1
353 ace90326 2021-09-27 thomas fi
354 ace90326 2021-09-27 thomas
355 ace90326 2021-09-27 thomas # bad symlink dotgotbar.link appears as a symlink in the merge commit:
356 ace90326 2021-09-27 thomas cat > $testroot/stdout.expected <<EOF
357 ace90326 2021-09-27 thomas alpha
358 ace90326 2021-09-27 thomas dotgotbar.link@ -> .got/bar
359 ace90326 2021-09-27 thomas epsilon/
360 ace90326 2021-09-27 thomas epsilon/new
361 ace90326 2021-09-27 thomas epsilon/zeta
362 ace90326 2021-09-27 thomas gamma/
363 ace90326 2021-09-27 thomas gamma/delta
364 ace90326 2021-09-27 thomas symlink@ -> alpha
365 ace90326 2021-09-27 thomas EOF
366 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
367 fc414659 2022-04-16 thomas ret=$?
368 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
369 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
370 10604dce 2021-09-24 thomas fi
371 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
372 10604dce 2021-09-24 thomas }
373 10604dce 2021-09-24 thomas
374 10604dce 2021-09-24 thomas test_merge_continue() {
375 10604dce 2021-09-24 thomas local testroot=`test_init merge_continue`
376 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
377 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
378 10604dce 2021-09-24 thomas
379 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
380 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
381 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to delta on newbranch"
382 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
383 10604dce 2021-09-24 thomas
384 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
385 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
386 10604dce 2021-09-24 thomas local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
387 10604dce 2021-09-24 thomas (cd $testroot/repo && git rm -q beta)
388 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "removing beta on newbranch"
389 10604dce 2021-09-24 thomas local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
390 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/repo/epsilon/new
391 10604dce 2021-09-24 thomas (cd $testroot/repo && git add epsilon/new)
392 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding new file on newbranch"
393 10604dce 2021-09-24 thomas local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
394 10604dce 2021-09-24 thomas
395 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
396 fc414659 2022-04-16 thomas ret=$?
397 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
398 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
399 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
400 10604dce 2021-09-24 thomas return 1
401 10604dce 2021-09-24 thomas fi
402 10604dce 2021-09-24 thomas
403 10604dce 2021-09-24 thomas # create a conflicting commit
404 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
405 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
406 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
407 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
408 10604dce 2021-09-24 thomas
409 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
410 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
411 fc414659 2022-04-16 thomas ret=$?
412 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
413 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
414 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
415 10604dce 2021-09-24 thomas return 1
416 10604dce 2021-09-24 thomas fi
417 10604dce 2021-09-24 thomas
418 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
419 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
420 fc414659 2022-04-16 thomas ret=$?
421 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
422 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
423 10604dce 2021-09-24 thomas test_done "$testroot" "1"
424 10604dce 2021-09-24 thomas return 1
425 10604dce 2021-09-24 thomas fi
426 10604dce 2021-09-24 thomas
427 10604dce 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
428 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
429 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
430 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
431 10604dce 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
432 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
433 fc414659 2022-04-16 thomas ret=$?
434 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
435 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
436 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
437 10604dce 2021-09-24 thomas return 1
438 10604dce 2021-09-24 thomas fi
439 10604dce 2021-09-24 thomas
440 10604dce 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
441 10604dce 2021-09-24 thomas > $testroot/stderr.expected
442 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
443 fc414659 2022-04-16 thomas ret=$?
444 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
445 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
446 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
447 10604dce 2021-09-24 thomas return 1
448 10604dce 2021-09-24 thomas fi
449 10604dce 2021-09-24 thomas
450 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
451 10604dce 2021-09-24 thomas
452 10604dce 2021-09-24 thomas echo "C alpha" > $testroot/stdout.expected
453 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
454 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
455 10604dce 2021-09-24 thomas echo "M gamma/delta" >> $testroot/stdout.expected
456 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
457 fc414659 2022-04-16 thomas ret=$?
458 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
459 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
460 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
461 10604dce 2021-09-24 thomas return 1
462 10604dce 2021-09-24 thomas fi
463 10604dce 2021-09-24 thomas
464 10604dce 2021-09-24 thomas echo '<<<<<<<' > $testroot/content.expected
465 10604dce 2021-09-24 thomas echo "modified alpha on master" >> $testroot/content.expected
466 10604dce 2021-09-24 thomas echo "||||||| 3-way merge base: commit $commit0" \
467 10604dce 2021-09-24 thomas >> $testroot/content.expected
468 10604dce 2021-09-24 thomas echo "alpha" >> $testroot/content.expected
469 10604dce 2021-09-24 thomas echo "=======" >> $testroot/content.expected
470 10604dce 2021-09-24 thomas echo "modified alpha on branch" >> $testroot/content.expected
471 10604dce 2021-09-24 thomas echo ">>>>>>> merged change: commit $branch_commit3" \
472 10604dce 2021-09-24 thomas >> $testroot/content.expected
473 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
474 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
475 fc414659 2022-04-16 thomas ret=$?
476 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
477 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
478 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
479 10604dce 2021-09-24 thomas return 1
480 10604dce 2021-09-24 thomas fi
481 10604dce 2021-09-24 thomas
482 10604dce 2021-09-24 thomas # resolve the conflict
483 10604dce 2021-09-24 thomas echo "modified alpha by both branches" > $testroot/wt/alpha
484 10604dce 2021-09-24 thomas
485 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge -c > $testroot/stdout)
486 fc414659 2022-04-16 thomas ret=$?
487 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
488 10604dce 2021-09-24 thomas echo "got merge failed unexpectedly" >&2
489 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
490 10604dce 2021-09-24 thomas return 1
491 10604dce 2021-09-24 thomas fi
492 10604dce 2021-09-24 thomas
493 10604dce 2021-09-24 thomas local merge_commit=`git_show_head $testroot/repo`
494 10604dce 2021-09-24 thomas
495 ae1e948a 2021-09-28 thomas echo "M alpha" > $testroot/stdout.expected
496 ae1e948a 2021-09-28 thomas echo "D beta" >> $testroot/stdout.expected
497 ae1e948a 2021-09-28 thomas echo "A epsilon/new" >> $testroot/stdout.expected
498 ae1e948a 2021-09-28 thomas echo "M gamma/delta" >> $testroot/stdout.expected
499 10604dce 2021-09-24 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
500 ae1e948a 2021-09-28 thomas >> $testroot/stdout.expected
501 10604dce 2021-09-24 thomas echo $merge_commit >> $testroot/stdout.expected
502 10604dce 2021-09-24 thomas
503 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
504 fc414659 2022-04-16 thomas ret=$?
505 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
506 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
507 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
508 10604dce 2021-09-24 thomas return 1
509 10604dce 2021-09-24 thomas fi
510 10604dce 2021-09-24 thomas
511 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/content.expected
512 10604dce 2021-09-24 thomas cat $testroot/wt/gamma/delta > $testroot/content
513 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
514 fc414659 2022-04-16 thomas ret=$?
515 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
516 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
517 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
518 10604dce 2021-09-24 thomas return 1
519 10604dce 2021-09-24 thomas fi
520 10604dce 2021-09-24 thomas
521 10604dce 2021-09-24 thomas echo "modified alpha by both branches" > $testroot/content.expected
522 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
523 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
524 fc414659 2022-04-16 thomas ret=$?
525 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
526 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
527 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
528 10604dce 2021-09-24 thomas return 1
529 10604dce 2021-09-24 thomas fi
530 10604dce 2021-09-24 thomas
531 10604dce 2021-09-24 thomas if [ -e $testroot/wt/beta ]; then
532 10604dce 2021-09-24 thomas echo "removed file beta still exists on disk" >&2
533 10604dce 2021-09-24 thomas test_done "$testroot" "1"
534 10604dce 2021-09-24 thomas return 1
535 10604dce 2021-09-24 thomas fi
536 10604dce 2021-09-24 thomas
537 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/content.expected
538 10604dce 2021-09-24 thomas cat $testroot/wt/epsilon/new > $testroot/content
539 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
540 fc414659 2022-04-16 thomas ret=$?
541 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
542 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
543 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
544 10604dce 2021-09-24 thomas return 1
545 10604dce 2021-09-24 thomas fi
546 10604dce 2021-09-24 thomas
547 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
548 10604dce 2021-09-24 thomas
549 10604dce 2021-09-24 thomas echo -n > $testroot/stdout.expected
550 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
551 fc414659 2022-04-16 thomas ret=$?
552 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
553 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
554 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
555 10604dce 2021-09-24 thomas return 1
556 10604dce 2021-09-24 thomas fi
557 10604dce 2021-09-24 thomas
558 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
559 10604dce 2021-09-24 thomas echo "commit $merge_commit (master)" > $testroot/stdout.expected
560 10604dce 2021-09-24 thomas echo "commit $master_commit" >> $testroot/stdout.expected
561 10604dce 2021-09-24 thomas echo "commit $commit0" >> $testroot/stdout.expected
562 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
563 fc414659 2022-04-16 thomas ret=$?
564 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
565 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
566 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
567 10604dce 2021-09-24 thomas return 1
568 10604dce 2021-09-24 thomas fi
569 10604dce 2021-09-24 thomas
570 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > $testroot/stdout)
571 10604dce 2021-09-24 thomas
572 10604dce 2021-09-24 thomas echo 'Already up-to-date' > $testroot/stdout.expected
573 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
574 fc414659 2022-04-16 thomas ret=$?
575 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
576 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
577 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
578 10604dce 2021-09-24 thomas return 1
579 10604dce 2021-09-24 thomas fi
580 10604dce 2021-09-24 thomas
581 10604dce 2021-09-24 thomas # We should have created a merge commit with two parents.
582 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
583 10604dce 2021-09-24 thomas echo "parent 1: $master_commit" > $testroot/stdout.expected
584 10604dce 2021-09-24 thomas echo "parent 2: $branch_commit3" >> $testroot/stdout.expected
585 fe3f264b 2023-06-08 thomas cmp -s $testroot/stdout.expected $testroot/stdout
586 fe3f264b 2023-06-08 thomas ret=$?
587 fe3f264b 2023-06-08 thomas if [ $ret -ne 0 ]; then
588 fe3f264b 2023-06-08 thomas diff -u $testroot/stdout.expected $testroot/stdout
589 fe3f264b 2023-06-08 thomas fi
590 fe3f264b 2023-06-08 thomas test_done "$testroot" "$ret"
591 fe3f264b 2023-06-08 thomas }
592 fe3f264b 2023-06-08 thomas
593 fe3f264b 2023-06-08 thomas test_merge_continue_new_commit() {
594 fe3f264b 2023-06-08 thomas # "got merge -c" should refuse to run if the current branch tip has
595 fe3f264b 2023-06-08 thomas # changed since the merge was started, to avoid clobbering the changes.
596 fe3f264b 2023-06-08 thomas local testroot=`test_init merge_continue_new_commit`
597 fe3f264b 2023-06-08 thomas
598 fe3f264b 2023-06-08 thomas (cd $testroot/repo && git checkout -q -b newbranch)
599 fe3f264b 2023-06-08 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
600 fe3f264b 2023-06-08 thomas git_commit $testroot/repo -m "committing to delta on newbranch"
601 fe3f264b 2023-06-08 thomas
602 fe3f264b 2023-06-08 thomas (cd $testroot/repo && git checkout -q master)
603 fe3f264b 2023-06-08 thomas echo "modified alpha on master" > $testroot/repo/alpha
604 fe3f264b 2023-06-08 thomas git_commit $testroot/repo -m "committing to alpha on master"
605 fe3f264b 2023-06-08 thomas
606 fe3f264b 2023-06-08 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
607 fe3f264b 2023-06-08 thomas ret=$?
608 fe3f264b 2023-06-08 thomas if [ $ret -ne 0 ]; then
609 fe3f264b 2023-06-08 thomas echo "got checkout failed unexpectedly" >&2
610 fe3f264b 2023-06-08 thomas test_done "$testroot" "$ret"
611 fe3f264b 2023-06-08 thomas return 1
612 fe3f264b 2023-06-08 thomas fi
613 fe3f264b 2023-06-08 thomas
614 fe3f264b 2023-06-08 thomas (cd $testroot/wt && got merge -n newbranch >/dev/null)
615 fe3f264b 2023-06-08 thomas ret=$?
616 fe3f264b 2023-06-08 thomas if [ $ret -ne 0 ]; then
617 fe3f264b 2023-06-08 thomas echo "got merge failed unexpectedly" >&2
618 fe3f264b 2023-06-08 thomas test_done "$testroot" "$ret"
619 fe3f264b 2023-06-08 thomas return 1
620 fe3f264b 2023-06-08 thomas fi
621 fe3f264b 2023-06-08 thomas
622 fe3f264b 2023-06-08 thomas echo "modified alpha again on master" > $testroot/repo/alpha
623 fe3f264b 2023-06-08 thomas git_commit $testroot/repo -m "committing to alpha on master again"
624 fe3f264b 2023-06-08 thomas
625 fe3f264b 2023-06-08 thomas (cd $testroot/wt && got merge -c > $testroot/stdout 2> $testroot/stderr)
626 fe3f264b 2023-06-08 thomas ret=$?
627 fe3f264b 2023-06-08 thomas if [ $ret -eq 0 ]; then
628 fe3f264b 2023-06-08 thomas echo "got merge succeeded unexpectedly" >&2
629 fe3f264b 2023-06-08 thomas test_done "$testroot" "1"
630 fe3f264b 2023-06-08 thomas return 1
631 fe3f264b 2023-06-08 thomas fi
632 fe3f264b 2023-06-08 thomas
633 fe3f264b 2023-06-08 thomas echo -n > $testroot/stdout.expected
634 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
635 fc414659 2022-04-16 thomas ret=$?
636 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
637 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
638 fe3f264b 2023-06-08 thomas test_done "$testroot" "$ret"
639 fe3f264b 2023-06-08 thomas return 1
640 fe3f264b 2023-06-08 thomas fi
641 fe3f264b 2023-06-08 thomas
642 fe3f264b 2023-06-08 thomas echo -n "got: merging cannot proceed because the work tree is no " \
643 fe3f264b 2023-06-08 thomas > $testroot/stderr.expected
644 fe3f264b 2023-06-08 thomas echo "longer up-to-date; merge must be aborted and retried" \
645 fe3f264b 2023-06-08 thomas >> $testroot/stderr.expected
646 fe3f264b 2023-06-08 thomas cmp -s $testroot/stderr.expected $testroot/stderr
647 fe3f264b 2023-06-08 thomas ret=$?
648 fe3f264b 2023-06-08 thomas if [ $ret -ne 0 ]; then
649 fe3f264b 2023-06-08 thomas diff -u $testroot/stderr.expected $testroot/stderr
650 10604dce 2021-09-24 thomas fi
651 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
652 10604dce 2021-09-24 thomas }
653 10604dce 2021-09-24 thomas
654 10604dce 2021-09-24 thomas test_merge_abort() {
655 10604dce 2021-09-24 thomas local testroot=`test_init merge_abort`
656 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
657 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
658 10604dce 2021-09-24 thomas
659 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
660 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
661 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to delta on newbranch"
662 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
663 10604dce 2021-09-24 thomas
664 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
665 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
666 10604dce 2021-09-24 thomas local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
667 10604dce 2021-09-24 thomas (cd $testroot/repo && git rm -q beta)
668 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "removing beta on newbranch"
669 10604dce 2021-09-24 thomas local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
670 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/repo/epsilon/new
671 10604dce 2021-09-24 thomas (cd $testroot/repo && git add epsilon/new)
672 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding new file on newbranch"
673 10604dce 2021-09-24 thomas local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
674 10604dce 2021-09-24 thomas (cd $testroot/repo && ln -s alpha symlink && git add symlink)
675 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding symlink on newbranch"
676 10604dce 2021-09-24 thomas local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
677 10604dce 2021-09-24 thomas
678 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
679 fc414659 2022-04-16 thomas ret=$?
680 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
681 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
682 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
683 10604dce 2021-09-24 thomas return 1
684 10604dce 2021-09-24 thomas fi
685 d52bac28 2021-10-08 thomas
686 d52bac28 2021-10-08 thomas # unrelated unversioned file in work tree
687 d52bac28 2021-10-08 thomas touch $testroot/wt/unversioned-file
688 10604dce 2021-09-24 thomas
689 10604dce 2021-09-24 thomas # create a conflicting commit
690 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
691 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
692 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
693 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
694 10604dce 2021-09-24 thomas
695 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
696 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
697 fc414659 2022-04-16 thomas ret=$?
698 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
699 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
700 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
701 10604dce 2021-09-24 thomas return 1
702 10604dce 2021-09-24 thomas fi
703 10604dce 2021-09-24 thomas
704 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
705 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
706 fc414659 2022-04-16 thomas ret=$?
707 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
708 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
709 10604dce 2021-09-24 thomas test_done "$testroot" "1"
710 10604dce 2021-09-24 thomas return 1
711 10604dce 2021-09-24 thomas fi
712 10604dce 2021-09-24 thomas
713 10604dce 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
714 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
715 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
716 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
717 10604dce 2021-09-24 thomas echo "A symlink" >> $testroot/stdout.expected
718 10604dce 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
719 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
720 fc414659 2022-04-16 thomas ret=$?
721 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
722 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
723 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
724 10604dce 2021-09-24 thomas return 1
725 10604dce 2021-09-24 thomas fi
726 10604dce 2021-09-24 thomas
727 10604dce 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
728 10604dce 2021-09-24 thomas > $testroot/stderr.expected
729 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
730 fc414659 2022-04-16 thomas ret=$?
731 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
732 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
733 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
734 10604dce 2021-09-24 thomas return 1
735 10604dce 2021-09-24 thomas fi
736 8641a332 2023-04-14 thomas
737 8641a332 2023-04-14 thomas # unrelated added file added during conflict resolution
738 8641a332 2023-04-14 thomas touch $testroot/wt/added-file
739 8641a332 2023-04-14 thomas (cd $testroot/wt && got add added-file > /dev/null)
740 10604dce 2021-09-24 thomas
741 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
742 10604dce 2021-09-24 thomas
743 8641a332 2023-04-14 thomas echo "A added-file" > $testroot/stdout.expected
744 8641a332 2023-04-14 thomas echo "C alpha" >> $testroot/stdout.expected
745 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
746 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
747 10604dce 2021-09-24 thomas echo "M gamma/delta" >> $testroot/stdout.expected
748 10604dce 2021-09-24 thomas echo "A symlink" >> $testroot/stdout.expected
749 d52bac28 2021-10-08 thomas echo "? unversioned-file" >> $testroot/stdout.expected
750 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
751 fc414659 2022-04-16 thomas ret=$?
752 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
753 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
754 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
755 10604dce 2021-09-24 thomas return 1
756 10604dce 2021-09-24 thomas fi
757 10604dce 2021-09-24 thomas
758 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge -a > $testroot/stdout)
759 fc414659 2022-04-16 thomas ret=$?
760 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
761 10604dce 2021-09-24 thomas echo "got merge failed unexpectedly" >&2
762 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
763 10604dce 2021-09-24 thomas return 1
764 10604dce 2021-09-24 thomas fi
765 10604dce 2021-09-24 thomas
766 8641a332 2023-04-14 thomas echo "R added-file" > $testroot/stdout.expected
767 8641a332 2023-04-14 thomas echo "R alpha" >> $testroot/stdout.expected
768 10604dce 2021-09-24 thomas echo "R beta" >> $testroot/stdout.expected
769 10604dce 2021-09-24 thomas echo "R epsilon/new" >> $testroot/stdout.expected
770 10604dce 2021-09-24 thomas echo "R gamma/delta" >> $testroot/stdout.expected
771 10604dce 2021-09-24 thomas echo "R symlink" >> $testroot/stdout.expected
772 8641a332 2023-04-14 thomas echo "G added-file" >> $testroot/stdout.expected
773 10604dce 2021-09-24 thomas echo "Merge of refs/heads/newbranch aborted" \
774 10604dce 2021-09-24 thomas >> $testroot/stdout.expected
775 10604dce 2021-09-24 thomas
776 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
777 fc414659 2022-04-16 thomas ret=$?
778 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
779 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
780 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
781 10604dce 2021-09-24 thomas return 1
782 10604dce 2021-09-24 thomas fi
783 10604dce 2021-09-24 thomas
784 10604dce 2021-09-24 thomas echo "delta" > $testroot/content.expected
785 10604dce 2021-09-24 thomas cat $testroot/wt/gamma/delta > $testroot/content
786 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
787 fc414659 2022-04-16 thomas ret=$?
788 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
789 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
790 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
791 10604dce 2021-09-24 thomas return 1
792 10604dce 2021-09-24 thomas fi
793 10604dce 2021-09-24 thomas
794 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/content.expected
795 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
796 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
797 fc414659 2022-04-16 thomas ret=$?
798 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
799 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
800 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
801 10604dce 2021-09-24 thomas return 1
802 10604dce 2021-09-24 thomas fi
803 10604dce 2021-09-24 thomas
804 10604dce 2021-09-24 thomas echo "beta" > $testroot/content.expected
805 10604dce 2021-09-24 thomas cat $testroot/wt/beta > $testroot/content
806 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
807 fc414659 2022-04-16 thomas ret=$?
808 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
809 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
810 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
811 10604dce 2021-09-24 thomas return 1
812 10604dce 2021-09-24 thomas fi
813 10604dce 2021-09-24 thomas
814 10604dce 2021-09-24 thomas if [ -e $testroot/wt/epsilon/new ]; then
815 10604dce 2021-09-24 thomas echo "reverted file epsilon/new still exists on disk" >&2
816 10604dce 2021-09-24 thomas test_done "$testroot" "1"
817 10604dce 2021-09-24 thomas return 1
818 10604dce 2021-09-24 thomas fi
819 10604dce 2021-09-24 thomas
820 10604dce 2021-09-24 thomas if [ -e $testroot/wt/symlink ]; then
821 10604dce 2021-09-24 thomas echo "reverted symlink still exists on disk" >&2
822 10604dce 2021-09-24 thomas test_done "$testroot" "1"
823 10604dce 2021-09-24 thomas return 1
824 10604dce 2021-09-24 thomas fi
825 10604dce 2021-09-24 thomas
826 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
827 10604dce 2021-09-24 thomas
828 8641a332 2023-04-14 thomas echo "? added-file" > $testroot/stdout.expected
829 8641a332 2023-04-14 thomas echo "? unversioned-file" >> $testroot/stdout.expected
830 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
831 fc414659 2022-04-16 thomas ret=$?
832 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
833 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
834 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
835 10604dce 2021-09-24 thomas return 1
836 10604dce 2021-09-24 thomas fi
837 10604dce 2021-09-24 thomas
838 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
839 10604dce 2021-09-24 thomas echo "commit $master_commit (master)" > $testroot/stdout.expected
840 10604dce 2021-09-24 thomas echo "commit $commit0" >> $testroot/stdout.expected
841 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
842 fc414659 2022-04-16 thomas ret=$?
843 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
844 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
845 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
846 10604dce 2021-09-24 thomas return 1
847 10604dce 2021-09-24 thomas fi
848 10604dce 2021-09-24 thomas
849 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > $testroot/stdout)
850 10604dce 2021-09-24 thomas
851 10604dce 2021-09-24 thomas echo 'Already up-to-date' > $testroot/stdout.expected
852 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
853 fc414659 2022-04-16 thomas ret=$?
854 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
855 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
856 10604dce 2021-09-24 thomas fi
857 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
858 10604dce 2021-09-24 thomas }
859 10604dce 2021-09-24 thomas
860 10604dce 2021-09-24 thomas test_merge_in_progress() {
861 10604dce 2021-09-24 thomas local testroot=`test_init merge_in_progress`
862 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
863 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
864 10604dce 2021-09-24 thomas
865 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
866 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
867 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
868 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
869 10604dce 2021-09-24 thomas
870 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
871 fc414659 2022-04-16 thomas ret=$?
872 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
873 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
874 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
875 10604dce 2021-09-24 thomas return 1
876 10604dce 2021-09-24 thomas fi
877 10604dce 2021-09-24 thomas
878 10604dce 2021-09-24 thomas # create a conflicting commit
879 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
880 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
881 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
882 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
883 10604dce 2021-09-24 thomas
884 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
885 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
886 fc414659 2022-04-16 thomas ret=$?
887 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
888 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
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 newbranch \
894 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
895 fc414659 2022-04-16 thomas ret=$?
896 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
897 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
898 10604dce 2021-09-24 thomas test_done "$testroot" "1"
899 10604dce 2021-09-24 thomas return 1
900 10604dce 2021-09-24 thomas fi
901 10604dce 2021-09-24 thomas
902 10604dce 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
903 10604dce 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
904 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
905 fc414659 2022-04-16 thomas ret=$?
906 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
907 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
908 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
909 10604dce 2021-09-24 thomas return 1
910 10604dce 2021-09-24 thomas fi
911 10604dce 2021-09-24 thomas
912 10604dce 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
913 10604dce 2021-09-24 thomas > $testroot/stderr.expected
914 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
915 fc414659 2022-04-16 thomas ret=$?
916 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
917 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
918 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
919 10604dce 2021-09-24 thomas return 1
920 10604dce 2021-09-24 thomas fi
921 10604dce 2021-09-24 thomas
922 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
923 10604dce 2021-09-24 thomas
924 10604dce 2021-09-24 thomas echo "C alpha" > $testroot/stdout.expected
925 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
926 fc414659 2022-04-16 thomas ret=$?
927 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
928 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
929 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
930 10604dce 2021-09-24 thomas return 1
931 10604dce 2021-09-24 thomas fi
932 10604dce 2021-09-24 thomas
933 10604dce 2021-09-24 thomas for cmd in update commit histedit "rebase newbranch" \
934 d8a7bd7d 2023-06-01 thomas "integrate newbranch" "merge newbranch" "stage alpha"; do
935 10604dce 2021-09-24 thomas (cd $testroot/wt && got $cmd > $testroot/stdout \
936 10604dce 2021-09-24 thomas 2> $testroot/stderr)
937 d8a7bd7d 2023-06-01 thomas ret=$?
938 d8a7bd7d 2023-06-01 thomas if [ $ret -eq 0 ]; then
939 d8a7bd7d 2023-06-01 thomas echo "got $cmd succeeded unexpectedly" >&2
940 d8a7bd7d 2023-06-01 thomas test_done "$testroot" "1"
941 d8a7bd7d 2023-06-01 thomas return 1
942 d8a7bd7d 2023-06-01 thomas fi
943 10604dce 2021-09-24 thomas
944 10604dce 2021-09-24 thomas echo -n > $testroot/stdout.expected
945 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
946 fc414659 2022-04-16 thomas ret=$?
947 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
948 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
949 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
950 10604dce 2021-09-24 thomas return 1
951 10604dce 2021-09-24 thomas fi
952 10604dce 2021-09-24 thomas
953 10604dce 2021-09-24 thomas echo -n "got: a merge operation is in progress in this " \
954 10604dce 2021-09-24 thomas > $testroot/stderr.expected
955 10604dce 2021-09-24 thomas echo "work tree and must be continued or aborted first" \
956 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
957 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
958 fc414659 2022-04-16 thomas ret=$?
959 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
960 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
961 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
962 10604dce 2021-09-24 thomas return 1
963 10604dce 2021-09-24 thomas fi
964 10604dce 2021-09-24 thomas done
965 10604dce 2021-09-24 thomas
966 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
967 10604dce 2021-09-24 thomas }
968 10604dce 2021-09-24 thomas
969 10604dce 2021-09-24 thomas test_merge_path_prefix() {
970 10604dce 2021-09-24 thomas local testroot=`test_init merge_path_prefix`
971 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
972 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
973 10604dce 2021-09-24 thomas
974 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
975 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
976 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
977 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
978 10604dce 2021-09-24 thomas
979 10604dce 2021-09-24 thomas got checkout -p epsilon -b master $testroot/repo $testroot/wt \
980 10604dce 2021-09-24 thomas > /dev/null
981 fc414659 2022-04-16 thomas ret=$?
982 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
983 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
984 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
985 10604dce 2021-09-24 thomas return 1
986 10604dce 2021-09-24 thomas fi
987 10604dce 2021-09-24 thomas
988 10604dce 2021-09-24 thomas # create a conflicting commit
989 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
990 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
991 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
992 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
993 10604dce 2021-09-24 thomas
994 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
995 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
996 fc414659 2022-04-16 thomas ret=$?
997 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
998 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
999 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1000 10604dce 2021-09-24 thomas return 1
1001 10604dce 2021-09-24 thomas fi
1002 10604dce 2021-09-24 thomas
1003 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
1004 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
1005 fc414659 2022-04-16 thomas ret=$?
1006 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
1007 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
1008 10604dce 2021-09-24 thomas test_done "$testroot" "1"
1009 10604dce 2021-09-24 thomas return 1
1010 10604dce 2021-09-24 thomas fi
1011 10604dce 2021-09-24 thomas
1012 10604dce 2021-09-24 thomas echo -n "got: cannot merge branch which contains changes outside " \
1013 10604dce 2021-09-24 thomas > $testroot/stderr.expected
1014 10604dce 2021-09-24 thomas echo "of this work tree's path prefix" >> $testroot/stderr.expected
1015 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1016 fc414659 2022-04-16 thomas ret=$?
1017 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1018 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1019 10604dce 2021-09-24 thomas fi
1020 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1021 10604dce 2021-09-24 thomas }
1022 10604dce 2021-09-24 thomas
1023 10604dce 2021-09-24 thomas test_merge_missing_file() {
1024 10604dce 2021-09-24 thomas local testroot=`test_init merge_missing_file`
1025 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
1026 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1027 10604dce 2021-09-24 thomas
1028 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
1029 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
1030 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
1031 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha and delta"
1032 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1033 10604dce 2021-09-24 thomas
1034 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
1035 fc414659 2022-04-16 thomas ret=$?
1036 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1037 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
1038 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1039 10604dce 2021-09-24 thomas return 1
1040 10604dce 2021-09-24 thomas fi
1041 10604dce 2021-09-24 thomas
1042 10604dce 2021-09-24 thomas # create a conflicting commit which renames alpha
1043 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
1044 10604dce 2021-09-24 thomas (cd $testroot/repo && git mv alpha epsilon/alpha-moved)
1045 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "moving alpha on master"
1046 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
1047 10604dce 2021-09-24 thomas
1048 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
1049 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
1050 fc414659 2022-04-16 thomas ret=$?
1051 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1052 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
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 merge newbranch \
1058 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
1059 fc414659 2022-04-16 thomas ret=$?
1060 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
1061 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
1062 10604dce 2021-09-24 thomas test_done "$testroot" "1"
1063 10604dce 2021-09-24 thomas return 1
1064 10604dce 2021-09-24 thomas fi
1065 10604dce 2021-09-24 thomas
1066 10604dce 2021-09-24 thomas echo "! alpha" > $testroot/stdout.expected
1067 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
1068 0ef68859 2021-09-28 thomas echo -n "Files which had incoming changes but could not be found " \
1069 0ef68859 2021-09-28 thomas >> $testroot/stdout.expected
1070 0ef68859 2021-09-28 thomas echo "in the work tree: 1" >> $testroot/stdout.expected
1071 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1072 fc414659 2022-04-16 thomas ret=$?
1073 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1074 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1075 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1076 10604dce 2021-09-24 thomas return 1
1077 10604dce 2021-09-24 thomas fi
1078 10604dce 2021-09-24 thomas
1079 ba162991 2021-09-28 thomas echo -n "got: changes destined for some files " \
1080 10604dce 2021-09-24 thomas > $testroot/stderr.expected
1081 10604dce 2021-09-24 thomas echo -n "were not yet merged and should be merged manually if " \
1082 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
1083 10604dce 2021-09-24 thomas echo "required before the merge operation is continued" \
1084 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
1085 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1086 fc414659 2022-04-16 thomas ret=$?
1087 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1088 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1089 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1090 10604dce 2021-09-24 thomas return 1
1091 10604dce 2021-09-24 thomas fi
1092 10604dce 2021-09-24 thomas
1093 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1094 10604dce 2021-09-24 thomas
1095 10604dce 2021-09-24 thomas echo "M gamma/delta" > $testroot/stdout.expected
1096 2d7ce510 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1097 fc414659 2022-04-16 thomas ret=$?
1098 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1099 2d7ce510 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1100 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1101 2d7ce510 2021-09-24 thomas return 1
1102 2d7ce510 2021-09-24 thomas fi
1103 2d7ce510 2021-09-24 thomas
1104 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1105 2d7ce510 2021-09-24 thomas }
1106 2d7ce510 2021-09-24 thomas
1107 2d7ce510 2021-09-24 thomas test_merge_no_op() {
1108 2d7ce510 2021-09-24 thomas local testroot=`test_init merge_no_op`
1109 2d7ce510 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
1110 2d7ce510 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1111 2d7ce510 2021-09-24 thomas
1112 2d7ce510 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
1113 2d7ce510 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
1114 2d7ce510 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
1115 1678610c 2023-04-22 thomas local branch_commit=`git_show_branch_head $testroot/repo newbranch`
1116 2d7ce510 2021-09-24 thomas
1117 2d7ce510 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
1118 fc414659 2022-04-16 thomas ret=$?
1119 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1120 2d7ce510 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
1121 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1122 2d7ce510 2021-09-24 thomas return 1
1123 2d7ce510 2021-09-24 thomas fi
1124 2d7ce510 2021-09-24 thomas
1125 2d7ce510 2021-09-24 thomas # create a conflicting commit
1126 2d7ce510 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
1127 2d7ce510 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
1128 2d7ce510 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
1129 2d7ce510 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
1130 2d7ce510 2021-09-24 thomas
1131 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
1132 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
1133 fc414659 2022-04-16 thomas ret=$?
1134 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1135 2d7ce510 2021-09-24 thomas echo "got update failed unexpectedly" >&2
1136 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1137 2d7ce510 2021-09-24 thomas return 1
1138 2d7ce510 2021-09-24 thomas fi
1139 2d7ce510 2021-09-24 thomas
1140 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
1141 2d7ce510 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
1142 fc414659 2022-04-16 thomas ret=$?
1143 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
1144 2d7ce510 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
1145 2d7ce510 2021-09-24 thomas test_done "$testroot" "1"
1146 2d7ce510 2021-09-24 thomas return 1
1147 2d7ce510 2021-09-24 thomas fi
1148 2d7ce510 2021-09-24 thomas
1149 2d7ce510 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
1150 2d7ce510 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1151 2d7ce510 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1152 fc414659 2022-04-16 thomas ret=$?
1153 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1154 2d7ce510 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1155 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1156 2d7ce510 2021-09-24 thomas return 1
1157 2d7ce510 2021-09-24 thomas fi
1158 2d7ce510 2021-09-24 thomas
1159 2d7ce510 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
1160 2d7ce510 2021-09-24 thomas > $testroot/stderr.expected
1161 2d7ce510 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1162 fc414659 2022-04-16 thomas ret=$?
1163 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1164 2d7ce510 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1165 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1166 2d7ce510 2021-09-24 thomas return 1
1167 2d7ce510 2021-09-24 thomas fi
1168 2d7ce510 2021-09-24 thomas
1169 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1170 2d7ce510 2021-09-24 thomas
1171 2d7ce510 2021-09-24 thomas echo "C alpha" > $testroot/stdout.expected
1172 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1173 fc414659 2022-04-16 thomas ret=$?
1174 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1175 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1176 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1177 10604dce 2021-09-24 thomas return 1
1178 10604dce 2021-09-24 thomas fi
1179 10604dce 2021-09-24 thomas
1180 2d7ce510 2021-09-24 thomas # resolve the conflict by reverting all changes; now it is no-op merge
1181 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got revert alpha > /dev/null)
1182 fc414659 2022-04-16 thomas ret=$?
1183 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1184 2d7ce510 2021-09-24 thomas echo "got revert failed unexpectedly" >&2
1185 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1186 2d7ce510 2021-09-24 thomas return 1
1187 2d7ce510 2021-09-24 thomas fi
1188 2d7ce510 2021-09-24 thomas
1189 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got merge -c > $testroot/stdout \
1190 2d7ce510 2021-09-24 thomas 2> $testroot/stderr)
1191 fc414659 2022-04-16 thomas ret=$?
1192 1678610c 2023-04-22 thomas if [ $ret -ne 0 ]; then
1193 1678610c 2023-04-22 thomas echo "got merge failed unexpectedly" >&2
1194 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1195 2d7ce510 2021-09-24 thomas return 1
1196 2d7ce510 2021-09-24 thomas fi
1197 2d7ce510 2021-09-24 thomas
1198 1678610c 2023-04-22 thomas echo -n '' > $testroot/stderr.expected
1199 2d7ce510 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1200 fc414659 2022-04-16 thomas ret=$?
1201 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1202 2d7ce510 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1203 1678610c 2023-04-22 thomas test_done "$testroot" "$ret"
1204 1678610c 2023-04-22 thomas return 1
1205 1678610c 2023-04-22 thomas fi
1206 1678610c 2023-04-22 thomas
1207 1678610c 2023-04-22 thomas local merge_commit=`git_show_head $testroot/repo`
1208 1678610c 2023-04-22 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1209 1678610c 2023-04-22 thomas > $testroot/stdout.expected
1210 1678610c 2023-04-22 thomas echo $merge_commit >> $testroot/stdout.expected
1211 1678610c 2023-04-22 thomas
1212 1678610c 2023-04-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1213 1678610c 2023-04-22 thomas ret=$?
1214 1678610c 2023-04-22 thomas if [ $ret -ne 0 ]; then
1215 1678610c 2023-04-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1216 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1217 2d7ce510 2021-09-24 thomas return 1
1218 2d7ce510 2021-09-24 thomas fi
1219 2d7ce510 2021-09-24 thomas
1220 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1221 2d7ce510 2021-09-24 thomas
1222 2d7ce510 2021-09-24 thomas echo -n "" > $testroot/stdout.expected
1223 768705e3 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1224 fc414659 2022-04-16 thomas ret=$?
1225 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1226 768705e3 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1227 1678610c 2023-04-22 thomas test_done "$testroot" "$ret"
1228 1678610c 2023-04-22 thomas return 1
1229 768705e3 2021-09-27 thomas fi
1230 1678610c 2023-04-22 thomas
1231 1678610c 2023-04-22 thomas # We should have created a merge commit with two parents.
1232 1678610c 2023-04-22 thomas got log -r $testroot/repo -l1 -c $merge_commit | grep ^parent \
1233 1678610c 2023-04-22 thomas > $testroot/stdout
1234 1678610c 2023-04-22 thomas echo "parent 1: $master_commit" > $testroot/stdout.expected
1235 1678610c 2023-04-22 thomas echo "parent 2: $branch_commit" >> $testroot/stdout.expected
1236 1678610c 2023-04-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1237 1678610c 2023-04-22 thomas ret=$?
1238 1678610c 2023-04-22 thomas if [ $ret -ne 0 ]; then
1239 1678610c 2023-04-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1240 1678610c 2023-04-22 thomas fi
1241 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1242 768705e3 2021-09-27 thomas }
1243 768705e3 2021-09-27 thomas
1244 768705e3 2021-09-27 thomas test_merge_imported_branch() {
1245 768705e3 2021-09-27 thomas local testroot=`test_init merge_import`
1246 768705e3 2021-09-27 thomas local commit0=`git_show_head $testroot/repo`
1247 768705e3 2021-09-27 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1248 768705e3 2021-09-27 thomas
1249 768705e3 2021-09-27 thomas # import a new sub-tree to the 'files' branch such that
1250 768705e3 2021-09-27 thomas # none of the files added here collide with existing ones
1251 768705e3 2021-09-27 thomas mkdir -p $testroot/tree/there
1252 768705e3 2021-09-27 thomas mkdir -p $testroot/tree/be/lots
1253 768705e3 2021-09-27 thomas mkdir -p $testroot/tree/files
1254 768705e3 2021-09-27 thomas echo "there should" > $testroot/tree/there/should
1255 768705e3 2021-09-27 thomas echo "be lots of" > $testroot/tree/be/lots/of
1256 768705e3 2021-09-27 thomas echo "files here" > $testroot/tree/files/here
1257 768705e3 2021-09-27 thomas got import -r $testroot/repo -b files -m 'import files' \
1258 768705e3 2021-09-27 thomas $testroot/tree > /dev/null
1259 768705e3 2021-09-27 thomas
1260 768705e3 2021-09-27 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
1261 fc414659 2022-04-16 thomas ret=$?
1262 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1263 768705e3 2021-09-27 thomas echo "got checkout failed unexpectedly" >&2
1264 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1265 768705e3 2021-09-27 thomas return 1
1266 768705e3 2021-09-27 thomas fi
1267 768705e3 2021-09-27 thomas
1268 768705e3 2021-09-27 thomas (cd $testroot/wt && got merge files > $testroot/stdout)
1269 fc414659 2022-04-16 thomas ret=$?
1270 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1271 768705e3 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1272 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1273 768705e3 2021-09-27 thomas return 1
1274 768705e3 2021-09-27 thomas fi
1275 768705e3 2021-09-27 thomas
1276 768705e3 2021-09-27 thomas local merge_commit0=`git_show_head $testroot/repo`
1277 768705e3 2021-09-27 thomas cat > $testroot/stdout.expected <<EOF
1278 768705e3 2021-09-27 thomas A be/lots/of
1279 768705e3 2021-09-27 thomas A files/here
1280 768705e3 2021-09-27 thomas A there/should
1281 768705e3 2021-09-27 thomas Merged refs/heads/files into refs/heads/master: $merge_commit0
1282 768705e3 2021-09-27 thomas EOF
1283 768705e3 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1284 fc414659 2022-04-16 thomas ret=$?
1285 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1286 768705e3 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1287 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1288 768705e3 2021-09-27 thomas return 1
1289 768705e3 2021-09-27 thomas fi
1290 768705e3 2021-09-27 thomas
1291 768705e3 2021-09-27 thomas # try to merge again while no new changes are available
1292 768705e3 2021-09-27 thomas (cd $testroot/wt && got merge files > $testroot/stdout)
1293 fc414659 2022-04-16 thomas ret=$?
1294 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1295 768705e3 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1296 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1297 768705e3 2021-09-27 thomas return 1
1298 768705e3 2021-09-27 thomas fi
1299 768705e3 2021-09-27 thomas echo "Already up-to-date" > $testroot/stdout.expected
1300 2d7ce510 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1301 fc414659 2022-04-16 thomas ret=$?
1302 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1303 2d7ce510 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1304 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1305 768705e3 2021-09-27 thomas return 1
1306 2d7ce510 2021-09-24 thomas fi
1307 768705e3 2021-09-27 thomas
1308 768705e3 2021-09-27 thomas # update the 'files' branch
1309 768705e3 2021-09-27 thomas (cd $testroot/repo && git reset -q --hard master)
1310 768705e3 2021-09-27 thomas (cd $testroot/repo && git checkout -q files)
1311 768705e3 2021-09-27 thomas echo "indeed" > $testroot/repo/indeed
1312 768705e3 2021-09-27 thomas (cd $testroot/repo && git add indeed)
1313 768705e3 2021-09-27 thomas git_commit $testroot/repo -m "adding another file indeed"
1314 768705e3 2021-09-27 thomas echo "be lots and lots of" > $testroot/repo/be/lots/of
1315 768705e3 2021-09-27 thomas git_commit $testroot/repo -m "lots of changes"
1316 768705e3 2021-09-27 thomas
1317 768705e3 2021-09-27 thomas (cd $testroot/wt && got update > /dev/null)
1318 fc414659 2022-04-16 thomas ret=$?
1319 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1320 768705e3 2021-09-27 thomas echo "got update failed unexpectedly" >&2
1321 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1322 768705e3 2021-09-27 thomas return 1
1323 768705e3 2021-09-27 thomas fi
1324 768705e3 2021-09-27 thomas
1325 768705e3 2021-09-27 thomas # we should now be able to merge more changes from files branch
1326 768705e3 2021-09-27 thomas (cd $testroot/wt && got merge files > $testroot/stdout)
1327 fc414659 2022-04-16 thomas ret=$?
1328 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1329 768705e3 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1330 768705e3 2021-09-27 thomas test_done "$testroot" "$ret"
1331 768705e3 2021-09-27 thomas return 1
1332 768705e3 2021-09-27 thomas fi
1333 768705e3 2021-09-27 thomas
1334 768705e3 2021-09-27 thomas local merge_commit1=`git_show_branch_head $testroot/repo master`
1335 768705e3 2021-09-27 thomas cat > $testroot/stdout.expected <<EOF
1336 768705e3 2021-09-27 thomas G be/lots/of
1337 768705e3 2021-09-27 thomas A indeed
1338 768705e3 2021-09-27 thomas Merged refs/heads/files into refs/heads/master: $merge_commit1
1339 768705e3 2021-09-27 thomas EOF
1340 768705e3 2021-09-27 thomas
1341 768705e3 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1342 fc414659 2022-04-16 thomas ret=$?
1343 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1344 768705e3 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1345 768705e3 2021-09-27 thomas fi
1346 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1347 10604dce 2021-09-24 thomas }
1348 ba34626b 2021-09-27 thomas
1349 ba34626b 2021-09-27 thomas test_merge_interrupt() {
1350 ba34626b 2021-09-27 thomas local testroot=`test_init merge_interrupt`
1351 ba34626b 2021-09-27 thomas local commit0=`git_show_head $testroot/repo`
1352 ba34626b 2021-09-27 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
1353 ba34626b 2021-09-27 thomas
1354 ba34626b 2021-09-27 thomas (cd $testroot/repo && git checkout -q -b newbranch)
1355 ba34626b 2021-09-27 thomas echo "modified alpha on branch" > $testroot/repo/alpha
1356 ba34626b 2021-09-27 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
1357 ba34626b 2021-09-27 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
1358 ba34626b 2021-09-27 thomas
1359 ba34626b 2021-09-27 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
1360 fc414659 2022-04-16 thomas ret=$?
1361 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1362 ba34626b 2021-09-27 thomas echo "got checkout failed unexpectedly" >&2
1363 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1364 ba34626b 2021-09-27 thomas return 1
1365 ba34626b 2021-09-27 thomas fi
1366 ba34626b 2021-09-27 thomas
1367 ba34626b 2021-09-27 thomas # create a non-conflicting commit
1368 ba34626b 2021-09-27 thomas (cd $testroot/repo && git checkout -q master)
1369 ba34626b 2021-09-27 thomas echo "modified beta on master" > $testroot/repo/beta
1370 ba34626b 2021-09-27 thomas git_commit $testroot/repo -m "committing to beta on master"
1371 ba34626b 2021-09-27 thomas local master_commit=`git_show_head $testroot/repo`
1372 10604dce 2021-09-24 thomas
1373 b6b86fd1 2022-08-30 thomas # need an up-to-date work tree for 'got merge'
1374 ba34626b 2021-09-27 thomas (cd $testroot/wt && got update > /dev/null)
1375 fc414659 2022-04-16 thomas ret=$?
1376 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1377 ba34626b 2021-09-27 thomas echo "got update failed unexpectedly" >&2
1378 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1379 ba34626b 2021-09-27 thomas return 1
1380 ba34626b 2021-09-27 thomas fi
1381 ba34626b 2021-09-27 thomas
1382 ba34626b 2021-09-27 thomas (cd $testroot/wt && got merge -n newbranch \
1383 ba34626b 2021-09-27 thomas > $testroot/stdout 2> $testroot/stderr)
1384 fc414659 2022-04-16 thomas ret=$?
1385 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1386 ba34626b 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1387 ba34626b 2021-09-27 thomas test_done "$testroot" "1"
1388 ba34626b 2021-09-27 thomas return 1
1389 ba34626b 2021-09-27 thomas fi
1390 ba34626b 2021-09-27 thomas
1391 ba34626b 2021-09-27 thomas echo "G alpha" > $testroot/stdout.expected
1392 ba34626b 2021-09-27 thomas echo "Merge of refs/heads/newbranch interrupted on request" \
1393 ba34626b 2021-09-27 thomas >> $testroot/stdout.expected
1394 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1395 fc414659 2022-04-16 thomas ret=$?
1396 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1397 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1398 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1399 ba34626b 2021-09-27 thomas return 1
1400 ba34626b 2021-09-27 thomas fi
1401 ba34626b 2021-09-27 thomas
1402 ba34626b 2021-09-27 thomas (cd $testroot/wt && got status > $testroot/stdout)
1403 ba34626b 2021-09-27 thomas
1404 ba34626b 2021-09-27 thomas echo "M alpha" > $testroot/stdout.expected
1405 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1406 fc414659 2022-04-16 thomas ret=$?
1407 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1408 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1409 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1410 ba34626b 2021-09-27 thomas return 1
1411 ba34626b 2021-09-27 thomas fi
1412 ba34626b 2021-09-27 thomas
1413 ba34626b 2021-09-27 thomas echo "modified alpha on branch" > $testroot/content.expected
1414 ba34626b 2021-09-27 thomas cat $testroot/wt/alpha > $testroot/content
1415 ba34626b 2021-09-27 thomas cmp -s $testroot/content.expected $testroot/content
1416 fc414659 2022-04-16 thomas ret=$?
1417 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1418 ba34626b 2021-09-27 thomas diff -u $testroot/content.expected $testroot/content
1419 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1420 ba34626b 2021-09-27 thomas return 1
1421 ba34626b 2021-09-27 thomas fi
1422 ba34626b 2021-09-27 thomas
1423 ba34626b 2021-09-27 thomas # adjust merge result
1424 ba34626b 2021-09-27 thomas echo "adjusted merge result" > $testroot/wt/alpha
1425 ba34626b 2021-09-27 thomas
1426 ba34626b 2021-09-27 thomas # continue the merge
1427 ba34626b 2021-09-27 thomas (cd $testroot/wt && got merge -c > $testroot/stdout)
1428 fc414659 2022-04-16 thomas ret=$?
1429 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1430 ba34626b 2021-09-27 thomas echo "got merge failed unexpectedly" >&2
1431 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1432 ba34626b 2021-09-27 thomas return 1
1433 ba34626b 2021-09-27 thomas fi
1434 ba34626b 2021-09-27 thomas
1435 ba34626b 2021-09-27 thomas local merge_commit=`git_show_head $testroot/repo`
1436 ba34626b 2021-09-27 thomas
1437 ae1e948a 2021-09-28 thomas echo "M alpha" > $testroot/stdout.expected
1438 ba34626b 2021-09-27 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
1439 ae1e948a 2021-09-28 thomas >> $testroot/stdout.expected
1440 ba34626b 2021-09-27 thomas echo $merge_commit >> $testroot/stdout.expected
1441 ba34626b 2021-09-27 thomas
1442 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1443 fc414659 2022-04-16 thomas ret=$?
1444 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1445 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1446 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1447 ba34626b 2021-09-27 thomas return 1
1448 ba34626b 2021-09-27 thomas fi
1449 ba34626b 2021-09-27 thomas
1450 ba34626b 2021-09-27 thomas (cd $testroot/wt && got status > $testroot/stdout)
1451 ba34626b 2021-09-27 thomas
1452 ba34626b 2021-09-27 thomas echo -n > $testroot/stdout.expected
1453 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1454 fc414659 2022-04-16 thomas ret=$?
1455 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1456 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1457 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1458 ba34626b 2021-09-27 thomas return 1
1459 ba34626b 2021-09-27 thomas fi
1460 ba34626b 2021-09-27 thomas
1461 ba34626b 2021-09-27 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1462 ba34626b 2021-09-27 thomas echo "commit $merge_commit (master)" > $testroot/stdout.expected
1463 ba34626b 2021-09-27 thomas echo "commit $master_commit" >> $testroot/stdout.expected
1464 ba34626b 2021-09-27 thomas echo "commit $commit0" >> $testroot/stdout.expected
1465 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1466 fc414659 2022-04-16 thomas ret=$?
1467 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1468 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1469 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1470 ba34626b 2021-09-27 thomas return 1
1471 ba34626b 2021-09-27 thomas fi
1472 ba34626b 2021-09-27 thomas
1473 ba34626b 2021-09-27 thomas (cd $testroot/wt && got update > $testroot/stdout)
1474 ba34626b 2021-09-27 thomas
1475 ba34626b 2021-09-27 thomas echo 'Already up-to-date' > $testroot/stdout.expected
1476 ba34626b 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 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1480 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1481 ba34626b 2021-09-27 thomas return 1
1482 ba34626b 2021-09-27 thomas fi
1483 ba34626b 2021-09-27 thomas
1484 ba34626b 2021-09-27 thomas # We should have created a merge commit with two parents.
1485 ba34626b 2021-09-27 thomas (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
1486 ba34626b 2021-09-27 thomas echo "parent 1: $master_commit" > $testroot/stdout.expected
1487 ba34626b 2021-09-27 thomas echo "parent 2: $branch_commit0" >> $testroot/stdout.expected
1488 ba34626b 2021-09-27 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1489 fc414659 2022-04-16 thomas ret=$?
1490 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1491 ba34626b 2021-09-27 thomas diff -u $testroot/stdout.expected $testroot/stdout
1492 ba34626b 2021-09-27 thomas fi
1493 ba34626b 2021-09-27 thomas test_done "$testroot" "$ret"
1494 a2c162eb 2022-10-30 thomas }
1495 a2c162eb 2022-10-30 thomas
1496 a2c162eb 2022-10-30 thomas test_merge_umask() {
1497 a2c162eb 2022-10-30 thomas local testroot=`test_init merge_umask`
1498 a2c162eb 2022-10-30 thomas
1499 a2c162eb 2022-10-30 thomas (cd $testroot/repo && git checkout -q -b newbranch)
1500 a2c162eb 2022-10-30 thomas echo "modified alpha on branch" >$testroot/repo/alpha
1501 a2c162eb 2022-10-30 thomas git_commit "$testroot/repo" -m "committing alpha on newbranch"
1502 a2c162eb 2022-10-30 thomas echo "modified delta on branch" >$testroot/repo/gamma/delta
1503 a2c162eb 2022-10-30 thomas git_commit "$testroot/repo" -m "committing delta on newbranch"
1504 a2c162eb 2022-10-30 thomas
1505 a2c162eb 2022-10-30 thomas # diverge from newbranch
1506 a2c162eb 2022-10-30 thomas (cd "$testroot/repo" && git checkout -q master)
1507 a2c162eb 2022-10-30 thomas echo "modified beta on master" >$testroot/repo/beta
1508 a2c162eb 2022-10-30 thomas git_commit "$testroot/repo" -m "committing zeto no master"
1509 a2c162eb 2022-10-30 thomas
1510 a2c162eb 2022-10-30 thomas got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1511 a2c162eb 2022-10-30 thomas
1512 a2c162eb 2022-10-30 thomas # using a subshell to avoid clobbering global umask
1513 a2c162eb 2022-10-30 thomas (umask 077 && cd "$testroot/wt" && got merge newbranch) >/dev/null
1514 a2c162eb 2022-10-30 thomas
1515 a2c162eb 2022-10-30 thomas for f in alpha gamma/delta; do
1516 a2c162eb 2022-10-30 thomas ls -l "$testroot/wt/$f" | grep -q ^-rw-------
1517 a2c162eb 2022-10-30 thomas if [ $? -ne 0 ]; then
1518 a2c162eb 2022-10-30 thomas echo "$f is not 0600 after merge" >&2
1519 a2c162eb 2022-10-30 thomas ls -l "$testroot/wt/$f" >&2
1520 a2c162eb 2022-10-30 thomas test_done "$testroot" 1
1521 a2c162eb 2022-10-30 thomas fi
1522 a2c162eb 2022-10-30 thomas done
1523 a2c162eb 2022-10-30 thomas
1524 a2c162eb 2022-10-30 thomas test_done "$testroot" 0
1525 ba34626b 2021-09-27 thomas }
1526 b16f1832 2023-02-21 thomas
1527 b16f1832 2023-02-21 thomas test_merge_gitconfig_author() {
1528 b16f1832 2023-02-21 thomas local testroot=`test_init merge_gitconfig_author`
1529 b16f1832 2023-02-21 thomas
1530 b16f1832 2023-02-21 thomas (cd $testroot/repo && git config user.name 'Flan Luck')
1531 b16f1832 2023-02-21 thomas (cd $testroot/repo && git config user.email 'flan_luck@openbsd.org')
1532 b16f1832 2023-02-21 thomas
1533 b16f1832 2023-02-21 thomas (cd $testroot/repo && git checkout -q -b newbranch)
1534 b16f1832 2023-02-21 thomas echo "modified alpha on branch" >$testroot/repo/alpha
1535 b16f1832 2023-02-21 thomas git_commit "$testroot/repo" -m "committing alpha on newbranch"
1536 b16f1832 2023-02-21 thomas echo "modified delta on branch" >$testroot/repo/gamma/delta
1537 b16f1832 2023-02-21 thomas git_commit "$testroot/repo" -m "committing delta on newbranch"
1538 ba34626b 2021-09-27 thomas
1539 b16f1832 2023-02-21 thomas # diverge from newbranch
1540 b16f1832 2023-02-21 thomas (cd "$testroot/repo" && git checkout -q master)
1541 b16f1832 2023-02-21 thomas echo "modified beta on master" >$testroot/repo/beta
1542 b16f1832 2023-02-21 thomas git_commit "$testroot/repo" -m "committing zeto no master"
1543 b16f1832 2023-02-21 thomas
1544 b16f1832 2023-02-21 thomas got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1545 b16f1832 2023-02-21 thomas
1546 b16f1832 2023-02-21 thomas # unset in a subshell to avoid affecting our environment
1547 b16f1832 2023-02-21 thomas (unset GOT_IGNORE_GITCONFIG && cd $testroot/wt && \
1548 b16f1832 2023-02-21 thomas got merge newbranch > /dev/null)
1549 b16f1832 2023-02-21 thomas
1550 b16f1832 2023-02-21 thomas (cd $testroot/repo && got log -l1 | grep ^from: > $testroot/stdout)
1551 b16f1832 2023-02-21 thomas ret=$?
1552 b16f1832 2023-02-21 thomas if [ $ret -ne 0 ]; then
1553 b16f1832 2023-02-21 thomas test_done "$testroot" "$ret"
1554 b16f1832 2023-02-21 thomas return 1
1555 b16f1832 2023-02-21 thomas fi
1556 b16f1832 2023-02-21 thomas
1557 b16f1832 2023-02-21 thomas echo "from: Flan Luck <flan_luck@openbsd.org>" \
1558 b16f1832 2023-02-21 thomas > $testroot/stdout.expected
1559 b16f1832 2023-02-21 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1560 b16f1832 2023-02-21 thomas ret=$?
1561 b16f1832 2023-02-21 thomas if [ $ret -ne 0 ]; then
1562 b16f1832 2023-02-21 thomas diff -u $testroot/stdout.expected $testroot/stdout
1563 b16f1832 2023-02-21 thomas fi
1564 b16f1832 2023-02-21 thomas test_done "$testroot" "$ret"
1565 b16f1832 2023-02-21 thomas }
1566 b16f1832 2023-02-21 thomas
1567 10604dce 2021-09-24 thomas test_parseargs "$@"
1568 10604dce 2021-09-24 thomas run_test test_merge_basic
1569 10604dce 2021-09-24 thomas run_test test_merge_continue
1570 fe3f264b 2023-06-08 thomas run_test test_merge_continue_new_commit
1571 10604dce 2021-09-24 thomas run_test test_merge_abort
1572 10604dce 2021-09-24 thomas run_test test_merge_in_progress
1573 10604dce 2021-09-24 thomas run_test test_merge_path_prefix
1574 10604dce 2021-09-24 thomas run_test test_merge_missing_file
1575 2d7ce510 2021-09-24 thomas run_test test_merge_no_op
1576 768705e3 2021-09-27 thomas run_test test_merge_imported_branch
1577 ba34626b 2021-09-27 thomas run_test test_merge_interrupt
1578 a2c162eb 2022-10-30 thomas run_test test_merge_umask
1579 b16f1832 2023-02-21 thomas run_test test_merge_gitconfig_author