Blame


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