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