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 f259c4c1 2021-09-24 stsp ret="$?"
49 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 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 f259c4c1 2021-09-24 stsp ret="$?"
59 f259c4c1 2021-09-24 stsp if [ "$ret" == "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 f259c4c1 2021-09-24 stsp ret="$?"
73 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 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 f259c4c1 2021-09-24 stsp ret="$?"
89 f259c4c1 2021-09-24 stsp if [ "$ret" == "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 f259c4c1 2021-09-24 stsp ret="$?"
99 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 stsp ret="$?"
107 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 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 f259c4c1 2021-09-24 stsp ret="$?"
116 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 stsp ret="$?"
124 f259c4c1 2021-09-24 stsp if [ "$ret" == "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 f259c4c1 2021-09-24 stsp ret="$?"
135 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 stsp ret="$?"
143 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 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 f259c4c1 2021-09-24 stsp ret="$?"
153 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 stsp ret="$?"
161 f259c4c1 2021-09-24 stsp if [ "$ret" == "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 f259c4c1 2021-09-24 stsp ret="$?"
169 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 stsp ret="$?"
176 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 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 f259c4c1 2021-09-24 stsp ret="$?"
186 f259c4c1 2021-09-24 stsp if [ "$ret" == "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 f259c4c1 2021-09-24 stsp ret="$?"
197 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 stsp ret="$?"
205 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 stsp ret="$?"
213 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 stsp ret="$?"
233 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 stsp ret="$?"
243 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 stsp ret="$?"
253 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 stsp ret="$?"
269 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 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 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 f259c4c1 2021-09-24 stsp ret="$?"
296 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 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 (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 f259c4c1 2021-09-24 stsp ret="$?"
322 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 5267b9e4 2021-09-26 stsp ret="$?"
341 5267b9e4 2021-09-26 stsp if [ "$ret" != "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 5267b9e4 2021-09-26 stsp ret="$?"
349 5267b9e4 2021-09-26 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 stsp ret="$?"
368 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 stsp ret="$?"
397 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 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 f259c4c1 2021-09-24 stsp ret="$?"
412 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 stsp ret="$?"
421 f259c4c1 2021-09-24 stsp if [ "$ret" == "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 f259c4c1 2021-09-24 stsp ret="$?"
434 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 stsp ret="$?"
444 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 stsp ret="$?"
458 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 stsp ret="$?"
476 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 stsp ret="$?"
487 f259c4c1 2021-09-24 stsp if [ "$ret" != "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 f259c4c1 2021-09-24 stsp echo -n "Merged refs/heads/newbranch into refs/heads/master: " \
496 f259c4c1 2021-09-24 stsp > $testroot/stdout.expected
497 f259c4c1 2021-09-24 stsp echo $merge_commit >> $testroot/stdout.expected
498 f259c4c1 2021-09-24 stsp
499 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
500 f259c4c1 2021-09-24 stsp ret="$?"
501 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
502 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
503 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
504 f259c4c1 2021-09-24 stsp return 1
505 f259c4c1 2021-09-24 stsp fi
506 f259c4c1 2021-09-24 stsp
507 f259c4c1 2021-09-24 stsp echo "modified delta on branch" > $testroot/content.expected
508 f259c4c1 2021-09-24 stsp cat $testroot/wt/gamma/delta > $testroot/content
509 f259c4c1 2021-09-24 stsp cmp -s $testroot/content.expected $testroot/content
510 f259c4c1 2021-09-24 stsp ret="$?"
511 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
512 f259c4c1 2021-09-24 stsp diff -u $testroot/content.expected $testroot/content
513 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
514 f259c4c1 2021-09-24 stsp return 1
515 f259c4c1 2021-09-24 stsp fi
516 f259c4c1 2021-09-24 stsp
517 f259c4c1 2021-09-24 stsp echo "modified alpha by both branches" > $testroot/content.expected
518 f259c4c1 2021-09-24 stsp cat $testroot/wt/alpha > $testroot/content
519 f259c4c1 2021-09-24 stsp cmp -s $testroot/content.expected $testroot/content
520 f259c4c1 2021-09-24 stsp ret="$?"
521 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
522 f259c4c1 2021-09-24 stsp diff -u $testroot/content.expected $testroot/content
523 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
524 f259c4c1 2021-09-24 stsp return 1
525 f259c4c1 2021-09-24 stsp fi
526 f259c4c1 2021-09-24 stsp
527 f259c4c1 2021-09-24 stsp if [ -e $testroot/wt/beta ]; then
528 f259c4c1 2021-09-24 stsp echo "removed file beta still exists on disk" >&2
529 f259c4c1 2021-09-24 stsp test_done "$testroot" "1"
530 f259c4c1 2021-09-24 stsp return 1
531 f259c4c1 2021-09-24 stsp fi
532 f259c4c1 2021-09-24 stsp
533 f259c4c1 2021-09-24 stsp echo "new file on branch" > $testroot/content.expected
534 f259c4c1 2021-09-24 stsp cat $testroot/wt/epsilon/new > $testroot/content
535 f259c4c1 2021-09-24 stsp cmp -s $testroot/content.expected $testroot/content
536 f259c4c1 2021-09-24 stsp ret="$?"
537 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
538 f259c4c1 2021-09-24 stsp diff -u $testroot/content.expected $testroot/content
539 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
540 f259c4c1 2021-09-24 stsp return 1
541 f259c4c1 2021-09-24 stsp fi
542 f259c4c1 2021-09-24 stsp
543 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
544 f259c4c1 2021-09-24 stsp
545 f259c4c1 2021-09-24 stsp echo -n > $testroot/stdout.expected
546 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
547 f259c4c1 2021-09-24 stsp ret="$?"
548 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
549 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
550 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
551 f259c4c1 2021-09-24 stsp return 1
552 f259c4c1 2021-09-24 stsp fi
553 f259c4c1 2021-09-24 stsp
554 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
555 f259c4c1 2021-09-24 stsp echo "commit $merge_commit (master)" > $testroot/stdout.expected
556 f259c4c1 2021-09-24 stsp echo "commit $master_commit" >> $testroot/stdout.expected
557 f259c4c1 2021-09-24 stsp echo "commit $commit0" >> $testroot/stdout.expected
558 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
559 f259c4c1 2021-09-24 stsp ret="$?"
560 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
561 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
562 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
563 f259c4c1 2021-09-24 stsp return 1
564 f259c4c1 2021-09-24 stsp fi
565 f259c4c1 2021-09-24 stsp
566 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got update > $testroot/stdout)
567 f259c4c1 2021-09-24 stsp
568 f259c4c1 2021-09-24 stsp echo 'Already up-to-date' > $testroot/stdout.expected
569 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
570 f259c4c1 2021-09-24 stsp ret="$?"
571 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
572 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
573 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
574 f259c4c1 2021-09-24 stsp return 1
575 f259c4c1 2021-09-24 stsp fi
576 f259c4c1 2021-09-24 stsp
577 f259c4c1 2021-09-24 stsp # We should have created a merge commit with two parents.
578 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got log -l1 | grep ^parent > $testroot/stdout)
579 f259c4c1 2021-09-24 stsp echo "parent 1: $master_commit" > $testroot/stdout.expected
580 f259c4c1 2021-09-24 stsp echo "parent 2: $branch_commit3" >> $testroot/stdout.expected
581 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
582 f259c4c1 2021-09-24 stsp ret="$?"
583 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
584 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
585 f259c4c1 2021-09-24 stsp fi
586 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
587 f259c4c1 2021-09-24 stsp }
588 f259c4c1 2021-09-24 stsp
589 f259c4c1 2021-09-24 stsp test_merge_abort() {
590 f259c4c1 2021-09-24 stsp local testroot=`test_init merge_abort`
591 f259c4c1 2021-09-24 stsp local commit0=`git_show_head $testroot/repo`
592 f259c4c1 2021-09-24 stsp local commit0_author_time=`git_show_author_time $testroot/repo`
593 f259c4c1 2021-09-24 stsp
594 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git checkout -q -b newbranch)
595 f259c4c1 2021-09-24 stsp echo "modified delta on branch" > $testroot/repo/gamma/delta
596 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "committing to delta on newbranch"
597 f259c4c1 2021-09-24 stsp local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
598 f259c4c1 2021-09-24 stsp
599 f259c4c1 2021-09-24 stsp echo "modified alpha on branch" > $testroot/repo/alpha
600 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "committing to alpha on newbranch"
601 f259c4c1 2021-09-24 stsp local branch_commit1=`git_show_branch_head $testroot/repo newbranch`
602 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git rm -q beta)
603 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "removing beta on newbranch"
604 f259c4c1 2021-09-24 stsp local branch_commit2=`git_show_branch_head $testroot/repo newbranch`
605 f259c4c1 2021-09-24 stsp echo "new file on branch" > $testroot/repo/epsilon/new
606 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git add epsilon/new)
607 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "adding new file on newbranch"
608 f259c4c1 2021-09-24 stsp local branch_commit3=`git_show_branch_head $testroot/repo newbranch`
609 f259c4c1 2021-09-24 stsp (cd $testroot/repo && ln -s alpha symlink && git add symlink)
610 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "adding symlink on newbranch"
611 f259c4c1 2021-09-24 stsp local branch_commit4=`git_show_branch_head $testroot/repo newbranch`
612 f259c4c1 2021-09-24 stsp
613 f259c4c1 2021-09-24 stsp got checkout -b master $testroot/repo $testroot/wt > /dev/null
614 f259c4c1 2021-09-24 stsp ret="$?"
615 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
616 f259c4c1 2021-09-24 stsp echo "got checkout failed unexpectedly" >&2
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 # create a conflicting commit
622 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git checkout -q master)
623 f259c4c1 2021-09-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
624 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "committing to alpha on master"
625 f259c4c1 2021-09-24 stsp local master_commit=`git_show_head $testroot/repo`
626 f259c4c1 2021-09-24 stsp
627 f259c4c1 2021-09-24 stsp # need an up-to-date work tree for 'got merge'
628 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got update > /dev/null)
629 f259c4c1 2021-09-24 stsp ret="$?"
630 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
631 f259c4c1 2021-09-24 stsp echo "got update failed unexpectedly" >&2
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 newbranch \
637 f259c4c1 2021-09-24 stsp > $testroot/stdout 2> $testroot/stderr)
638 f259c4c1 2021-09-24 stsp ret="$?"
639 f259c4c1 2021-09-24 stsp if [ "$ret" == "0" ]; then
640 f259c4c1 2021-09-24 stsp echo "got merge succeeded unexpectedly" >&2
641 f259c4c1 2021-09-24 stsp test_done "$testroot" "1"
642 f259c4c1 2021-09-24 stsp return 1
643 f259c4c1 2021-09-24 stsp fi
644 f259c4c1 2021-09-24 stsp
645 f259c4c1 2021-09-24 stsp echo "C alpha" >> $testroot/stdout.expected
646 f259c4c1 2021-09-24 stsp echo "D beta" >> $testroot/stdout.expected
647 f259c4c1 2021-09-24 stsp echo "A epsilon/new" >> $testroot/stdout.expected
648 f259c4c1 2021-09-24 stsp echo "G gamma/delta" >> $testroot/stdout.expected
649 f259c4c1 2021-09-24 stsp echo "A symlink" >> $testroot/stdout.expected
650 f259c4c1 2021-09-24 stsp echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
651 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
652 f259c4c1 2021-09-24 stsp ret="$?"
653 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
654 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
655 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
656 f259c4c1 2021-09-24 stsp return 1
657 f259c4c1 2021-09-24 stsp fi
658 f259c4c1 2021-09-24 stsp
659 f259c4c1 2021-09-24 stsp echo "got: conflicts must be resolved before merging can continue" \
660 f259c4c1 2021-09-24 stsp > $testroot/stderr.expected
661 f259c4c1 2021-09-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
662 f259c4c1 2021-09-24 stsp ret="$?"
663 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
664 f259c4c1 2021-09-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
665 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
666 f259c4c1 2021-09-24 stsp return 1
667 f259c4c1 2021-09-24 stsp fi
668 f259c4c1 2021-09-24 stsp
669 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
670 f259c4c1 2021-09-24 stsp
671 f259c4c1 2021-09-24 stsp echo "C alpha" > $testroot/stdout.expected
672 f259c4c1 2021-09-24 stsp echo "D beta" >> $testroot/stdout.expected
673 f259c4c1 2021-09-24 stsp echo "A epsilon/new" >> $testroot/stdout.expected
674 f259c4c1 2021-09-24 stsp echo "M gamma/delta" >> $testroot/stdout.expected
675 f259c4c1 2021-09-24 stsp echo "A symlink" >> $testroot/stdout.expected
676 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
677 f259c4c1 2021-09-24 stsp ret="$?"
678 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
679 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
680 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
681 f259c4c1 2021-09-24 stsp return 1
682 f259c4c1 2021-09-24 stsp fi
683 f259c4c1 2021-09-24 stsp
684 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got merge -a > $testroot/stdout)
685 f259c4c1 2021-09-24 stsp ret="$?"
686 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
687 f259c4c1 2021-09-24 stsp echo "got merge failed unexpectedly" >&2
688 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
689 f259c4c1 2021-09-24 stsp return 1
690 f259c4c1 2021-09-24 stsp fi
691 f259c4c1 2021-09-24 stsp
692 f259c4c1 2021-09-24 stsp echo "R alpha" > $testroot/stdout.expected
693 f259c4c1 2021-09-24 stsp echo "R beta" >> $testroot/stdout.expected
694 f259c4c1 2021-09-24 stsp echo "R epsilon/new" >> $testroot/stdout.expected
695 f259c4c1 2021-09-24 stsp echo "R gamma/delta" >> $testroot/stdout.expected
696 f259c4c1 2021-09-24 stsp echo "R symlink" >> $testroot/stdout.expected
697 f259c4c1 2021-09-24 stsp echo "Merge of refs/heads/newbranch aborted" \
698 f259c4c1 2021-09-24 stsp >> $testroot/stdout.expected
699 f259c4c1 2021-09-24 stsp
700 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
701 f259c4c1 2021-09-24 stsp ret="$?"
702 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
703 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
704 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
705 f259c4c1 2021-09-24 stsp return 1
706 f259c4c1 2021-09-24 stsp fi
707 f259c4c1 2021-09-24 stsp
708 f259c4c1 2021-09-24 stsp echo "delta" > $testroot/content.expected
709 f259c4c1 2021-09-24 stsp cat $testroot/wt/gamma/delta > $testroot/content
710 f259c4c1 2021-09-24 stsp cmp -s $testroot/content.expected $testroot/content
711 f259c4c1 2021-09-24 stsp ret="$?"
712 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
713 f259c4c1 2021-09-24 stsp diff -u $testroot/content.expected $testroot/content
714 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
715 f259c4c1 2021-09-24 stsp return 1
716 f259c4c1 2021-09-24 stsp fi
717 f259c4c1 2021-09-24 stsp
718 f259c4c1 2021-09-24 stsp echo "modified alpha on master" > $testroot/content.expected
719 f259c4c1 2021-09-24 stsp cat $testroot/wt/alpha > $testroot/content
720 f259c4c1 2021-09-24 stsp cmp -s $testroot/content.expected $testroot/content
721 f259c4c1 2021-09-24 stsp ret="$?"
722 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
723 f259c4c1 2021-09-24 stsp diff -u $testroot/content.expected $testroot/content
724 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
725 f259c4c1 2021-09-24 stsp return 1
726 f259c4c1 2021-09-24 stsp fi
727 f259c4c1 2021-09-24 stsp
728 f259c4c1 2021-09-24 stsp echo "beta" > $testroot/content.expected
729 f259c4c1 2021-09-24 stsp cat $testroot/wt/beta > $testroot/content
730 f259c4c1 2021-09-24 stsp cmp -s $testroot/content.expected $testroot/content
731 f259c4c1 2021-09-24 stsp ret="$?"
732 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
733 f259c4c1 2021-09-24 stsp diff -u $testroot/content.expected $testroot/content
734 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
735 f259c4c1 2021-09-24 stsp return 1
736 f259c4c1 2021-09-24 stsp fi
737 f259c4c1 2021-09-24 stsp
738 f259c4c1 2021-09-24 stsp if [ -e $testroot/wt/epsilon/new ]; then
739 f259c4c1 2021-09-24 stsp echo "reverted file epsilon/new still exists on disk" >&2
740 f259c4c1 2021-09-24 stsp test_done "$testroot" "1"
741 f259c4c1 2021-09-24 stsp return 1
742 f259c4c1 2021-09-24 stsp fi
743 f259c4c1 2021-09-24 stsp
744 f259c4c1 2021-09-24 stsp if [ -e $testroot/wt/symlink ]; then
745 f259c4c1 2021-09-24 stsp echo "reverted symlink still exists on disk" >&2
746 f259c4c1 2021-09-24 stsp test_done "$testroot" "1"
747 f259c4c1 2021-09-24 stsp return 1
748 f259c4c1 2021-09-24 stsp fi
749 f259c4c1 2021-09-24 stsp
750 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
751 f259c4c1 2021-09-24 stsp
752 f259c4c1 2021-09-24 stsp echo -n "" > $testroot/stdout.expected
753 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
754 f259c4c1 2021-09-24 stsp ret="$?"
755 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
756 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
757 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
758 f259c4c1 2021-09-24 stsp return 1
759 f259c4c1 2021-09-24 stsp fi
760 f259c4c1 2021-09-24 stsp
761 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
762 f259c4c1 2021-09-24 stsp echo "commit $master_commit (master)" > $testroot/stdout.expected
763 f259c4c1 2021-09-24 stsp echo "commit $commit0" >> $testroot/stdout.expected
764 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
765 f259c4c1 2021-09-24 stsp ret="$?"
766 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
767 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
768 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
769 f259c4c1 2021-09-24 stsp return 1
770 f259c4c1 2021-09-24 stsp fi
771 f259c4c1 2021-09-24 stsp
772 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got update > $testroot/stdout)
773 f259c4c1 2021-09-24 stsp
774 f259c4c1 2021-09-24 stsp echo 'Already up-to-date' > $testroot/stdout.expected
775 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
776 f259c4c1 2021-09-24 stsp ret="$?"
777 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
778 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
779 f259c4c1 2021-09-24 stsp fi
780 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
781 f259c4c1 2021-09-24 stsp }
782 f259c4c1 2021-09-24 stsp
783 f259c4c1 2021-09-24 stsp test_merge_in_progress() {
784 f259c4c1 2021-09-24 stsp local testroot=`test_init merge_in_progress`
785 f259c4c1 2021-09-24 stsp local commit0=`git_show_head $testroot/repo`
786 f259c4c1 2021-09-24 stsp local commit0_author_time=`git_show_author_time $testroot/repo`
787 f259c4c1 2021-09-24 stsp
788 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git checkout -q -b newbranch)
789 f259c4c1 2021-09-24 stsp echo "modified alpha on branch" > $testroot/repo/alpha
790 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "committing to alpha on newbranch"
791 f259c4c1 2021-09-24 stsp local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
792 f259c4c1 2021-09-24 stsp
793 f259c4c1 2021-09-24 stsp got checkout -b master $testroot/repo $testroot/wt > /dev/null
794 f259c4c1 2021-09-24 stsp ret="$?"
795 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
796 f259c4c1 2021-09-24 stsp echo "got checkout failed unexpectedly" >&2
797 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
798 f259c4c1 2021-09-24 stsp return 1
799 f259c4c1 2021-09-24 stsp fi
800 f259c4c1 2021-09-24 stsp
801 f259c4c1 2021-09-24 stsp # create a conflicting commit
802 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git checkout -q master)
803 f259c4c1 2021-09-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
804 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "committing to alpha on master"
805 f259c4c1 2021-09-24 stsp local master_commit=`git_show_head $testroot/repo`
806 f259c4c1 2021-09-24 stsp
807 f259c4c1 2021-09-24 stsp # need an up-to-date work tree for 'got merge'
808 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got update > /dev/null)
809 f259c4c1 2021-09-24 stsp ret="$?"
810 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
811 f259c4c1 2021-09-24 stsp echo "got update failed unexpectedly" >&2
812 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
813 f259c4c1 2021-09-24 stsp return 1
814 f259c4c1 2021-09-24 stsp fi
815 f259c4c1 2021-09-24 stsp
816 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got merge newbranch \
817 f259c4c1 2021-09-24 stsp > $testroot/stdout 2> $testroot/stderr)
818 f259c4c1 2021-09-24 stsp ret="$?"
819 f259c4c1 2021-09-24 stsp if [ "$ret" == "0" ]; then
820 f259c4c1 2021-09-24 stsp echo "got merge succeeded unexpectedly" >&2
821 f259c4c1 2021-09-24 stsp test_done "$testroot" "1"
822 f259c4c1 2021-09-24 stsp return 1
823 f259c4c1 2021-09-24 stsp fi
824 f259c4c1 2021-09-24 stsp
825 f259c4c1 2021-09-24 stsp echo "C alpha" >> $testroot/stdout.expected
826 f259c4c1 2021-09-24 stsp echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
827 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
828 f259c4c1 2021-09-24 stsp ret="$?"
829 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
830 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
831 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
832 f259c4c1 2021-09-24 stsp return 1
833 f259c4c1 2021-09-24 stsp fi
834 f259c4c1 2021-09-24 stsp
835 f259c4c1 2021-09-24 stsp echo "got: conflicts must be resolved before merging can continue" \
836 f259c4c1 2021-09-24 stsp > $testroot/stderr.expected
837 f259c4c1 2021-09-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
838 f259c4c1 2021-09-24 stsp ret="$?"
839 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
840 f259c4c1 2021-09-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
841 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
842 f259c4c1 2021-09-24 stsp return 1
843 f259c4c1 2021-09-24 stsp fi
844 f259c4c1 2021-09-24 stsp
845 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
846 f259c4c1 2021-09-24 stsp
847 f259c4c1 2021-09-24 stsp echo "C alpha" > $testroot/stdout.expected
848 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
849 f259c4c1 2021-09-24 stsp ret="$?"
850 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
851 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
852 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
853 f259c4c1 2021-09-24 stsp return 1
854 f259c4c1 2021-09-24 stsp fi
855 f259c4c1 2021-09-24 stsp
856 f259c4c1 2021-09-24 stsp for cmd in update commit histedit "rebase newbranch" \
857 f259c4c1 2021-09-24 stsp "integrate newbranch" "stage alpha"; do
858 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got $cmd > $testroot/stdout \
859 f259c4c1 2021-09-24 stsp 2> $testroot/stderr)
860 f259c4c1 2021-09-24 stsp
861 f259c4c1 2021-09-24 stsp echo -n > $testroot/stdout.expected
862 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
863 f259c4c1 2021-09-24 stsp ret="$?"
864 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
865 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
866 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
867 f259c4c1 2021-09-24 stsp return 1
868 f259c4c1 2021-09-24 stsp fi
869 f259c4c1 2021-09-24 stsp
870 f259c4c1 2021-09-24 stsp echo -n "got: a merge operation is in progress in this " \
871 f259c4c1 2021-09-24 stsp > $testroot/stderr.expected
872 f259c4c1 2021-09-24 stsp echo "work tree and must be continued or aborted first" \
873 f259c4c1 2021-09-24 stsp >> $testroot/stderr.expected
874 f259c4c1 2021-09-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
875 f259c4c1 2021-09-24 stsp ret="$?"
876 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
877 f259c4c1 2021-09-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
878 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
879 f259c4c1 2021-09-24 stsp return 1
880 f259c4c1 2021-09-24 stsp fi
881 f259c4c1 2021-09-24 stsp done
882 f259c4c1 2021-09-24 stsp
883 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
884 f259c4c1 2021-09-24 stsp }
885 f259c4c1 2021-09-24 stsp
886 f259c4c1 2021-09-24 stsp test_merge_path_prefix() {
887 f259c4c1 2021-09-24 stsp local testroot=`test_init merge_path_prefix`
888 f259c4c1 2021-09-24 stsp local commit0=`git_show_head $testroot/repo`
889 f259c4c1 2021-09-24 stsp local commit0_author_time=`git_show_author_time $testroot/repo`
890 f259c4c1 2021-09-24 stsp
891 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git checkout -q -b newbranch)
892 f259c4c1 2021-09-24 stsp echo "modified alpha on branch" > $testroot/repo/alpha
893 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "committing to alpha on newbranch"
894 f259c4c1 2021-09-24 stsp local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
895 f259c4c1 2021-09-24 stsp
896 f259c4c1 2021-09-24 stsp got checkout -p epsilon -b master $testroot/repo $testroot/wt \
897 f259c4c1 2021-09-24 stsp > /dev/null
898 f259c4c1 2021-09-24 stsp ret="$?"
899 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
900 f259c4c1 2021-09-24 stsp echo "got checkout failed unexpectedly" >&2
901 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
902 f259c4c1 2021-09-24 stsp return 1
903 f259c4c1 2021-09-24 stsp fi
904 f259c4c1 2021-09-24 stsp
905 f259c4c1 2021-09-24 stsp # create a conflicting commit
906 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git checkout -q master)
907 f259c4c1 2021-09-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
908 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "committing to alpha on master"
909 f259c4c1 2021-09-24 stsp local master_commit=`git_show_head $testroot/repo`
910 f259c4c1 2021-09-24 stsp
911 f259c4c1 2021-09-24 stsp # need an up-to-date work tree for 'got merge'
912 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got update > /dev/null)
913 f259c4c1 2021-09-24 stsp ret="$?"
914 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
915 f259c4c1 2021-09-24 stsp echo "got update failed unexpectedly" >&2
916 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
917 f259c4c1 2021-09-24 stsp return 1
918 f259c4c1 2021-09-24 stsp fi
919 f259c4c1 2021-09-24 stsp
920 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got merge newbranch \
921 f259c4c1 2021-09-24 stsp > $testroot/stdout 2> $testroot/stderr)
922 f259c4c1 2021-09-24 stsp ret="$?"
923 f259c4c1 2021-09-24 stsp if [ "$ret" == "0" ]; then
924 f259c4c1 2021-09-24 stsp echo "got merge succeeded unexpectedly" >&2
925 f259c4c1 2021-09-24 stsp test_done "$testroot" "1"
926 f259c4c1 2021-09-24 stsp return 1
927 f259c4c1 2021-09-24 stsp fi
928 f259c4c1 2021-09-24 stsp
929 f259c4c1 2021-09-24 stsp echo -n "got: cannot merge branch which contains changes outside " \
930 f259c4c1 2021-09-24 stsp > $testroot/stderr.expected
931 f259c4c1 2021-09-24 stsp echo "of this work tree's path prefix" >> $testroot/stderr.expected
932 f259c4c1 2021-09-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
933 f259c4c1 2021-09-24 stsp ret="$?"
934 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
935 f259c4c1 2021-09-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
936 f259c4c1 2021-09-24 stsp fi
937 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
938 f259c4c1 2021-09-24 stsp }
939 f259c4c1 2021-09-24 stsp
940 f259c4c1 2021-09-24 stsp test_merge_missing_file() {
941 f259c4c1 2021-09-24 stsp local testroot=`test_init merge_missing_file`
942 f259c4c1 2021-09-24 stsp local commit0=`git_show_head $testroot/repo`
943 f259c4c1 2021-09-24 stsp local commit0_author_time=`git_show_author_time $testroot/repo`
944 f259c4c1 2021-09-24 stsp
945 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git checkout -q -b newbranch)
946 f259c4c1 2021-09-24 stsp echo "modified alpha on branch" > $testroot/repo/alpha
947 f259c4c1 2021-09-24 stsp echo "modified delta on branch" > $testroot/repo/gamma/delta
948 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "committing to alpha and delta"
949 f259c4c1 2021-09-24 stsp local branch_commit0=`git_show_branch_head $testroot/repo newbranch`
950 f259c4c1 2021-09-24 stsp
951 f259c4c1 2021-09-24 stsp got checkout -b master $testroot/repo $testroot/wt > /dev/null
952 f259c4c1 2021-09-24 stsp ret="$?"
953 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
954 f259c4c1 2021-09-24 stsp echo "got checkout failed unexpectedly" >&2
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 # create a conflicting commit which renames alpha
960 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git checkout -q master)
961 f259c4c1 2021-09-24 stsp (cd $testroot/repo && git mv alpha epsilon/alpha-moved)
962 f259c4c1 2021-09-24 stsp git_commit $testroot/repo -m "moving alpha on master"
963 f259c4c1 2021-09-24 stsp local master_commit=`git_show_head $testroot/repo`
964 f259c4c1 2021-09-24 stsp
965 f259c4c1 2021-09-24 stsp # need an up-to-date work tree for 'got merge'
966 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got update > /dev/null)
967 f259c4c1 2021-09-24 stsp ret="$?"
968 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
969 f259c4c1 2021-09-24 stsp echo "got update failed unexpectedly" >&2
970 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
971 f259c4c1 2021-09-24 stsp return 1
972 f259c4c1 2021-09-24 stsp fi
973 f259c4c1 2021-09-24 stsp
974 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got merge newbranch \
975 f259c4c1 2021-09-24 stsp > $testroot/stdout 2> $testroot/stderr)
976 f259c4c1 2021-09-24 stsp ret="$?"
977 f259c4c1 2021-09-24 stsp if [ "$ret" == "0" ]; then
978 f259c4c1 2021-09-24 stsp echo "got merge succeeded unexpectedly" >&2
979 f259c4c1 2021-09-24 stsp test_done "$testroot" "1"
980 f259c4c1 2021-09-24 stsp return 1
981 f259c4c1 2021-09-24 stsp fi
982 f259c4c1 2021-09-24 stsp
983 f259c4c1 2021-09-24 stsp echo "! alpha" > $testroot/stdout.expected
984 f259c4c1 2021-09-24 stsp echo "G gamma/delta" >> $testroot/stdout.expected
985 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
986 f259c4c1 2021-09-24 stsp ret="$?"
987 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
988 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
989 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
990 f259c4c1 2021-09-24 stsp return 1
991 f259c4c1 2021-09-24 stsp fi
992 f259c4c1 2021-09-24 stsp
993 1acd48bc 2021-09-24 stsp echo -n "got: changes destined for missing files " \
994 f259c4c1 2021-09-24 stsp > $testroot/stderr.expected
995 f259c4c1 2021-09-24 stsp echo -n "were not yet merged and should be merged manually if " \
996 f259c4c1 2021-09-24 stsp >> $testroot/stderr.expected
997 f259c4c1 2021-09-24 stsp echo "required before the merge operation is continued" \
998 f259c4c1 2021-09-24 stsp >> $testroot/stderr.expected
999 f259c4c1 2021-09-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
1000 f259c4c1 2021-09-24 stsp ret="$?"
1001 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
1002 f259c4c1 2021-09-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
1003 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
1004 f259c4c1 2021-09-24 stsp return 1
1005 f259c4c1 2021-09-24 stsp fi
1006 f259c4c1 2021-09-24 stsp
1007 f259c4c1 2021-09-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
1008 f259c4c1 2021-09-24 stsp
1009 f259c4c1 2021-09-24 stsp echo "M gamma/delta" > $testroot/stdout.expected
1010 a6a8f8bb 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1011 a6a8f8bb 2021-09-24 stsp ret="$?"
1012 a6a8f8bb 2021-09-24 stsp if [ "$ret" != "0" ]; then
1013 a6a8f8bb 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
1014 a6a8f8bb 2021-09-24 stsp test_done "$testroot" "$ret"
1015 a6a8f8bb 2021-09-24 stsp return 1
1016 a6a8f8bb 2021-09-24 stsp fi
1017 a6a8f8bb 2021-09-24 stsp
1018 a6a8f8bb 2021-09-24 stsp test_done "$testroot" "$ret"
1019 a6a8f8bb 2021-09-24 stsp }
1020 a6a8f8bb 2021-09-24 stsp
1021 a6a8f8bb 2021-09-24 stsp test_merge_no_op() {
1022 a6a8f8bb 2021-09-24 stsp local testroot=`test_init merge_no_op`
1023 a6a8f8bb 2021-09-24 stsp local commit0=`git_show_head $testroot/repo`
1024 a6a8f8bb 2021-09-24 stsp local commit0_author_time=`git_show_author_time $testroot/repo`
1025 a6a8f8bb 2021-09-24 stsp
1026 a6a8f8bb 2021-09-24 stsp (cd $testroot/repo && git checkout -q -b newbranch)
1027 a6a8f8bb 2021-09-24 stsp echo "modified alpha on branch" > $testroot/repo/alpha
1028 a6a8f8bb 2021-09-24 stsp git_commit $testroot/repo -m "committing to alpha on newbranch"
1029 a6a8f8bb 2021-09-24 stsp local branch_commitk=`git_show_branch_head $testroot/repo newbranch`
1030 a6a8f8bb 2021-09-24 stsp
1031 a6a8f8bb 2021-09-24 stsp got checkout -b master $testroot/repo $testroot/wt > /dev/null
1032 a6a8f8bb 2021-09-24 stsp ret="$?"
1033 a6a8f8bb 2021-09-24 stsp if [ "$ret" != "0" ]; then
1034 a6a8f8bb 2021-09-24 stsp echo "got checkout failed unexpectedly" >&2
1035 a6a8f8bb 2021-09-24 stsp test_done "$testroot" "$ret"
1036 a6a8f8bb 2021-09-24 stsp return 1
1037 a6a8f8bb 2021-09-24 stsp fi
1038 a6a8f8bb 2021-09-24 stsp
1039 a6a8f8bb 2021-09-24 stsp # create a conflicting commit
1040 a6a8f8bb 2021-09-24 stsp (cd $testroot/repo && git checkout -q master)
1041 a6a8f8bb 2021-09-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
1042 a6a8f8bb 2021-09-24 stsp git_commit $testroot/repo -m "committing to alpha on master"
1043 a6a8f8bb 2021-09-24 stsp local master_commit=`git_show_head $testroot/repo`
1044 a6a8f8bb 2021-09-24 stsp
1045 a6a8f8bb 2021-09-24 stsp # need an up-to-date work tree for 'got merge'
1046 a6a8f8bb 2021-09-24 stsp (cd $testroot/wt && got update > /dev/null)
1047 a6a8f8bb 2021-09-24 stsp ret="$?"
1048 a6a8f8bb 2021-09-24 stsp if [ "$ret" != "0" ]; then
1049 a6a8f8bb 2021-09-24 stsp echo "got update failed unexpectedly" >&2
1050 a6a8f8bb 2021-09-24 stsp test_done "$testroot" "$ret"
1051 a6a8f8bb 2021-09-24 stsp return 1
1052 a6a8f8bb 2021-09-24 stsp fi
1053 a6a8f8bb 2021-09-24 stsp
1054 a6a8f8bb 2021-09-24 stsp (cd $testroot/wt && got merge newbranch \
1055 a6a8f8bb 2021-09-24 stsp > $testroot/stdout 2> $testroot/stderr)
1056 a6a8f8bb 2021-09-24 stsp ret="$?"
1057 a6a8f8bb 2021-09-24 stsp if [ "$ret" == "0" ]; then
1058 a6a8f8bb 2021-09-24 stsp echo "got merge succeeded unexpectedly" >&2
1059 a6a8f8bb 2021-09-24 stsp test_done "$testroot" "1"
1060 a6a8f8bb 2021-09-24 stsp return 1
1061 a6a8f8bb 2021-09-24 stsp fi
1062 a6a8f8bb 2021-09-24 stsp
1063 a6a8f8bb 2021-09-24 stsp echo "C alpha" >> $testroot/stdout.expected
1064 a6a8f8bb 2021-09-24 stsp echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1065 a6a8f8bb 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1066 a6a8f8bb 2021-09-24 stsp ret="$?"
1067 a6a8f8bb 2021-09-24 stsp if [ "$ret" != "0" ]; then
1068 a6a8f8bb 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
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 echo "got: conflicts must be resolved before merging can continue" \
1074 a6a8f8bb 2021-09-24 stsp > $testroot/stderr.expected
1075 a6a8f8bb 2021-09-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
1076 a6a8f8bb 2021-09-24 stsp ret="$?"
1077 a6a8f8bb 2021-09-24 stsp if [ "$ret" != "0" ]; then
1078 a6a8f8bb 2021-09-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
1079 a6a8f8bb 2021-09-24 stsp test_done "$testroot" "$ret"
1080 a6a8f8bb 2021-09-24 stsp return 1
1081 a6a8f8bb 2021-09-24 stsp fi
1082 a6a8f8bb 2021-09-24 stsp
1083 a6a8f8bb 2021-09-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
1084 a6a8f8bb 2021-09-24 stsp
1085 a6a8f8bb 2021-09-24 stsp echo "C alpha" > $testroot/stdout.expected
1086 f259c4c1 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1087 f259c4c1 2021-09-24 stsp ret="$?"
1088 f259c4c1 2021-09-24 stsp if [ "$ret" != "0" ]; then
1089 f259c4c1 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
1090 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
1091 f259c4c1 2021-09-24 stsp return 1
1092 f259c4c1 2021-09-24 stsp fi
1093 f259c4c1 2021-09-24 stsp
1094 a6a8f8bb 2021-09-24 stsp # resolve the conflict by reverting all changes; now it is no-op merge
1095 a6a8f8bb 2021-09-24 stsp (cd $testroot/wt && got revert alpha > /dev/null)
1096 a6a8f8bb 2021-09-24 stsp ret="$?"
1097 a6a8f8bb 2021-09-24 stsp if [ "$ret" != "0" ]; then
1098 a6a8f8bb 2021-09-24 stsp echo "got revert failed unexpectedly" >&2
1099 a6a8f8bb 2021-09-24 stsp test_done "$testroot" "$ret"
1100 a6a8f8bb 2021-09-24 stsp return 1
1101 a6a8f8bb 2021-09-24 stsp fi
1102 a6a8f8bb 2021-09-24 stsp
1103 a6a8f8bb 2021-09-24 stsp (cd $testroot/wt && got merge -c > $testroot/stdout \
1104 a6a8f8bb 2021-09-24 stsp 2> $testroot/stderr)
1105 a6a8f8bb 2021-09-24 stsp ret="$?"
1106 a6a8f8bb 2021-09-24 stsp if [ "$ret" == "0" ]; then
1107 a6a8f8bb 2021-09-24 stsp echo "got merge succeeded unexpectedly" >&2
1108 a6a8f8bb 2021-09-24 stsp test_done "$testroot" "$ret"
1109 a6a8f8bb 2021-09-24 stsp return 1
1110 a6a8f8bb 2021-09-24 stsp fi
1111 a6a8f8bb 2021-09-24 stsp
1112 a6a8f8bb 2021-09-24 stsp echo -n "got: merge of refs/heads/newbranch cannot proceed: " \
1113 a6a8f8bb 2021-09-24 stsp > $testroot/stderr.expected
1114 a6a8f8bb 2021-09-24 stsp echo "no changes to commit" >> $testroot/stderr.expected
1115 a6a8f8bb 2021-09-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
1116 a6a8f8bb 2021-09-24 stsp ret="$?"
1117 a6a8f8bb 2021-09-24 stsp if [ "$ret" != "0" ]; then
1118 a6a8f8bb 2021-09-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
1119 a6a8f8bb 2021-09-24 stsp test_done "$testroot" "$ret"
1120 a6a8f8bb 2021-09-24 stsp return 1
1121 a6a8f8bb 2021-09-24 stsp fi
1122 a6a8f8bb 2021-09-24 stsp
1123 a6a8f8bb 2021-09-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
1124 a6a8f8bb 2021-09-24 stsp
1125 a6a8f8bb 2021-09-24 stsp echo -n "" > $testroot/stdout.expected
1126 a6a8f8bb 2021-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1127 a6a8f8bb 2021-09-24 stsp ret="$?"
1128 a6a8f8bb 2021-09-24 stsp if [ "$ret" != "0" ]; then
1129 a6a8f8bb 2021-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
1130 a6a8f8bb 2021-09-24 stsp fi
1131 f259c4c1 2021-09-24 stsp test_done "$testroot" "$ret"
1132 f259c4c1 2021-09-24 stsp }
1133 f259c4c1 2021-09-24 stsp
1134 f259c4c1 2021-09-24 stsp test_parseargs "$@"
1135 f259c4c1 2021-09-24 stsp run_test test_merge_basic
1136 f259c4c1 2021-09-24 stsp run_test test_merge_continue
1137 f259c4c1 2021-09-24 stsp run_test test_merge_abort
1138 f259c4c1 2021-09-24 stsp run_test test_merge_in_progress
1139 f259c4c1 2021-09-24 stsp run_test test_merge_path_prefix
1140 f259c4c1 2021-09-24 stsp run_test test_merge_missing_file
1141 a6a8f8bb 2021-09-24 stsp run_test test_merge_no_op