Blame


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