Blame


1 f2900386 2022-10-31 thomas #!/bin/sh
2 f2900386 2022-10-31 thomas #
3 f2900386 2022-10-31 thomas # Copyright (c) 2022 Stefan Sperling <stsp@openbsd.org>
4 f2900386 2022-10-31 thomas #
5 f2900386 2022-10-31 thomas # Permission to use, copy, modify, and distribute this software for any
6 f2900386 2022-10-31 thomas # purpose with or without fee is hereby granted, provided that the above
7 f2900386 2022-10-31 thomas # copyright notice and this permission notice appear in all copies.
8 f2900386 2022-10-31 thomas #
9 f2900386 2022-10-31 thomas # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 f2900386 2022-10-31 thomas # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 f2900386 2022-10-31 thomas # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 f2900386 2022-10-31 thomas # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 f2900386 2022-10-31 thomas # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 f2900386 2022-10-31 thomas # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 f2900386 2022-10-31 thomas # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 f2900386 2022-10-31 thomas
17 f2900386 2022-10-31 thomas . ../cmdline/common.sh
18 f2900386 2022-10-31 thomas . ./common.sh
19 f2900386 2022-10-31 thomas
20 f2900386 2022-10-31 thomas test_send_basic() {
21 f2900386 2022-10-31 thomas local testroot=`test_init send_basic 1`
22 f2900386 2022-10-31 thomas
23 0445d8ec 2023-01-19 thomas ls -R ${GOTD_TEST_REPO}/objects/pack > $testroot/repo-list.before
24 f2900386 2022-10-31 thomas
25 f2900386 2022-10-31 thomas got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
26 f2900386 2022-10-31 thomas ret=$?
27 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
28 f2900386 2022-10-31 thomas echo "got clone failed unexpectedly" >&2
29 f2900386 2022-10-31 thomas test_done "$testroot" "1"
30 f2900386 2022-10-31 thomas return 1
31 f2900386 2022-10-31 thomas fi
32 f2900386 2022-10-31 thomas
33 c9aa63fb 2023-01-10 thomas # create a second clone to test an incremental fetch with later
34 c9aa63fb 2023-01-10 thomas got clone -q -m ${GOTD_TEST_REPO_URL} $testroot/repo-clone2
35 c9aa63fb 2023-01-10 thomas ret=$?
36 c9aa63fb 2023-01-10 thomas if [ $ret -ne 0 ]; then
37 c9aa63fb 2023-01-10 thomas echo "got clone failed unexpectedly" >&2
38 c9aa63fb 2023-01-10 thomas test_done "$testroot" "1"
39 c9aa63fb 2023-01-10 thomas return 1
40 c9aa63fb 2023-01-10 thomas fi
41 0445d8ec 2023-01-19 thomas # same for Git
42 0445d8ec 2023-01-19 thomas git clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone3 \
43 0445d8ec 2023-01-19 thomas >$testroot/stdout 2>$testroot/stderr
44 0445d8ec 2023-01-19 thomas ret=$?
45 0445d8ec 2023-01-19 thomas if [ $ret -ne 0 ]; then
46 0445d8ec 2023-01-19 thomas echo "git clone failed unexpectedly" >&2
47 0445d8ec 2023-01-19 thomas test_done "$testroot" "1"
48 0445d8ec 2023-01-19 thomas return 1
49 0445d8ec 2023-01-19 thomas fi
50 c9aa63fb 2023-01-10 thomas
51 f2900386 2022-10-31 thomas got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
52 f2900386 2022-10-31 thomas ret=$?
53 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
54 f2900386 2022-10-31 thomas echo "got checkout failed unexpectedly" >&2
55 f2900386 2022-10-31 thomas test_done "$testroot" "1"
56 f2900386 2022-10-31 thomas return 1
57 f2900386 2022-10-31 thomas fi
58 f2900386 2022-10-31 thomas
59 f2900386 2022-10-31 thomas mkdir $testroot/wt/psi
60 f2900386 2022-10-31 thomas echo "new" > $testroot/wt/psi/new
61 f2900386 2022-10-31 thomas (cd $testroot/wt && got add psi/new > /dev/null)
62 f2900386 2022-10-31 thomas echo "more alpha" >> $testroot/wt/alpha
63 f2900386 2022-10-31 thomas (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
64 0445d8ec 2023-01-19 thomas (cd $testroot/wt && got branch newbranch >/dev/null)
65 0445d8ec 2023-01-19 thomas echo "even more alpha" >> $testroot/wt/alpha
66 0445d8ec 2023-01-19 thomas (cd $testroot/wt && got commit -m 'more changes' > /dev/null)
67 0445d8ec 2023-01-19 thomas got tag -r $testroot/repo-clone -m "tagging 1.0" 1.0 >/dev/null
68 f2900386 2022-10-31 thomas
69 0445d8ec 2023-01-19 thomas got send -b main -b newbranch -q -r $testroot/repo-clone -t 1.0
70 f2900386 2022-10-31 thomas ret=$?
71 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
72 f2900386 2022-10-31 thomas echo "got send failed unexpectedly" >&2
73 f2900386 2022-10-31 thomas test_done "$testroot" "1"
74 f2900386 2022-10-31 thomas return 1
75 f2900386 2022-10-31 thomas fi
76 f2900386 2022-10-31 thomas
77 f2900386 2022-10-31 thomas # Verify that the send operation worked fine.
78 c9aa63fb 2023-01-10 thomas got fetch -q -r $testroot/repo-clone2
79 f2900386 2022-10-31 thomas ret=$?
80 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
81 c9aa63fb 2023-01-10 thomas echo "got fetch failed unexpectedly" >&2
82 f2900386 2022-10-31 thomas test_done "$testroot" "1"
83 f2900386 2022-10-31 thomas return 1
84 f2900386 2022-10-31 thomas fi
85 f2900386 2022-10-31 thomas
86 f2900386 2022-10-31 thomas got tree -R -r $testroot/repo-clone2 > $testroot/stdout
87 f2900386 2022-10-31 thomas cat > $testroot/stdout.expected <<EOF
88 f2900386 2022-10-31 thomas alpha
89 f2900386 2022-10-31 thomas beta
90 f2900386 2022-10-31 thomas epsilon/
91 f2900386 2022-10-31 thomas epsilon/zeta
92 f2900386 2022-10-31 thomas gamma/
93 f2900386 2022-10-31 thomas gamma/delta
94 f2900386 2022-10-31 thomas psi/
95 f2900386 2022-10-31 thomas psi/new
96 f2900386 2022-10-31 thomas EOF
97 f2900386 2022-10-31 thomas cmp -s $testroot/stdout.expected $testroot/stdout
98 f2900386 2022-10-31 thomas ret=$?
99 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
100 f2900386 2022-10-31 thomas diff -u $testroot/stdout.expected $testroot/stdout
101 f2900386 2022-10-31 thomas test_done "$testroot" "$ret"
102 f2900386 2022-10-31 thomas return 1
103 f2900386 2022-10-31 thomas fi
104 f2900386 2022-10-31 thomas
105 0445d8ec 2023-01-19 thomas # Verify that git pull works, too
106 0445d8ec 2023-01-19 thomas (cd $testroot/repo-clone3 && git pull -q > $testroot/stdout \
107 0445d8ec 2023-01-19 thomas 2> $testroot/stderr)
108 0445d8ec 2023-01-19 thomas ret=$?
109 0445d8ec 2023-01-19 thomas if [ $ret -ne 0 ]; then
110 0445d8ec 2023-01-19 thomas echo "git pull failed unexpectedly" >&2
111 8e92c55c 2023-06-08 thomas test_done "$testroot" "1"
112 8e92c55c 2023-06-08 thomas return 1
113 8e92c55c 2023-06-08 thomas fi
114 8e92c55c 2023-06-08 thomas
115 8e92c55c 2023-06-08 thomas # Verify that git push reports no changes to send and no error.
116 8e92c55c 2023-06-08 thomas (cd $testroot/repo-clone3 && git push -q > $testroot/stdout \
117 8e92c55c 2023-06-08 thomas 2> $testroot/stderr)
118 8e92c55c 2023-06-08 thomas ret=$?
119 8e92c55c 2023-06-08 thomas if [ $ret -ne 0 ]; then
120 8e92c55c 2023-06-08 thomas echo "git push failed unexpectedly" >&2
121 0445d8ec 2023-01-19 thomas test_done "$testroot" "1"
122 0445d8ec 2023-01-19 thomas return 1
123 0445d8ec 2023-01-19 thomas fi
124 0445d8ec 2023-01-19 thomas
125 f2900386 2022-10-31 thomas # sending to a repository should result in a new pack file
126 0445d8ec 2023-01-19 thomas ls -R ${GOTD_TEST_REPO}/objects/pack > $testroot/repo-list.after
127 f2900386 2022-10-31 thomas diff -u $testroot/repo-list.before $testroot/repo-list.after \
128 f2900386 2022-10-31 thomas > $testroot/repo-list.diff
129 f2900386 2022-10-31 thomas grep '^+[^+]' < $testroot/repo-list.diff > $testroot/repo-list.newlines
130 f2900386 2022-10-31 thomas nplus=`wc -l < $testroot/repo-list.newlines | tr -d ' '`
131 f2900386 2022-10-31 thomas if [ "$nplus" != "2" ]; then
132 0445d8ec 2023-01-19 thomas echo "$nplus new files created:"
133 0445d8ec 2023-01-19 thomas cat $testroot/repo-list.diff
134 f2900386 2022-10-31 thomas test_done "$testroot" "$ret"
135 f2900386 2022-10-31 thomas return 1
136 f2900386 2022-10-31 thomas fi
137 f2900386 2022-10-31 thomas egrep -q '\+pack-[a-f0-9]{40}.pack' $testroot/repo-list.newlines
138 f2900386 2022-10-31 thomas ret=$?
139 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
140 f2900386 2022-10-31 thomas echo "new pack file not found in ${GOTD_TEST_REPO}"
141 f2900386 2022-10-31 thomas cat $testroot/repo-list.newlines
142 f2900386 2022-10-31 thomas test_done "$testroot" "$ret"
143 f2900386 2022-10-31 thomas return 1
144 f2900386 2022-10-31 thomas fi
145 f2900386 2022-10-31 thomas egrep -q '\+pack-[a-f0-9]{40}.idx' $testroot/repo-list.newlines
146 f2900386 2022-10-31 thomas ret=$?
147 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
148 f2900386 2022-10-31 thomas echo "new pack index not found in ${GOTD_TEST_REPO}"
149 f2900386 2022-10-31 thomas test_done "$testroot" "$ret"
150 f2900386 2022-10-31 thomas return 1
151 f2900386 2022-10-31 thomas fi
152 f2900386 2022-10-31 thomas
153 f2900386 2022-10-31 thomas test_done "$testroot" "$ret"
154 f2900386 2022-10-31 thomas }
155 f2900386 2022-10-31 thomas
156 6110f5ef 2023-01-19 thomas test_fetch_more_history() {
157 6110f5ef 2023-01-19 thomas local testroot=`test_init fetch_more_history 1`
158 6110f5ef 2023-01-19 thomas
159 6110f5ef 2023-01-19 thomas got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
160 6110f5ef 2023-01-19 thomas ret=$?
161 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
162 6110f5ef 2023-01-19 thomas echo "got clone failed unexpectedly" >&2
163 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
164 6110f5ef 2023-01-19 thomas return 1
165 6110f5ef 2023-01-19 thomas fi
166 6110f5ef 2023-01-19 thomas
167 6110f5ef 2023-01-19 thomas got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
168 6110f5ef 2023-01-19 thomas ret=$?
169 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
170 6110f5ef 2023-01-19 thomas echo "got checkout failed unexpectedly" >&2
171 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
172 6110f5ef 2023-01-19 thomas return 1
173 6110f5ef 2023-01-19 thomas fi
174 6110f5ef 2023-01-19 thomas
175 6110f5ef 2023-01-19 thomas # Create some more commit history on the main branch.
176 6110f5ef 2023-01-19 thomas # History needs to be deep enough to trick 'git pull' into sending
177 6110f5ef 2023-01-19 thomas # a lot of 'have' lines, which triggered a bug in gotd.
178 cf85a643 2024-04-09 thomas for i in `seq 50`; do
179 6110f5ef 2023-01-19 thomas echo "more alpha" >> $testroot/wt/alpha
180 6110f5ef 2023-01-19 thomas (cd $testroot/wt && got commit -m 'more changes' > /dev/null)
181 6110f5ef 2023-01-19 thomas done
182 6110f5ef 2023-01-19 thomas got send -b main -q -r $testroot/repo-clone
183 6110f5ef 2023-01-19 thomas ret=$?
184 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
185 6110f5ef 2023-01-19 thomas echo "got send failed unexpectedly" >&2
186 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
187 6110f5ef 2023-01-19 thomas return 1
188 6110f5ef 2023-01-19 thomas fi
189 6110f5ef 2023-01-19 thomas
190 6110f5ef 2023-01-19 thomas # create a second clone to test an incremental fetch with later
191 6110f5ef 2023-01-19 thomas got clone -q -m ${GOTD_TEST_REPO_URL} $testroot/repo-clone2
192 6110f5ef 2023-01-19 thomas ret=$?
193 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
194 6110f5ef 2023-01-19 thomas echo "got clone failed unexpectedly" >&2
195 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
196 6110f5ef 2023-01-19 thomas return 1
197 6110f5ef 2023-01-19 thomas fi
198 6110f5ef 2023-01-19 thomas # same for Git, which used to fail:
199 6110f5ef 2023-01-19 thomas # fetch-pack: protocol error: bad band #69
200 6110f5ef 2023-01-19 thomas # fatal: protocol error: bad pack header
201 6110f5ef 2023-01-19 thomas # gotsh: unexpected 'have' packet
202 6110f5ef 2023-01-19 thomas git clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone3 \
203 6110f5ef 2023-01-19 thomas >$testroot/stdout 2>$testroot/stderr
204 6110f5ef 2023-01-19 thomas ret=$?
205 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
206 6110f5ef 2023-01-19 thomas echo "git clone failed unexpectedly" >&2
207 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
208 6110f5ef 2023-01-19 thomas return 1
209 6110f5ef 2023-01-19 thomas fi
210 6110f5ef 2023-01-19 thomas
211 6110f5ef 2023-01-19 thomas # Create more commit history on the main branch
212 6110f5ef 2023-01-19 thomas echo "more alpha" >> $testroot/wt/alpha
213 6110f5ef 2023-01-19 thomas (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
214 6110f5ef 2023-01-19 thomas echo "more beta" >> $testroot/wt/beta
215 6110f5ef 2023-01-19 thomas (cd $testroot/wt && got commit -m 'more changes' > /dev/null)
216 6110f5ef 2023-01-19 thomas (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
217 6110f5ef 2023-01-19 thomas (cd $testroot/wt && got commit -m 'rm epsilon/zeta' > /dev/null)
218 6110f5ef 2023-01-19 thomas got send -b main -q -r $testroot/repo-clone
219 6110f5ef 2023-01-19 thomas ret=$?
220 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
221 6110f5ef 2023-01-19 thomas echo "got send failed unexpectedly" >&2
222 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
223 6110f5ef 2023-01-19 thomas return 1
224 6110f5ef 2023-01-19 thomas fi
225 6110f5ef 2023-01-19 thomas
226 6110f5ef 2023-01-19 thomas # Verify that the new changes can be fetched
227 6110f5ef 2023-01-19 thomas got fetch -q -r $testroot/repo-clone2
228 6110f5ef 2023-01-19 thomas ret=$?
229 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
230 6110f5ef 2023-01-19 thomas echo "got fetch failed unexpectedly" >&2
231 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
232 6110f5ef 2023-01-19 thomas return 1
233 6110f5ef 2023-01-19 thomas fi
234 6110f5ef 2023-01-19 thomas
235 6110f5ef 2023-01-19 thomas got tree -R -r $testroot/repo-clone2 > $testroot/stdout
236 6110f5ef 2023-01-19 thomas cat > $testroot/stdout.expected <<EOF
237 6110f5ef 2023-01-19 thomas alpha
238 6110f5ef 2023-01-19 thomas beta
239 6110f5ef 2023-01-19 thomas gamma/
240 6110f5ef 2023-01-19 thomas gamma/delta
241 6110f5ef 2023-01-19 thomas psi/
242 6110f5ef 2023-01-19 thomas psi/new
243 6110f5ef 2023-01-19 thomas EOF
244 6110f5ef 2023-01-19 thomas cmp -s $testroot/stdout.expected $testroot/stdout
245 6110f5ef 2023-01-19 thomas ret=$?
246 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
247 6110f5ef 2023-01-19 thomas diff -u $testroot/stdout.expected $testroot/stdout
248 6110f5ef 2023-01-19 thomas test_done "$testroot" "$ret"
249 6110f5ef 2023-01-19 thomas return 1
250 6110f5ef 2023-01-19 thomas fi
251 6110f5ef 2023-01-19 thomas
252 6110f5ef 2023-01-19 thomas # Verify that git pull works, too
253 6110f5ef 2023-01-19 thomas (cd $testroot/repo-clone3 && git pull -q > $testroot/stdout \
254 6110f5ef 2023-01-19 thomas 2> $testroot/stderr)
255 6110f5ef 2023-01-19 thomas ret=$?
256 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
257 6110f5ef 2023-01-19 thomas echo "git pull failed unexpectedly" >&2
258 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
259 6110f5ef 2023-01-19 thomas return 1
260 6110f5ef 2023-01-19 thomas fi
261 6110f5ef 2023-01-19 thomas
262 6110f5ef 2023-01-19 thomas test_done "$testroot" "$ret"
263 6110f5ef 2023-01-19 thomas }
264 d98779cd 2023-01-19 thomas
265 d98779cd 2023-01-19 thomas test_send_new_empty_branch() {
266 d98779cd 2023-01-19 thomas local testroot=`test_init send_new_empty_branch 1`
267 d98779cd 2023-01-19 thomas
268 d98779cd 2023-01-19 thomas got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
269 d98779cd 2023-01-19 thomas ret=$?
270 d98779cd 2023-01-19 thomas if [ $ret -ne 0 ]; then
271 d98779cd 2023-01-19 thomas echo "got clone failed unexpectedly" >&2
272 d98779cd 2023-01-19 thomas test_done "$testroot" "1"
273 d98779cd 2023-01-19 thomas return 1
274 d98779cd 2023-01-19 thomas fi
275 d98779cd 2023-01-19 thomas local commit_id=`git_show_head $testroot/repo-clone`
276 6110f5ef 2023-01-19 thomas
277 d98779cd 2023-01-19 thomas got branch -r $testroot/repo-clone -c main newbranch2 >/dev/null
278 d98779cd 2023-01-19 thomas got send -b newbranch2 -q -r $testroot/repo-clone
279 d98779cd 2023-01-19 thomas ret=$?
280 d98779cd 2023-01-19 thomas if [ $ret -ne 0 ]; then
281 d98779cd 2023-01-19 thomas echo "got send failed unexpectedly" >&2
282 d98779cd 2023-01-19 thomas test_done "$testroot" "1"
283 d98779cd 2023-01-19 thomas return 1
284 d98779cd 2023-01-19 thomas fi
285 6110f5ef 2023-01-19 thomas
286 d98779cd 2023-01-19 thomas # Verify that the send operation worked fine.
287 d98779cd 2023-01-19 thomas got clone -l ${GOTD_TEST_REPO_URL} | grep newbranch2 > $testroot/stdout
288 d98779cd 2023-01-19 thomas ret=$?
289 d98779cd 2023-01-19 thomas if [ $ret -ne 0 ]; then
290 d98779cd 2023-01-19 thomas echo "got clone -l failed unexpectedly" >&2
291 d98779cd 2023-01-19 thomas test_done "$testroot" "1"
292 d98779cd 2023-01-19 thomas return 1
293 d98779cd 2023-01-19 thomas fi
294 d98779cd 2023-01-19 thomas
295 d98779cd 2023-01-19 thomas echo "refs/heads/newbranch2: $commit_id" > $testroot/stdout.expected
296 d98779cd 2023-01-19 thomas cmp -s $testroot/stdout.expected $testroot/stdout
297 d98779cd 2023-01-19 thomas ret=$?
298 d98779cd 2023-01-19 thomas if [ $ret -ne 0 ]; then
299 d98779cd 2023-01-19 thomas diff -u $testroot/stdout.expected $testroot/stdout
300 d98779cd 2023-01-19 thomas fi
301 d98779cd 2023-01-19 thomas
302 d98779cd 2023-01-19 thomas test_done "$testroot" "$ret"
303 d98779cd 2023-01-19 thomas }
304 49563dfb 2023-01-28 thomas
305 49563dfb 2023-01-28 thomas test_delete_branch() {
306 49563dfb 2023-01-28 thomas local testroot=`test_init delete_branch 1`
307 49563dfb 2023-01-28 thomas
308 a9020bab 2023-01-28 thomas got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
309 49563dfb 2023-01-28 thomas ret=$?
310 49563dfb 2023-01-28 thomas if [ $ret -ne 0 ]; then
311 49563dfb 2023-01-28 thomas echo "got clone failed unexpectedly" >&2
312 49563dfb 2023-01-28 thomas test_done "$testroot" 1
313 49563dfb 2023-01-28 thomas return 1
314 49563dfb 2023-01-28 thomas fi
315 49563dfb 2023-01-28 thomas
316 49563dfb 2023-01-28 thomas got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
317 49563dfb 2023-01-28 thomas ret=$?
318 49563dfb 2023-01-28 thomas if [ $ret -ne 0 ]; then
319 49563dfb 2023-01-28 thomas echo "got checkout failed unexpectedly" >&2
320 49563dfb 2023-01-28 thomas test_done "$testroot" 1
321 49563dfb 2023-01-28 thomas return 1
322 49563dfb 2023-01-28 thomas fi
323 49563dfb 2023-01-28 thomas
324 49563dfb 2023-01-28 thomas (cd $testroot/wt && got branch foo) >/dev/null
325 49563dfb 2023-01-28 thomas ret=$?
326 49563dfb 2023-01-28 thomas if [ $ret -ne 0 ]; then
327 49563dfb 2023-01-28 thomas echo "got branch failed unexpectedly" >&2
328 49563dfb 2023-01-28 thomas test_done "$testroot" 1
329 49563dfb 2023-01-28 thomas return 1
330 49563dfb 2023-01-28 thomas fi
331 49563dfb 2023-01-28 thomas
332 49563dfb 2023-01-28 thomas echo modified alpha > $testroot/wt/alpha
333 49563dfb 2023-01-28 thomas (cd $testroot/wt && got commit -m 'edit alpha') >/dev/null
334 49563dfb 2023-01-28 thomas ret=$?
335 49563dfb 2023-01-28 thomas if [ $ret -ne 0 ]; then
336 49563dfb 2023-01-28 thomas echo "got commit failed unexpectedly" >&2
337 49563dfb 2023-01-28 thomas test_done "$testroot" 1
338 49563dfb 2023-01-28 thomas return 1
339 49563dfb 2023-01-28 thomas fi
340 a9020bab 2023-01-28 thomas
341 a9020bab 2023-01-28 thomas local foo_id=`git_show_branch_head "$testroot/repo-clone" foo`
342 a9020bab 2023-01-28 thomas local main_id=`git_show_branch_head "$testroot/repo-clone" main`
343 a9020bab 2023-01-28 thomas local nb_id=`git_show_branch_head "$testroot/repo-clone" newbranch`
344 a9020bab 2023-01-28 thomas local nb2_id=`git_show_branch_head "$testroot/repo-clone" newbranch2`
345 a9020bab 2023-01-28 thomas local tag_id=`got ref -r "$testroot/repo-clone" -l refs/tags/1.0 | \
346 a9020bab 2023-01-28 thomas awk '{print $2}'`
347 49563dfb 2023-01-28 thomas
348 49563dfb 2023-01-28 thomas if ! got send -q -r $testroot/repo-clone -b foo; then
349 49563dfb 2023-01-28 thomas echo "got send failed unexpectedly" >&2
350 49563dfb 2023-01-28 thomas test_done "$testroot" 1
351 49563dfb 2023-01-28 thomas return 1
352 49563dfb 2023-01-28 thomas fi
353 49563dfb 2023-01-28 thomas
354 a9020bab 2023-01-28 thomas got fetch -q -r $testroot/repo-clone -l >$testroot/refs
355 a9020bab 2023-01-28 thomas cat <<EOF >$testroot/refs.expected
356 a9020bab 2023-01-28 thomas HEAD: refs/heads/main
357 619437c1 2023-11-29 thomas HEAD: $main_id
358 a9020bab 2023-01-28 thomas refs/heads/foo: $foo_id
359 a9020bab 2023-01-28 thomas refs/heads/main: $main_id
360 a9020bab 2023-01-28 thomas refs/heads/newbranch: $nb_id
361 a9020bab 2023-01-28 thomas refs/heads/newbranch2: $nb2_id
362 a9020bab 2023-01-28 thomas refs/tags/1.0: $tag_id
363 a9020bab 2023-01-28 thomas EOF
364 a9020bab 2023-01-28 thomas if ! cmp -s $testroot/refs.expected $testroot/refs; then
365 a9020bab 2023-01-28 thomas diff -u $testroot/refs.expected $testroot/refs
366 a9020bab 2023-01-28 thomas test_done "$testroot" 1
367 a9020bab 2023-01-28 thomas return 1
368 a9020bab 2023-01-28 thomas fi
369 a9020bab 2023-01-28 thomas
370 a9020bab 2023-01-28 thomas (cd $testroot/repo-clone && git push -d origin foo) >/dev/null 2>&1
371 49563dfb 2023-01-28 thomas ret=$?
372 49563dfb 2023-01-28 thomas if [ $ret -ne 0 ]; then
373 a9020bab 2023-01-28 thomas echo "git push -d failed unexpectedly" >&2
374 a9020bab 2023-01-28 thomas test_done "$testroot" 1
375 a9020bab 2023-01-28 thomas return 1
376 a9020bab 2023-01-28 thomas fi
377 a9020bab 2023-01-28 thomas
378 a9020bab 2023-01-28 thomas got fetch -q -r $testroot/repo-clone -l >$testroot/refs
379 a9020bab 2023-01-28 thomas cat <<EOF >$testroot/refs.expected
380 a9020bab 2023-01-28 thomas HEAD: refs/heads/main
381 619437c1 2023-11-29 thomas HEAD: $main_id
382 a9020bab 2023-01-28 thomas refs/heads/main: $main_id
383 a9020bab 2023-01-28 thomas refs/heads/newbranch: $nb_id
384 a9020bab 2023-01-28 thomas refs/heads/newbranch2: $nb2_id
385 a9020bab 2023-01-28 thomas refs/tags/1.0: $tag_id
386 a9020bab 2023-01-28 thomas EOF
387 a9020bab 2023-01-28 thomas if ! cmp -s $testroot/refs.expected $testroot/refs; then
388 a9020bab 2023-01-28 thomas diff -u $testroot/refs.expected $testroot/refs
389 49563dfb 2023-01-28 thomas test_done "$testroot" 1
390 49563dfb 2023-01-28 thomas return 1
391 49563dfb 2023-01-28 thomas fi
392 d98779cd 2023-01-19 thomas
393 a9020bab 2023-01-28 thomas # try to delete multiple branches in one go
394 a9020bab 2023-01-28 thomas got send -r $testroot/repo-clone -d newbranch -d newbranch2 \
395 a9020bab 2023-01-28 thomas >$testroot/stdout
396 a9020bab 2023-01-28 thomas ret=$?
397 a9020bab 2023-01-28 thomas if [ $ret -ne 0 ]; then
398 a9020bab 2023-01-28 thomas echo "got send with multiple -d failed unexpectedly" >&2
399 a9020bab 2023-01-28 thomas test_done "$testroot" 1
400 a9020bab 2023-01-28 thomas return 1
401 a9020bab 2023-01-28 thomas fi
402 a9020bab 2023-01-28 thomas
403 49563dfb 2023-01-28 thomas cat <<EOF >$testroot/stdout.expected
404 49563dfb 2023-01-28 thomas Connecting to "origin" ${GOTD_TEST_REPO_URL}
405 a9020bab 2023-01-28 thomas Server has deleted refs/heads/newbranch2
406 a9020bab 2023-01-28 thomas Server has deleted refs/heads/newbranch
407 49563dfb 2023-01-28 thomas EOF
408 49563dfb 2023-01-28 thomas if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
409 49563dfb 2023-01-28 thomas diff -u $testroot/stdout.expected $testroot/stdout
410 49563dfb 2023-01-28 thomas test_done "$testroot" 1
411 49563dfb 2023-01-28 thomas return 1
412 49563dfb 2023-01-28 thomas fi
413 d98779cd 2023-01-19 thomas
414 a9020bab 2023-01-28 thomas got fetch -q -r $testroot/repo-clone -l >$testroot/refs
415 a9020bab 2023-01-28 thomas cat <<EOF >$testroot/refs.expected
416 a9020bab 2023-01-28 thomas HEAD: refs/heads/main
417 619437c1 2023-11-29 thomas HEAD: $main_id
418 a9020bab 2023-01-28 thomas refs/heads/main: $main_id
419 a9020bab 2023-01-28 thomas refs/tags/1.0: $tag_id
420 a9020bab 2023-01-28 thomas EOF
421 a9020bab 2023-01-28 thomas if ! cmp -s $testroot/refs.expected $testroot/refs; then
422 a9020bab 2023-01-28 thomas diff -u $testroot/refs.expected $testroot/refs
423 a9020bab 2023-01-28 thomas test_done "$testroot" 1
424 a9020bab 2023-01-28 thomas return 1
425 a9020bab 2023-01-28 thomas fi
426 a9020bab 2023-01-28 thomas
427 49563dfb 2023-01-28 thomas # now try again but while also updating another branch
428 49563dfb 2023-01-28 thomas # other than deleting `foo'.
429 49563dfb 2023-01-28 thomas
430 49563dfb 2023-01-28 thomas (cd $testroot/wt && got up -b main && \
431 49563dfb 2023-01-28 thomas echo 'more alpha' > alpha && \
432 49563dfb 2023-01-28 thomas got commit -m 'edit alpha on main' && \
433 49563dfb 2023-01-28 thomas got send -q -b foo) >/dev/null
434 a9020bab 2023-01-28 thomas main_id=`git_show_branch_head "$testroot/repo-clone" main`
435 49563dfb 2023-01-28 thomas
436 49563dfb 2023-01-28 thomas got send -r $testroot/repo-clone -d foo -b main | \
437 49563dfb 2023-01-28 thomas grep '^Server has' >$testroot/stdout
438 49563dfb 2023-01-28 thomas ret=$?
439 49563dfb 2023-01-28 thomas if [ $ret -ne 0 ]; then
440 49563dfb 2023-01-28 thomas echo "got send -d foo -b main failed unexpectedly" >&2
441 49563dfb 2023-01-28 thomas test_done "$testroot" 1
442 49563dfb 2023-01-28 thomas return 1
443 49563dfb 2023-01-28 thomas fi
444 49563dfb 2023-01-28 thomas
445 49563dfb 2023-01-28 thomas cat <<EOF >$testroot/stdout.expected
446 49563dfb 2023-01-28 thomas Server has accepted refs/heads/main
447 49563dfb 2023-01-28 thomas Server has deleted refs/heads/foo
448 49563dfb 2023-01-28 thomas EOF
449 49563dfb 2023-01-28 thomas if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
450 49563dfb 2023-01-28 thomas diff -u $testroot/stdout.expected $testroot/stdout
451 49563dfb 2023-01-28 thomas test_done "$testroot" 1
452 49563dfb 2023-01-28 thomas return 1
453 49563dfb 2023-01-28 thomas fi
454 49563dfb 2023-01-28 thomas
455 a9020bab 2023-01-28 thomas got fetch -q -r $testroot/repo-clone -l >$testroot/refs
456 a9020bab 2023-01-28 thomas cat <<EOF >$testroot/refs.expected
457 a9020bab 2023-01-28 thomas HEAD: refs/heads/main
458 619437c1 2023-11-29 thomas HEAD: $main_id
459 a9020bab 2023-01-28 thomas refs/heads/main: $main_id
460 a9020bab 2023-01-28 thomas refs/tags/1.0: $tag_id
461 a9020bab 2023-01-28 thomas EOF
462 a9020bab 2023-01-28 thomas if ! cmp -s $testroot/refs.expected $testroot/refs; then
463 a9020bab 2023-01-28 thomas diff -u $testroot/refs.expected $testroot/refs
464 a9020bab 2023-01-28 thomas test_done "$testroot" 1
465 a9020bab 2023-01-28 thomas return 1
466 a9020bab 2023-01-28 thomas fi
467 a9020bab 2023-01-28 thomas
468 49563dfb 2023-01-28 thomas test_done "$testroot" 0
469 49563dfb 2023-01-28 thomas }
470 49563dfb 2023-01-28 thomas
471 f9542c24 2023-04-14 thomas test_rewind_branch() {
472 f9542c24 2023-04-14 thomas local testroot=`test_init rewind_branch 1`
473 f9542c24 2023-04-14 thomas
474 f9542c24 2023-04-14 thomas got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
475 f9542c24 2023-04-14 thomas ret=$?
476 f9542c24 2023-04-14 thomas if [ $ret -ne 0 ]; then
477 f9542c24 2023-04-14 thomas echo "got clone failed unexpectedly" >&2
478 f9542c24 2023-04-14 thomas test_done "$testroot" 1
479 f9542c24 2023-04-14 thomas return 1
480 f9542c24 2023-04-14 thomas fi
481 f9542c24 2023-04-14 thomas
482 f9542c24 2023-04-14 thomas got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
483 f9542c24 2023-04-14 thomas ret=$?
484 f9542c24 2023-04-14 thomas if [ $ret -ne 0 ]; then
485 f9542c24 2023-04-14 thomas echo "got checkout failed unexpectedly" >&2
486 f9542c24 2023-04-14 thomas test_done "$testroot" 1
487 f9542c24 2023-04-14 thomas return 1
488 f9542c24 2023-04-14 thomas fi
489 f9542c24 2023-04-14 thomas
490 f9542c24 2023-04-14 thomas (cd $testroot/wt && got branch foo) >/dev/null
491 f9542c24 2023-04-14 thomas ret=$?
492 f9542c24 2023-04-14 thomas if [ $ret -ne 0 ]; then
493 f9542c24 2023-04-14 thomas echo "got branch failed unexpectedly" >&2
494 f9542c24 2023-04-14 thomas test_done "$testroot" 1
495 f9542c24 2023-04-14 thomas return 1
496 f9542c24 2023-04-14 thomas fi
497 f9542c24 2023-04-14 thomas
498 f9542c24 2023-04-14 thomas echo modified alpha > $testroot/wt/alpha
499 f9542c24 2023-04-14 thomas (cd $testroot/wt && got commit -m 'edit alpha') >/dev/null
500 f9542c24 2023-04-14 thomas ret=$?
501 f9542c24 2023-04-14 thomas if [ $ret -ne 0 ]; then
502 f9542c24 2023-04-14 thomas echo "got commit failed unexpectedly" >&2
503 f9542c24 2023-04-14 thomas test_done "$testroot" 1
504 f9542c24 2023-04-14 thomas return 1
505 f9542c24 2023-04-14 thomas fi
506 f9542c24 2023-04-14 thomas
507 f9542c24 2023-04-14 thomas if ! got send -q -r $testroot/repo-clone -b foo; then
508 f9542c24 2023-04-14 thomas echo "got send failed unexpectedly" >&2
509 f9542c24 2023-04-14 thomas test_done "$testroot" 1
510 f9542c24 2023-04-14 thomas return 1
511 f9542c24 2023-04-14 thomas fi
512 f9542c24 2023-04-14 thomas
513 f9542c24 2023-04-14 thomas local foo_id=`git_show_branch_head "$testroot/repo-clone" foo`
514 f9542c24 2023-04-14 thomas local main_id=`git_show_branch_head "$testroot/repo-clone" main`
515 f9542c24 2023-04-14 thomas local tag_id=`got ref -r "$testroot/repo-clone" -l refs/tags/1.0 | \
516 f9542c24 2023-04-14 thomas awk '{print $2}'`
517 f9542c24 2023-04-14 thomas
518 f9542c24 2023-04-14 thomas (cd $testroot/wt && got update -c $main_id) >/dev/null
519 f9542c24 2023-04-14 thomas ret=$?
520 f9542c24 2023-04-14 thomas if [ $ret -ne 0 ]; then
521 f9542c24 2023-04-14 thomas echo "got update failed unexpectedly" >&2
522 f9542c24 2023-04-14 thomas test_done "$testroot" 1
523 f9542c24 2023-04-14 thomas return 1
524 f9542c24 2023-04-14 thomas fi
525 f9542c24 2023-04-14 thomas
526 f9542c24 2023-04-14 thomas (cd $testroot/wt && got histedit -d) >/dev/null
527 f9542c24 2023-04-14 thomas ret=$?
528 f9542c24 2023-04-14 thomas if [ $ret -ne 0 ]; then
529 f9542c24 2023-04-14 thomas echo "got histedit failed unexpectedly" >&2
530 f9542c24 2023-04-14 thomas test_done "$testroot" 1
531 f9542c24 2023-04-14 thomas return 1
532 f9542c24 2023-04-14 thomas fi
533 f9542c24 2023-04-14 thomas
534 f9542c24 2023-04-14 thomas if ! got send -q -r $testroot/repo-clone -f -b foo; then
535 f9542c24 2023-04-14 thomas echo "got send failed unexpectedly" >&2
536 f9542c24 2023-04-14 thomas test_done "$testroot" 1
537 f9542c24 2023-04-14 thomas return 1
538 f9542c24 2023-04-14 thomas fi
539 f9542c24 2023-04-14 thomas
540 f9542c24 2023-04-14 thomas got fetch -q -r $testroot/repo-clone -l >$testroot/refs
541 f9542c24 2023-04-14 thomas cat <<EOF >$testroot/refs.expected
542 f9542c24 2023-04-14 thomas HEAD: refs/heads/main
543 619437c1 2023-11-29 thomas HEAD: $main_id
544 f9542c24 2023-04-14 thomas refs/heads/foo: $main_id
545 f9542c24 2023-04-14 thomas refs/heads/main: $main_id
546 f9542c24 2023-04-14 thomas refs/tags/1.0: $tag_id
547 f9542c24 2023-04-14 thomas EOF
548 f9542c24 2023-04-14 thomas if ! cmp -s $testroot/refs.expected $testroot/refs; then
549 f9542c24 2023-04-14 thomas diff -u $testroot/refs.expected $testroot/refs
550 f9542c24 2023-04-14 thomas test_done "$testroot" 1
551 f9542c24 2023-04-14 thomas return 1
552 f9542c24 2023-04-14 thomas fi
553 f9542c24 2023-04-14 thomas
554 f9542c24 2023-04-14 thomas test_done "$testroot" 0
555 f9542c24 2023-04-14 thomas }
556 f9542c24 2023-04-14 thomas
557 f2900386 2022-10-31 thomas test_parseargs "$@"
558 f2900386 2022-10-31 thomas run_test test_send_basic
559 6110f5ef 2023-01-19 thomas run_test test_fetch_more_history
560 d98779cd 2023-01-19 thomas run_test test_send_new_empty_branch
561 49563dfb 2023-01-28 thomas run_test test_delete_branch
562 f9542c24 2023-04-14 thomas run_test test_rewind_branch