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 10604dce 2021-09-24 thomas
43 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
44 10604dce 2021-09-24 thomas ret="$?"
45 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
46 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
47 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
48 10604dce 2021-09-24 thomas return 1
49 10604dce 2021-09-24 thomas fi
50 10604dce 2021-09-24 thomas
51 10604dce 2021-09-24 thomas # need a divergant commit on the main branch for 'got merge'
52 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
53 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
54 10604dce 2021-09-24 thomas ret="$?"
55 10604dce 2021-09-24 thomas if [ "$ret" == "0" ]; then
56 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
57 10604dce 2021-09-24 thomas test_done "$testroot" "1"
58 10604dce 2021-09-24 thomas return 1
59 10604dce 2021-09-24 thomas fi
60 10604dce 2021-09-24 thomas echo -n "got: cannot create a merge commit because " \
61 10604dce 2021-09-24 thomas > $testroot/stderr.expected
62 10604dce 2021-09-24 thomas echo -n "refs/heads/newbranch is based on refs/heads/master; " \
63 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
64 10604dce 2021-09-24 thomas echo -n "refs/heads/newbranch can be integrated with " \
65 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
66 10604dce 2021-09-24 thomas echo "'got integrate' instead" >> $testroot/stderr.expected
67 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
68 10604dce 2021-09-24 thomas ret="$?"
69 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
70 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
71 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
72 10604dce 2021-09-24 thomas return 1
73 10604dce 2021-09-24 thomas fi
74 10604dce 2021-09-24 thomas
75 10604dce 2021-09-24 thomas # create the required dirvergant commit
76 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
77 10604dce 2021-09-24 thomas echo "modified zeta on master" > $testroot/repo/epsilon/zeta
78 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to zeta on master"
79 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
80 10604dce 2021-09-24 thomas
81 10604dce 2021-09-24 thomas # need an up-to-date work tree for 'got merge'
82 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
83 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
84 10604dce 2021-09-24 thomas ret="$?"
85 10604dce 2021-09-24 thomas if [ "$ret" == "0" ]; then
86 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
87 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
88 10604dce 2021-09-24 thomas return 1
89 10604dce 2021-09-24 thomas fi
90 10604dce 2021-09-24 thomas echo -n "got: work tree must be updated before it can be used " \
91 10604dce 2021-09-24 thomas > $testroot/stderr.expected
92 10604dce 2021-09-24 thomas echo "to merge a branch" >> $testroot/stderr.expected
93 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
94 10604dce 2021-09-24 thomas ret="$?"
95 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
96 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
97 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
98 10604dce 2021-09-24 thomas return 1
99 10604dce 2021-09-24 thomas fi
100 10604dce 2021-09-24 thomas
101 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
102 10604dce 2021-09-24 thomas ret="$?"
103 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
104 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
105 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
106 10604dce 2021-09-24 thomas return 1
107 10604dce 2021-09-24 thomas fi
108 10604dce 2021-09-24 thomas
109 10604dce 2021-09-24 thomas # must not use a mixed-commit work tree with 'got merge'
110 10604dce 2021-09-24 thomas (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
111 10604dce 2021-09-24 thomas ret="$?"
112 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
113 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
114 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
115 10604dce 2021-09-24 thomas return 1
116 10604dce 2021-09-24 thomas fi
117 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
118 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
119 10604dce 2021-09-24 thomas ret="$?"
120 10604dce 2021-09-24 thomas if [ "$ret" == "0" ]; then
121 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
122 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
123 10604dce 2021-09-24 thomas return 1
124 10604dce 2021-09-24 thomas fi
125 10604dce 2021-09-24 thomas echo -n "got: work tree contains files from multiple base commits; " \
126 10604dce 2021-09-24 thomas > $testroot/stderr.expected
127 10604dce 2021-09-24 thomas echo "the entire work tree must be updated first" \
128 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
129 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
130 10604dce 2021-09-24 thomas ret="$?"
131 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
132 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
133 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
134 10604dce 2021-09-24 thomas return 1
135 10604dce 2021-09-24 thomas fi
136 10604dce 2021-09-24 thomas
137 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
138 10604dce 2021-09-24 thomas ret="$?"
139 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
140 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
141 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
142 10604dce 2021-09-24 thomas return 1
143 10604dce 2021-09-24 thomas fi
144 10604dce 2021-09-24 thomas
145 10604dce 2021-09-24 thomas # must not have staged files with 'got merge'
146 10604dce 2021-09-24 thomas echo "modified file alpha" > $testroot/wt/alpha
147 10604dce 2021-09-24 thomas (cd $testroot/wt && got stage alpha > /dev/null)
148 10604dce 2021-09-24 thomas ret="$?"
149 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
150 10604dce 2021-09-24 thomas echo "got stage failed unexpectedly" >&2
151 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
152 10604dce 2021-09-24 thomas return 1
153 10604dce 2021-09-24 thomas fi
154 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
155 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
156 10604dce 2021-09-24 thomas ret="$?"
157 10604dce 2021-09-24 thomas if [ "$ret" == "0" ]; then
158 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
159 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
160 10604dce 2021-09-24 thomas return 1
161 10604dce 2021-09-24 thomas fi
162 10604dce 2021-09-24 thomas echo "got: alpha: file is staged" > $testroot/stderr.expected
163 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
164 10604dce 2021-09-24 thomas ret="$?"
165 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
166 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
167 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
168 10604dce 2021-09-24 thomas return 1
169 10604dce 2021-09-24 thomas fi
170 10604dce 2021-09-24 thomas (cd $testroot/wt && got unstage alpha > /dev/null)
171 10604dce 2021-09-24 thomas ret="$?"
172 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
173 10604dce 2021-09-24 thomas echo "got unstage failed unexpectedly" >&2
174 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
175 10604dce 2021-09-24 thomas return 1
176 10604dce 2021-09-24 thomas fi
177 10604dce 2021-09-24 thomas
178 10604dce 2021-09-24 thomas # must not have local changes with 'got merge'
179 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
180 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
181 10604dce 2021-09-24 thomas ret="$?"
182 10604dce 2021-09-24 thomas if [ "$ret" == "0" ]; then
183 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
184 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
185 10604dce 2021-09-24 thomas return 1
186 10604dce 2021-09-24 thomas fi
187 10604dce 2021-09-24 thomas echo -n "got: work tree contains local changes; " \
188 10604dce 2021-09-24 thomas > $testroot/stderr.expected
189 10604dce 2021-09-24 thomas echo "these changes must be committed or reverted first" \
190 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
191 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
192 10604dce 2021-09-24 thomas ret="$?"
193 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
194 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
195 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
196 10604dce 2021-09-24 thomas return 1
197 10604dce 2021-09-24 thomas fi
198 10604dce 2021-09-24 thomas
199 10604dce 2021-09-24 thomas (cd $testroot/wt && got revert alpha > /dev/null)
200 10604dce 2021-09-24 thomas ret="$?"
201 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
202 10604dce 2021-09-24 thomas echo "got revert failed unexpectedly" >&2
203 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
204 10604dce 2021-09-24 thomas return 1
205 10604dce 2021-09-24 thomas fi
206 10604dce 2021-09-24 thomas
207 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch > $testroot/stdout)
208 10604dce 2021-09-24 thomas ret="$?"
209 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
210 10604dce 2021-09-24 thomas echo "got merge failed unexpectedly" >&2
211 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
212 10604dce 2021-09-24 thomas return 1
213 10604dce 2021-09-24 thomas fi
214 10604dce 2021-09-24 thomas
215 10604dce 2021-09-24 thomas local merge_commit=`git_show_head $testroot/repo`
216 10604dce 2021-09-24 thomas
217 10604dce 2021-09-24 thomas echo "G alpha" >> $testroot/stdout.expected
218 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
219 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
220 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
221 10604dce 2021-09-24 thomas echo "A symlink" >> $testroot/stdout.expected
222 10604dce 2021-09-24 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
223 10604dce 2021-09-24 thomas >> $testroot/stdout.expected
224 10604dce 2021-09-24 thomas echo $merge_commit >> $testroot/stdout.expected
225 10604dce 2021-09-24 thomas
226 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
227 10604dce 2021-09-24 thomas ret="$?"
228 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
229 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
230 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
231 10604dce 2021-09-24 thomas return 1
232 10604dce 2021-09-24 thomas fi
233 10604dce 2021-09-24 thomas
234 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/content.expected
235 10604dce 2021-09-24 thomas cat $testroot/wt/gamma/delta > $testroot/content
236 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
237 10604dce 2021-09-24 thomas ret="$?"
238 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
239 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
240 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
241 10604dce 2021-09-24 thomas return 1
242 10604dce 2021-09-24 thomas fi
243 10604dce 2021-09-24 thomas
244 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/content.expected
245 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
246 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
247 10604dce 2021-09-24 thomas ret="$?"
248 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
249 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
250 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
251 10604dce 2021-09-24 thomas return 1
252 10604dce 2021-09-24 thomas fi
253 10604dce 2021-09-24 thomas
254 10604dce 2021-09-24 thomas if [ -e $testroot/wt/beta ]; then
255 10604dce 2021-09-24 thomas echo "removed file beta still exists on disk" >&2
256 10604dce 2021-09-24 thomas test_done "$testroot" "1"
257 10604dce 2021-09-24 thomas return 1
258 10604dce 2021-09-24 thomas fi
259 10604dce 2021-09-24 thomas
260 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/content.expected
261 10604dce 2021-09-24 thomas cat $testroot/wt/epsilon/new > $testroot/content
262 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
263 10604dce 2021-09-24 thomas ret="$?"
264 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
265 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
266 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
267 10604dce 2021-09-24 thomas return 1
268 10604dce 2021-09-24 thomas fi
269 10604dce 2021-09-24 thomas
270 10604dce 2021-09-24 thomas readlink $testroot/wt/symlink > $testroot/stdout
271 10604dce 2021-09-24 thomas echo "alpha" > $testroot/stdout.expected
272 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
273 10604dce 2021-09-24 thomas ret="$?"
274 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
275 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
276 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
277 10604dce 2021-09-24 thomas return 1
278 10604dce 2021-09-24 thomas fi
279 10604dce 2021-09-24 thomas
280 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
281 10604dce 2021-09-24 thomas
282 10604dce 2021-09-24 thomas echo -n > $testroot/stdout.expected
283 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
284 10604dce 2021-09-24 thomas ret="$?"
285 10604dce 2021-09-24 thomas if [ "$ret" != "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 log -l3 | grep ^commit > $testroot/stdout)
292 10604dce 2021-09-24 thomas echo "commit $merge_commit (master)" > $testroot/stdout.expected
293 10604dce 2021-09-24 thomas echo "commit $master_commit" >> $testroot/stdout.expected
294 10604dce 2021-09-24 thomas echo "commit $commit0" >> $testroot/stdout.expected
295 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
296 10604dce 2021-09-24 thomas ret="$?"
297 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
298 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
299 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
300 10604dce 2021-09-24 thomas return 1
301 10604dce 2021-09-24 thomas fi
302 10604dce 2021-09-24 thomas
303 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > $testroot/stdout)
304 10604dce 2021-09-24 thomas
305 10604dce 2021-09-24 thomas echo 'Already up-to-date' > $testroot/stdout.expected
306 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
307 10604dce 2021-09-24 thomas ret="$?"
308 10604dce 2021-09-24 thomas if [ "$ret" != "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 # We should have created a merge commit with two parents.
315 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
316 10604dce 2021-09-24 thomas echo "parent 1: $master_commit" > $testroot/stdout.expected
317 10604dce 2021-09-24 thomas echo "parent 2: $branch_commit4" >> $testroot/stdout.expected
318 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
319 10604dce 2021-09-24 thomas ret="$?"
320 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
321 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
322 10604dce 2021-09-24 thomas fi
323 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
324 10604dce 2021-09-24 thomas }
325 10604dce 2021-09-24 thomas
326 10604dce 2021-09-24 thomas test_merge_continue() {
327 10604dce 2021-09-24 thomas local testroot=`test_init merge_continue`
328 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
329 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
330 10604dce 2021-09-24 thomas
331 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
332 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
333 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to delta on newbranch"
334 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
335 10604dce 2021-09-24 thomas
336 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
337 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
338 10604dce 2021-09-24 thomas local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
339 10604dce 2021-09-24 thomas (cd $testroot/repo && git rm -q beta)
340 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "removing beta on newbranch"
341 10604dce 2021-09-24 thomas local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
342 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/repo/epsilon/new
343 10604dce 2021-09-24 thomas (cd $testroot/repo && git add epsilon/new)
344 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding new file on newbranch"
345 10604dce 2021-09-24 thomas local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
346 10604dce 2021-09-24 thomas
347 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
348 10604dce 2021-09-24 thomas ret="$?"
349 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
350 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
351 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
352 10604dce 2021-09-24 thomas return 1
353 10604dce 2021-09-24 thomas fi
354 10604dce 2021-09-24 thomas
355 10604dce 2021-09-24 thomas # create a conflicting commit
356 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
357 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
358 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
359 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
360 10604dce 2021-09-24 thomas
361 10604dce 2021-09-24 thomas # need an up-to-date work tree for 'got merge'
362 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
363 10604dce 2021-09-24 thomas ret="$?"
364 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
365 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
366 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
367 10604dce 2021-09-24 thomas return 1
368 10604dce 2021-09-24 thomas fi
369 10604dce 2021-09-24 thomas
370 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
371 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
372 10604dce 2021-09-24 thomas ret="$?"
373 10604dce 2021-09-24 thomas if [ "$ret" == "0" ]; then
374 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
375 10604dce 2021-09-24 thomas test_done "$testroot" "1"
376 10604dce 2021-09-24 thomas return 1
377 10604dce 2021-09-24 thomas fi
378 10604dce 2021-09-24 thomas
379 10604dce 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
380 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
381 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
382 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
383 10604dce 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
384 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
385 10604dce 2021-09-24 thomas ret="$?"
386 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
387 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
388 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
389 10604dce 2021-09-24 thomas return 1
390 10604dce 2021-09-24 thomas fi
391 10604dce 2021-09-24 thomas
392 10604dce 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
393 10604dce 2021-09-24 thomas > $testroot/stderr.expected
394 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
395 10604dce 2021-09-24 thomas ret="$?"
396 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
397 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
398 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
399 10604dce 2021-09-24 thomas return 1
400 10604dce 2021-09-24 thomas fi
401 10604dce 2021-09-24 thomas
402 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
403 10604dce 2021-09-24 thomas
404 10604dce 2021-09-24 thomas echo "C alpha" > $testroot/stdout.expected
405 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
406 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
407 10604dce 2021-09-24 thomas echo "M gamma/delta" >> $testroot/stdout.expected
408 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
409 10604dce 2021-09-24 thomas ret="$?"
410 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
411 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
412 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
413 10604dce 2021-09-24 thomas return 1
414 10604dce 2021-09-24 thomas fi
415 10604dce 2021-09-24 thomas
416 10604dce 2021-09-24 thomas echo '<<<<<<<' > $testroot/content.expected
417 10604dce 2021-09-24 thomas echo "modified alpha on master" >> $testroot/content.expected
418 10604dce 2021-09-24 thomas echo "||||||| 3-way merge base: commit $commit0" \
419 10604dce 2021-09-24 thomas >> $testroot/content.expected
420 10604dce 2021-09-24 thomas echo "alpha" >> $testroot/content.expected
421 10604dce 2021-09-24 thomas echo "=======" >> $testroot/content.expected
422 10604dce 2021-09-24 thomas echo "modified alpha on branch" >> $testroot/content.expected
423 10604dce 2021-09-24 thomas echo ">>>>>>> merged change: commit $branch_commit3" \
424 10604dce 2021-09-24 thomas >> $testroot/content.expected
425 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
426 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
427 10604dce 2021-09-24 thomas ret="$?"
428 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
429 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
430 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
431 10604dce 2021-09-24 thomas return 1
432 10604dce 2021-09-24 thomas fi
433 10604dce 2021-09-24 thomas
434 10604dce 2021-09-24 thomas # resolve the conflict
435 10604dce 2021-09-24 thomas echo "modified alpha by both branches" > $testroot/wt/alpha
436 10604dce 2021-09-24 thomas
437 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge -c > $testroot/stdout)
438 10604dce 2021-09-24 thomas ret="$?"
439 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
440 10604dce 2021-09-24 thomas echo "got merge failed unexpectedly" >&2
441 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
442 10604dce 2021-09-24 thomas return 1
443 10604dce 2021-09-24 thomas fi
444 10604dce 2021-09-24 thomas
445 10604dce 2021-09-24 thomas local merge_commit=`git_show_head $testroot/repo`
446 10604dce 2021-09-24 thomas
447 10604dce 2021-09-24 thomas echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
448 10604dce 2021-09-24 thomas > $testroot/stdout.expected
449 10604dce 2021-09-24 thomas echo $merge_commit >> $testroot/stdout.expected
450 10604dce 2021-09-24 thomas
451 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
452 10604dce 2021-09-24 thomas ret="$?"
453 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
454 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
455 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
456 10604dce 2021-09-24 thomas return 1
457 10604dce 2021-09-24 thomas fi
458 10604dce 2021-09-24 thomas
459 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/content.expected
460 10604dce 2021-09-24 thomas cat $testroot/wt/gamma/delta > $testroot/content
461 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
462 10604dce 2021-09-24 thomas ret="$?"
463 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
464 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
465 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
466 10604dce 2021-09-24 thomas return 1
467 10604dce 2021-09-24 thomas fi
468 10604dce 2021-09-24 thomas
469 10604dce 2021-09-24 thomas echo "modified alpha by both branches" > $testroot/content.expected
470 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
471 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
472 10604dce 2021-09-24 thomas ret="$?"
473 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
474 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
475 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
476 10604dce 2021-09-24 thomas return 1
477 10604dce 2021-09-24 thomas fi
478 10604dce 2021-09-24 thomas
479 10604dce 2021-09-24 thomas if [ -e $testroot/wt/beta ]; then
480 10604dce 2021-09-24 thomas echo "removed file beta still exists on disk" >&2
481 10604dce 2021-09-24 thomas test_done "$testroot" "1"
482 10604dce 2021-09-24 thomas return 1
483 10604dce 2021-09-24 thomas fi
484 10604dce 2021-09-24 thomas
485 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/content.expected
486 10604dce 2021-09-24 thomas cat $testroot/wt/epsilon/new > $testroot/content
487 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
488 10604dce 2021-09-24 thomas ret="$?"
489 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
490 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
491 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
492 10604dce 2021-09-24 thomas return 1
493 10604dce 2021-09-24 thomas fi
494 10604dce 2021-09-24 thomas
495 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
496 10604dce 2021-09-24 thomas
497 10604dce 2021-09-24 thomas echo -n > $testroot/stdout.expected
498 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
499 10604dce 2021-09-24 thomas ret="$?"
500 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
501 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
502 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
503 10604dce 2021-09-24 thomas return 1
504 10604dce 2021-09-24 thomas fi
505 10604dce 2021-09-24 thomas
506 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
507 10604dce 2021-09-24 thomas echo "commit $merge_commit (master)" > $testroot/stdout.expected
508 10604dce 2021-09-24 thomas echo "commit $master_commit" >> $testroot/stdout.expected
509 10604dce 2021-09-24 thomas echo "commit $commit0" >> $testroot/stdout.expected
510 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
511 10604dce 2021-09-24 thomas ret="$?"
512 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
513 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
514 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
515 10604dce 2021-09-24 thomas return 1
516 10604dce 2021-09-24 thomas fi
517 10604dce 2021-09-24 thomas
518 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > $testroot/stdout)
519 10604dce 2021-09-24 thomas
520 10604dce 2021-09-24 thomas echo 'Already up-to-date' > $testroot/stdout.expected
521 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
522 10604dce 2021-09-24 thomas ret="$?"
523 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
524 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
525 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
526 10604dce 2021-09-24 thomas return 1
527 10604dce 2021-09-24 thomas fi
528 10604dce 2021-09-24 thomas
529 10604dce 2021-09-24 thomas # We should have created a merge commit with two parents.
530 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
531 10604dce 2021-09-24 thomas echo "parent 1: $master_commit" > $testroot/stdout.expected
532 10604dce 2021-09-24 thomas echo "parent 2: $branch_commit3" >> $testroot/stdout.expected
533 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
534 10604dce 2021-09-24 thomas ret="$?"
535 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
536 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
537 10604dce 2021-09-24 thomas fi
538 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
539 10604dce 2021-09-24 thomas }
540 10604dce 2021-09-24 thomas
541 10604dce 2021-09-24 thomas test_merge_abort() {
542 10604dce 2021-09-24 thomas local testroot=`test_init merge_abort`
543 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
544 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
545 10604dce 2021-09-24 thomas
546 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
547 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
548 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to delta on newbranch"
549 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
550 10604dce 2021-09-24 thomas
551 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
552 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
553 10604dce 2021-09-24 thomas local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
554 10604dce 2021-09-24 thomas (cd $testroot/repo && git rm -q beta)
555 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "removing beta on newbranch"
556 10604dce 2021-09-24 thomas local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
557 10604dce 2021-09-24 thomas echo "new file on branch" > $testroot/repo/epsilon/new
558 10604dce 2021-09-24 thomas (cd $testroot/repo && git add epsilon/new)
559 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding new file on newbranch"
560 10604dce 2021-09-24 thomas local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
561 10604dce 2021-09-24 thomas (cd $testroot/repo && ln -s alpha symlink && git add symlink)
562 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "adding symlink on newbranch"
563 10604dce 2021-09-24 thomas local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
564 10604dce 2021-09-24 thomas
565 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
566 10604dce 2021-09-24 thomas ret="$?"
567 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
568 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
569 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
570 10604dce 2021-09-24 thomas return 1
571 10604dce 2021-09-24 thomas fi
572 10604dce 2021-09-24 thomas
573 10604dce 2021-09-24 thomas # create a conflicting commit
574 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
575 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
576 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
577 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
578 10604dce 2021-09-24 thomas
579 10604dce 2021-09-24 thomas # need an up-to-date work tree for 'got merge'
580 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
581 10604dce 2021-09-24 thomas ret="$?"
582 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
583 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
584 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
585 10604dce 2021-09-24 thomas return 1
586 10604dce 2021-09-24 thomas fi
587 10604dce 2021-09-24 thomas
588 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
589 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
590 10604dce 2021-09-24 thomas ret="$?"
591 10604dce 2021-09-24 thomas if [ "$ret" == "0" ]; then
592 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
593 10604dce 2021-09-24 thomas test_done "$testroot" "1"
594 10604dce 2021-09-24 thomas return 1
595 10604dce 2021-09-24 thomas fi
596 10604dce 2021-09-24 thomas
597 10604dce 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
598 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
599 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
600 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
601 10604dce 2021-09-24 thomas echo "A symlink" >> $testroot/stdout.expected
602 10604dce 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
603 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
604 10604dce 2021-09-24 thomas ret="$?"
605 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
606 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
607 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
608 10604dce 2021-09-24 thomas return 1
609 10604dce 2021-09-24 thomas fi
610 10604dce 2021-09-24 thomas
611 10604dce 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
612 10604dce 2021-09-24 thomas > $testroot/stderr.expected
613 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
614 10604dce 2021-09-24 thomas ret="$?"
615 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
616 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
617 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
618 10604dce 2021-09-24 thomas return 1
619 10604dce 2021-09-24 thomas fi
620 10604dce 2021-09-24 thomas
621 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
622 10604dce 2021-09-24 thomas
623 10604dce 2021-09-24 thomas echo "C alpha" > $testroot/stdout.expected
624 10604dce 2021-09-24 thomas echo "D beta" >> $testroot/stdout.expected
625 10604dce 2021-09-24 thomas echo "A epsilon/new" >> $testroot/stdout.expected
626 10604dce 2021-09-24 thomas echo "M gamma/delta" >> $testroot/stdout.expected
627 10604dce 2021-09-24 thomas echo "A symlink" >> $testroot/stdout.expected
628 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
629 10604dce 2021-09-24 thomas ret="$?"
630 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
631 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
632 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
633 10604dce 2021-09-24 thomas return 1
634 10604dce 2021-09-24 thomas fi
635 10604dce 2021-09-24 thomas
636 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge -a > $testroot/stdout)
637 10604dce 2021-09-24 thomas ret="$?"
638 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
639 10604dce 2021-09-24 thomas echo "got merge failed unexpectedly" >&2
640 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
641 10604dce 2021-09-24 thomas return 1
642 10604dce 2021-09-24 thomas fi
643 10604dce 2021-09-24 thomas
644 10604dce 2021-09-24 thomas echo "R alpha" > $testroot/stdout.expected
645 10604dce 2021-09-24 thomas echo "R beta" >> $testroot/stdout.expected
646 10604dce 2021-09-24 thomas echo "R epsilon/new" >> $testroot/stdout.expected
647 10604dce 2021-09-24 thomas echo "R gamma/delta" >> $testroot/stdout.expected
648 10604dce 2021-09-24 thomas echo "R symlink" >> $testroot/stdout.expected
649 10604dce 2021-09-24 thomas echo "Merge of refs/heads/newbranch aborted" \
650 10604dce 2021-09-24 thomas >> $testroot/stdout.expected
651 10604dce 2021-09-24 thomas
652 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
653 10604dce 2021-09-24 thomas ret="$?"
654 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
655 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
656 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
657 10604dce 2021-09-24 thomas return 1
658 10604dce 2021-09-24 thomas fi
659 10604dce 2021-09-24 thomas
660 10604dce 2021-09-24 thomas echo "delta" > $testroot/content.expected
661 10604dce 2021-09-24 thomas cat $testroot/wt/gamma/delta > $testroot/content
662 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
663 10604dce 2021-09-24 thomas ret="$?"
664 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
665 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
666 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
667 10604dce 2021-09-24 thomas return 1
668 10604dce 2021-09-24 thomas fi
669 10604dce 2021-09-24 thomas
670 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/content.expected
671 10604dce 2021-09-24 thomas cat $testroot/wt/alpha > $testroot/content
672 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
673 10604dce 2021-09-24 thomas ret="$?"
674 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
675 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
676 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
677 10604dce 2021-09-24 thomas return 1
678 10604dce 2021-09-24 thomas fi
679 10604dce 2021-09-24 thomas
680 10604dce 2021-09-24 thomas echo "beta" > $testroot/content.expected
681 10604dce 2021-09-24 thomas cat $testroot/wt/beta > $testroot/content
682 10604dce 2021-09-24 thomas cmp -s $testroot/content.expected $testroot/content
683 10604dce 2021-09-24 thomas ret="$?"
684 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
685 10604dce 2021-09-24 thomas diff -u $testroot/content.expected $testroot/content
686 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
687 10604dce 2021-09-24 thomas return 1
688 10604dce 2021-09-24 thomas fi
689 10604dce 2021-09-24 thomas
690 10604dce 2021-09-24 thomas if [ -e $testroot/wt/epsilon/new ]; then
691 10604dce 2021-09-24 thomas echo "reverted file epsilon/new still exists on disk" >&2
692 10604dce 2021-09-24 thomas test_done "$testroot" "1"
693 10604dce 2021-09-24 thomas return 1
694 10604dce 2021-09-24 thomas fi
695 10604dce 2021-09-24 thomas
696 10604dce 2021-09-24 thomas if [ -e $testroot/wt/symlink ]; then
697 10604dce 2021-09-24 thomas echo "reverted symlink still exists on disk" >&2
698 10604dce 2021-09-24 thomas test_done "$testroot" "1"
699 10604dce 2021-09-24 thomas return 1
700 10604dce 2021-09-24 thomas fi
701 10604dce 2021-09-24 thomas
702 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
703 10604dce 2021-09-24 thomas
704 10604dce 2021-09-24 thomas echo -n "" > $testroot/stdout.expected
705 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
706 10604dce 2021-09-24 thomas ret="$?"
707 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
708 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
709 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
710 10604dce 2021-09-24 thomas return 1
711 10604dce 2021-09-24 thomas fi
712 10604dce 2021-09-24 thomas
713 10604dce 2021-09-24 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
714 10604dce 2021-09-24 thomas echo "commit $master_commit (master)" > $testroot/stdout.expected
715 10604dce 2021-09-24 thomas echo "commit $commit0" >> $testroot/stdout.expected
716 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
717 10604dce 2021-09-24 thomas ret="$?"
718 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
719 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
720 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
721 10604dce 2021-09-24 thomas return 1
722 10604dce 2021-09-24 thomas fi
723 10604dce 2021-09-24 thomas
724 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > $testroot/stdout)
725 10604dce 2021-09-24 thomas
726 10604dce 2021-09-24 thomas echo 'Already up-to-date' > $testroot/stdout.expected
727 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
728 10604dce 2021-09-24 thomas ret="$?"
729 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
730 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
731 10604dce 2021-09-24 thomas fi
732 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
733 10604dce 2021-09-24 thomas }
734 10604dce 2021-09-24 thomas
735 10604dce 2021-09-24 thomas test_merge_in_progress() {
736 10604dce 2021-09-24 thomas local testroot=`test_init merge_in_progress`
737 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
738 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
739 10604dce 2021-09-24 thomas
740 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
741 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
742 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
743 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
744 10604dce 2021-09-24 thomas
745 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
746 10604dce 2021-09-24 thomas ret="$?"
747 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
748 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
749 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
750 10604dce 2021-09-24 thomas return 1
751 10604dce 2021-09-24 thomas fi
752 10604dce 2021-09-24 thomas
753 10604dce 2021-09-24 thomas # create a conflicting commit
754 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
755 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
756 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
757 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
758 10604dce 2021-09-24 thomas
759 10604dce 2021-09-24 thomas # need an up-to-date work tree for 'got merge'
760 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
761 10604dce 2021-09-24 thomas ret="$?"
762 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
763 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
764 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
765 10604dce 2021-09-24 thomas return 1
766 10604dce 2021-09-24 thomas fi
767 10604dce 2021-09-24 thomas
768 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
769 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
770 10604dce 2021-09-24 thomas ret="$?"
771 10604dce 2021-09-24 thomas if [ "$ret" == "0" ]; then
772 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
773 10604dce 2021-09-24 thomas test_done "$testroot" "1"
774 10604dce 2021-09-24 thomas return 1
775 10604dce 2021-09-24 thomas fi
776 10604dce 2021-09-24 thomas
777 10604dce 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
778 10604dce 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
779 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
780 10604dce 2021-09-24 thomas ret="$?"
781 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
782 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
783 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
784 10604dce 2021-09-24 thomas return 1
785 10604dce 2021-09-24 thomas fi
786 10604dce 2021-09-24 thomas
787 10604dce 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
788 10604dce 2021-09-24 thomas > $testroot/stderr.expected
789 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
790 10604dce 2021-09-24 thomas ret="$?"
791 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
792 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
793 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
794 10604dce 2021-09-24 thomas return 1
795 10604dce 2021-09-24 thomas fi
796 10604dce 2021-09-24 thomas
797 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
798 10604dce 2021-09-24 thomas
799 10604dce 2021-09-24 thomas echo "C alpha" > $testroot/stdout.expected
800 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
801 10604dce 2021-09-24 thomas ret="$?"
802 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
803 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
804 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
805 10604dce 2021-09-24 thomas return 1
806 10604dce 2021-09-24 thomas fi
807 10604dce 2021-09-24 thomas
808 10604dce 2021-09-24 thomas for cmd in update commit histedit "rebase newbranch" \
809 10604dce 2021-09-24 thomas "integrate newbranch" "stage alpha"; do
810 10604dce 2021-09-24 thomas (cd $testroot/wt && got $cmd > $testroot/stdout \
811 10604dce 2021-09-24 thomas 2> $testroot/stderr)
812 10604dce 2021-09-24 thomas
813 10604dce 2021-09-24 thomas echo -n > $testroot/stdout.expected
814 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
815 10604dce 2021-09-24 thomas ret="$?"
816 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
817 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
818 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
819 10604dce 2021-09-24 thomas return 1
820 10604dce 2021-09-24 thomas fi
821 10604dce 2021-09-24 thomas
822 10604dce 2021-09-24 thomas echo -n "got: a merge operation is in progress in this " \
823 10604dce 2021-09-24 thomas > $testroot/stderr.expected
824 10604dce 2021-09-24 thomas echo "work tree and must be continued or aborted first" \
825 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
826 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
827 10604dce 2021-09-24 thomas ret="$?"
828 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
829 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
830 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
831 10604dce 2021-09-24 thomas return 1
832 10604dce 2021-09-24 thomas fi
833 10604dce 2021-09-24 thomas done
834 10604dce 2021-09-24 thomas
835 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
836 10604dce 2021-09-24 thomas }
837 10604dce 2021-09-24 thomas
838 10604dce 2021-09-24 thomas test_merge_path_prefix() {
839 10604dce 2021-09-24 thomas local testroot=`test_init merge_path_prefix`
840 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
841 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
842 10604dce 2021-09-24 thomas
843 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
844 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
845 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
846 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
847 10604dce 2021-09-24 thomas
848 10604dce 2021-09-24 thomas got checkout -p epsilon -b master $testroot/repo $testroot/wt \
849 10604dce 2021-09-24 thomas > /dev/null
850 10604dce 2021-09-24 thomas ret="$?"
851 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
852 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
853 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
854 10604dce 2021-09-24 thomas return 1
855 10604dce 2021-09-24 thomas fi
856 10604dce 2021-09-24 thomas
857 10604dce 2021-09-24 thomas # create a conflicting commit
858 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
859 10604dce 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
860 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
861 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
862 10604dce 2021-09-24 thomas
863 10604dce 2021-09-24 thomas # need an up-to-date work tree for 'got merge'
864 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
865 10604dce 2021-09-24 thomas ret="$?"
866 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
867 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
868 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
869 10604dce 2021-09-24 thomas return 1
870 10604dce 2021-09-24 thomas fi
871 10604dce 2021-09-24 thomas
872 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
873 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
874 10604dce 2021-09-24 thomas ret="$?"
875 10604dce 2021-09-24 thomas if [ "$ret" == "0" ]; then
876 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
877 10604dce 2021-09-24 thomas test_done "$testroot" "1"
878 10604dce 2021-09-24 thomas return 1
879 10604dce 2021-09-24 thomas fi
880 10604dce 2021-09-24 thomas
881 10604dce 2021-09-24 thomas echo -n "got: cannot merge branch which contains changes outside " \
882 10604dce 2021-09-24 thomas > $testroot/stderr.expected
883 10604dce 2021-09-24 thomas echo "of this work tree's path prefix" >> $testroot/stderr.expected
884 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
885 10604dce 2021-09-24 thomas ret="$?"
886 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
887 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
888 10604dce 2021-09-24 thomas fi
889 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
890 10604dce 2021-09-24 thomas }
891 10604dce 2021-09-24 thomas
892 10604dce 2021-09-24 thomas test_merge_missing_file() {
893 10604dce 2021-09-24 thomas local testroot=`test_init merge_missing_file`
894 10604dce 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
895 10604dce 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
896 10604dce 2021-09-24 thomas
897 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
898 10604dce 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
899 10604dce 2021-09-24 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
900 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha and delta"
901 10604dce 2021-09-24 thomas local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
902 10604dce 2021-09-24 thomas
903 10604dce 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
904 10604dce 2021-09-24 thomas ret="$?"
905 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
906 10604dce 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
907 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
908 10604dce 2021-09-24 thomas return 1
909 10604dce 2021-09-24 thomas fi
910 10604dce 2021-09-24 thomas
911 10604dce 2021-09-24 thomas # create a conflicting commit which renames alpha
912 10604dce 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
913 10604dce 2021-09-24 thomas (cd $testroot/repo && git mv alpha epsilon/alpha-moved)
914 10604dce 2021-09-24 thomas git_commit $testroot/repo -m "moving alpha on master"
915 10604dce 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
916 10604dce 2021-09-24 thomas
917 10604dce 2021-09-24 thomas # need an up-to-date work tree for 'got merge'
918 10604dce 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
919 10604dce 2021-09-24 thomas ret="$?"
920 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
921 10604dce 2021-09-24 thomas echo "got update failed unexpectedly" >&2
922 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
923 10604dce 2021-09-24 thomas return 1
924 10604dce 2021-09-24 thomas fi
925 10604dce 2021-09-24 thomas
926 10604dce 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
927 10604dce 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
928 10604dce 2021-09-24 thomas ret="$?"
929 10604dce 2021-09-24 thomas if [ "$ret" == "0" ]; then
930 10604dce 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
931 10604dce 2021-09-24 thomas test_done "$testroot" "1"
932 10604dce 2021-09-24 thomas return 1
933 10604dce 2021-09-24 thomas fi
934 10604dce 2021-09-24 thomas
935 10604dce 2021-09-24 thomas echo "! alpha" > $testroot/stdout.expected
936 10604dce 2021-09-24 thomas echo "G gamma/delta" >> $testroot/stdout.expected
937 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
938 10604dce 2021-09-24 thomas ret="$?"
939 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
940 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
941 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
942 10604dce 2021-09-24 thomas return 1
943 10604dce 2021-09-24 thomas fi
944 10604dce 2021-09-24 thomas
945 88d249c2 2021-09-24 thomas echo -n "got: changes destined for missing files " \
946 10604dce 2021-09-24 thomas > $testroot/stderr.expected
947 10604dce 2021-09-24 thomas echo -n "were not yet merged and should be merged manually if " \
948 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
949 10604dce 2021-09-24 thomas echo "required before the merge operation is continued" \
950 10604dce 2021-09-24 thomas >> $testroot/stderr.expected
951 10604dce 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
952 10604dce 2021-09-24 thomas ret="$?"
953 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
954 10604dce 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
955 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
956 10604dce 2021-09-24 thomas return 1
957 10604dce 2021-09-24 thomas fi
958 10604dce 2021-09-24 thomas
959 10604dce 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
960 10604dce 2021-09-24 thomas
961 10604dce 2021-09-24 thomas echo "M gamma/delta" > $testroot/stdout.expected
962 2d7ce510 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
963 2d7ce510 2021-09-24 thomas ret="$?"
964 2d7ce510 2021-09-24 thomas if [ "$ret" != "0" ]; then
965 2d7ce510 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
966 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
967 2d7ce510 2021-09-24 thomas return 1
968 2d7ce510 2021-09-24 thomas fi
969 2d7ce510 2021-09-24 thomas
970 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
971 2d7ce510 2021-09-24 thomas }
972 2d7ce510 2021-09-24 thomas
973 2d7ce510 2021-09-24 thomas test_merge_no_op() {
974 2d7ce510 2021-09-24 thomas local testroot=`test_init merge_no_op`
975 2d7ce510 2021-09-24 thomas local commit0=`git_show_head $testroot/repo`
976 2d7ce510 2021-09-24 thomas local commit0_author_time=`git_show_author_time $testroot/repo`
977 2d7ce510 2021-09-24 thomas
978 2d7ce510 2021-09-24 thomas (cd $testroot/repo && git checkout -q -b newbranch)
979 2d7ce510 2021-09-24 thomas echo "modified alpha on branch" > $testroot/repo/alpha
980 2d7ce510 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on newbranch"
981 2d7ce510 2021-09-24 thomas local branch_commitk=`git_show_branch_head $testroot/repo newbranch`
982 2d7ce510 2021-09-24 thomas
983 2d7ce510 2021-09-24 thomas got checkout -b master $testroot/repo $testroot/wt > /dev/null
984 2d7ce510 2021-09-24 thomas ret="$?"
985 2d7ce510 2021-09-24 thomas if [ "$ret" != "0" ]; then
986 2d7ce510 2021-09-24 thomas echo "got checkout failed unexpectedly" >&2
987 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
988 2d7ce510 2021-09-24 thomas return 1
989 2d7ce510 2021-09-24 thomas fi
990 2d7ce510 2021-09-24 thomas
991 2d7ce510 2021-09-24 thomas # create a conflicting commit
992 2d7ce510 2021-09-24 thomas (cd $testroot/repo && git checkout -q master)
993 2d7ce510 2021-09-24 thomas echo "modified alpha on master" > $testroot/repo/alpha
994 2d7ce510 2021-09-24 thomas git_commit $testroot/repo -m "committing to alpha on master"
995 2d7ce510 2021-09-24 thomas local master_commit=`git_show_head $testroot/repo`
996 2d7ce510 2021-09-24 thomas
997 2d7ce510 2021-09-24 thomas # need an up-to-date work tree for 'got merge'
998 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got update > /dev/null)
999 2d7ce510 2021-09-24 thomas ret="$?"
1000 2d7ce510 2021-09-24 thomas if [ "$ret" != "0" ]; then
1001 2d7ce510 2021-09-24 thomas echo "got update failed unexpectedly" >&2
1002 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1003 2d7ce510 2021-09-24 thomas return 1
1004 2d7ce510 2021-09-24 thomas fi
1005 2d7ce510 2021-09-24 thomas
1006 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got merge newbranch \
1007 2d7ce510 2021-09-24 thomas > $testroot/stdout 2> $testroot/stderr)
1008 2d7ce510 2021-09-24 thomas ret="$?"
1009 2d7ce510 2021-09-24 thomas if [ "$ret" == "0" ]; then
1010 2d7ce510 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
1011 2d7ce510 2021-09-24 thomas test_done "$testroot" "1"
1012 2d7ce510 2021-09-24 thomas return 1
1013 2d7ce510 2021-09-24 thomas fi
1014 2d7ce510 2021-09-24 thomas
1015 2d7ce510 2021-09-24 thomas echo "C alpha" >> $testroot/stdout.expected
1016 2d7ce510 2021-09-24 thomas echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1017 2d7ce510 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1018 2d7ce510 2021-09-24 thomas ret="$?"
1019 2d7ce510 2021-09-24 thomas if [ "$ret" != "0" ]; then
1020 2d7ce510 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1021 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1022 2d7ce510 2021-09-24 thomas return 1
1023 2d7ce510 2021-09-24 thomas fi
1024 2d7ce510 2021-09-24 thomas
1025 2d7ce510 2021-09-24 thomas echo "got: conflicts must be resolved before merging can continue" \
1026 2d7ce510 2021-09-24 thomas > $testroot/stderr.expected
1027 2d7ce510 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1028 2d7ce510 2021-09-24 thomas ret="$?"
1029 2d7ce510 2021-09-24 thomas if [ "$ret" != "0" ]; then
1030 2d7ce510 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1031 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1032 2d7ce510 2021-09-24 thomas return 1
1033 2d7ce510 2021-09-24 thomas fi
1034 2d7ce510 2021-09-24 thomas
1035 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1036 2d7ce510 2021-09-24 thomas
1037 2d7ce510 2021-09-24 thomas echo "C alpha" > $testroot/stdout.expected
1038 10604dce 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1039 10604dce 2021-09-24 thomas ret="$?"
1040 10604dce 2021-09-24 thomas if [ "$ret" != "0" ]; then
1041 10604dce 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1042 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1043 10604dce 2021-09-24 thomas return 1
1044 10604dce 2021-09-24 thomas fi
1045 10604dce 2021-09-24 thomas
1046 2d7ce510 2021-09-24 thomas # resolve the conflict by reverting all changes; now it is no-op merge
1047 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got revert alpha > /dev/null)
1048 2d7ce510 2021-09-24 thomas ret="$?"
1049 2d7ce510 2021-09-24 thomas if [ "$ret" != "0" ]; then
1050 2d7ce510 2021-09-24 thomas echo "got revert failed unexpectedly" >&2
1051 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1052 2d7ce510 2021-09-24 thomas return 1
1053 2d7ce510 2021-09-24 thomas fi
1054 2d7ce510 2021-09-24 thomas
1055 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got merge -c > $testroot/stdout \
1056 2d7ce510 2021-09-24 thomas 2> $testroot/stderr)
1057 2d7ce510 2021-09-24 thomas ret="$?"
1058 2d7ce510 2021-09-24 thomas if [ "$ret" == "0" ]; then
1059 2d7ce510 2021-09-24 thomas echo "got merge succeeded unexpectedly" >&2
1060 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1061 2d7ce510 2021-09-24 thomas return 1
1062 2d7ce510 2021-09-24 thomas fi
1063 2d7ce510 2021-09-24 thomas
1064 2d7ce510 2021-09-24 thomas echo -n "got: merge of refs/heads/newbranch cannot proceed: " \
1065 2d7ce510 2021-09-24 thomas > $testroot/stderr.expected
1066 2d7ce510 2021-09-24 thomas echo "no changes to commit" >> $testroot/stderr.expected
1067 2d7ce510 2021-09-24 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1068 2d7ce510 2021-09-24 thomas ret="$?"
1069 2d7ce510 2021-09-24 thomas if [ "$ret" != "0" ]; then
1070 2d7ce510 2021-09-24 thomas diff -u $testroot/stderr.expected $testroot/stderr
1071 2d7ce510 2021-09-24 thomas test_done "$testroot" "$ret"
1072 2d7ce510 2021-09-24 thomas return 1
1073 2d7ce510 2021-09-24 thomas fi
1074 2d7ce510 2021-09-24 thomas
1075 2d7ce510 2021-09-24 thomas (cd $testroot/wt && got status > $testroot/stdout)
1076 2d7ce510 2021-09-24 thomas
1077 2d7ce510 2021-09-24 thomas echo -n "" > $testroot/stdout.expected
1078 2d7ce510 2021-09-24 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1079 2d7ce510 2021-09-24 thomas ret="$?"
1080 2d7ce510 2021-09-24 thomas if [ "$ret" != "0" ]; then
1081 2d7ce510 2021-09-24 thomas diff -u $testroot/stdout.expected $testroot/stdout
1082 2d7ce510 2021-09-24 thomas fi
1083 10604dce 2021-09-24 thomas test_done "$testroot" "$ret"
1084 10604dce 2021-09-24 thomas }
1085 10604dce 2021-09-24 thomas
1086 10604dce 2021-09-24 thomas test_parseargs "$@"
1087 10604dce 2021-09-24 thomas run_test test_merge_basic
1088 10604dce 2021-09-24 thomas run_test test_merge_continue
1089 10604dce 2021-09-24 thomas run_test test_merge_abort
1090 10604dce 2021-09-24 thomas run_test test_merge_in_progress
1091 10604dce 2021-09-24 thomas run_test test_merge_path_prefix
1092 10604dce 2021-09-24 thomas run_test test_merge_missing_file
1093 2d7ce510 2021-09-24 thomas run_test test_merge_no_op