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 0445d8ec 2023-01-19 thomas test_done "$testroot" "1"
112 0445d8ec 2023-01-19 thomas return 1
113 0445d8ec 2023-01-19 thomas fi
114 0445d8ec 2023-01-19 thomas
115 f2900386 2022-10-31 thomas # sending to a repository should result in a new pack file
116 0445d8ec 2023-01-19 thomas ls -R ${GOTD_TEST_REPO}/objects/pack > $testroot/repo-list.after
117 f2900386 2022-10-31 thomas diff -u $testroot/repo-list.before $testroot/repo-list.after \
118 f2900386 2022-10-31 thomas > $testroot/repo-list.diff
119 f2900386 2022-10-31 thomas grep '^+[^+]' < $testroot/repo-list.diff > $testroot/repo-list.newlines
120 f2900386 2022-10-31 thomas nplus=`wc -l < $testroot/repo-list.newlines | tr -d ' '`
121 f2900386 2022-10-31 thomas if [ "$nplus" != "2" ]; then
122 0445d8ec 2023-01-19 thomas echo "$nplus new files created:"
123 0445d8ec 2023-01-19 thomas cat $testroot/repo-list.diff
124 f2900386 2022-10-31 thomas test_done "$testroot" "$ret"
125 f2900386 2022-10-31 thomas return 1
126 f2900386 2022-10-31 thomas fi
127 f2900386 2022-10-31 thomas egrep -q '\+pack-[a-f0-9]{40}.pack' $testroot/repo-list.newlines
128 f2900386 2022-10-31 thomas ret=$?
129 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
130 f2900386 2022-10-31 thomas echo "new pack file not found in ${GOTD_TEST_REPO}"
131 f2900386 2022-10-31 thomas cat $testroot/repo-list.newlines
132 f2900386 2022-10-31 thomas test_done "$testroot" "$ret"
133 f2900386 2022-10-31 thomas return 1
134 f2900386 2022-10-31 thomas fi
135 f2900386 2022-10-31 thomas egrep -q '\+pack-[a-f0-9]{40}.idx' $testroot/repo-list.newlines
136 f2900386 2022-10-31 thomas ret=$?
137 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
138 f2900386 2022-10-31 thomas echo "new pack index not found in ${GOTD_TEST_REPO}"
139 f2900386 2022-10-31 thomas test_done "$testroot" "$ret"
140 f2900386 2022-10-31 thomas return 1
141 f2900386 2022-10-31 thomas fi
142 f2900386 2022-10-31 thomas
143 f2900386 2022-10-31 thomas test_done "$testroot" "$ret"
144 f2900386 2022-10-31 thomas }
145 f2900386 2022-10-31 thomas
146 6110f5ef 2023-01-19 thomas test_fetch_more_history() {
147 6110f5ef 2023-01-19 thomas local testroot=`test_init fetch_more_history 1`
148 6110f5ef 2023-01-19 thomas
149 6110f5ef 2023-01-19 thomas got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
150 6110f5ef 2023-01-19 thomas ret=$?
151 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
152 6110f5ef 2023-01-19 thomas echo "got clone failed unexpectedly" >&2
153 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
154 6110f5ef 2023-01-19 thomas return 1
155 6110f5ef 2023-01-19 thomas fi
156 6110f5ef 2023-01-19 thomas
157 6110f5ef 2023-01-19 thomas got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
158 6110f5ef 2023-01-19 thomas ret=$?
159 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
160 6110f5ef 2023-01-19 thomas echo "got checkout failed unexpectedly" >&2
161 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
162 6110f5ef 2023-01-19 thomas return 1
163 6110f5ef 2023-01-19 thomas fi
164 6110f5ef 2023-01-19 thomas
165 6110f5ef 2023-01-19 thomas # Create some more commit history on the main branch.
166 6110f5ef 2023-01-19 thomas # History needs to be deep enough to trick 'git pull' into sending
167 6110f5ef 2023-01-19 thomas # a lot of 'have' lines, which triggered a bug in gotd.
168 6110f5ef 2023-01-19 thomas for i in `jot 50`; do
169 6110f5ef 2023-01-19 thomas echo "more alpha" >> $testroot/wt/alpha
170 6110f5ef 2023-01-19 thomas (cd $testroot/wt && got commit -m 'more changes' > /dev/null)
171 6110f5ef 2023-01-19 thomas done
172 6110f5ef 2023-01-19 thomas got send -b main -q -r $testroot/repo-clone
173 6110f5ef 2023-01-19 thomas ret=$?
174 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
175 6110f5ef 2023-01-19 thomas echo "got send failed unexpectedly" >&2
176 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
177 6110f5ef 2023-01-19 thomas return 1
178 6110f5ef 2023-01-19 thomas fi
179 6110f5ef 2023-01-19 thomas
180 6110f5ef 2023-01-19 thomas # create a second clone to test an incremental fetch with later
181 6110f5ef 2023-01-19 thomas got clone -q -m ${GOTD_TEST_REPO_URL} $testroot/repo-clone2
182 6110f5ef 2023-01-19 thomas ret=$?
183 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
184 6110f5ef 2023-01-19 thomas echo "got clone failed unexpectedly" >&2
185 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
186 6110f5ef 2023-01-19 thomas return 1
187 6110f5ef 2023-01-19 thomas fi
188 6110f5ef 2023-01-19 thomas # same for Git, which used to fail:
189 6110f5ef 2023-01-19 thomas # fetch-pack: protocol error: bad band #69
190 6110f5ef 2023-01-19 thomas # fatal: protocol error: bad pack header
191 6110f5ef 2023-01-19 thomas # gotsh: unexpected 'have' packet
192 6110f5ef 2023-01-19 thomas git clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone3 \
193 6110f5ef 2023-01-19 thomas >$testroot/stdout 2>$testroot/stderr
194 6110f5ef 2023-01-19 thomas ret=$?
195 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
196 6110f5ef 2023-01-19 thomas echo "git clone failed unexpectedly" >&2
197 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
198 6110f5ef 2023-01-19 thomas return 1
199 6110f5ef 2023-01-19 thomas fi
200 6110f5ef 2023-01-19 thomas
201 6110f5ef 2023-01-19 thomas # Create more commit history on the main branch
202 6110f5ef 2023-01-19 thomas echo "more alpha" >> $testroot/wt/alpha
203 6110f5ef 2023-01-19 thomas (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
204 6110f5ef 2023-01-19 thomas echo "more beta" >> $testroot/wt/beta
205 6110f5ef 2023-01-19 thomas (cd $testroot/wt && got commit -m 'more changes' > /dev/null)
206 6110f5ef 2023-01-19 thomas (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
207 6110f5ef 2023-01-19 thomas (cd $testroot/wt && got commit -m 'rm epsilon/zeta' > /dev/null)
208 6110f5ef 2023-01-19 thomas got send -b main -q -r $testroot/repo-clone
209 6110f5ef 2023-01-19 thomas ret=$?
210 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
211 6110f5ef 2023-01-19 thomas echo "got send failed unexpectedly" >&2
212 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
213 6110f5ef 2023-01-19 thomas return 1
214 6110f5ef 2023-01-19 thomas fi
215 6110f5ef 2023-01-19 thomas
216 6110f5ef 2023-01-19 thomas # Verify that the new changes can be fetched
217 6110f5ef 2023-01-19 thomas got fetch -q -r $testroot/repo-clone2
218 6110f5ef 2023-01-19 thomas ret=$?
219 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
220 6110f5ef 2023-01-19 thomas echo "got fetch failed unexpectedly" >&2
221 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
222 6110f5ef 2023-01-19 thomas return 1
223 6110f5ef 2023-01-19 thomas fi
224 6110f5ef 2023-01-19 thomas
225 6110f5ef 2023-01-19 thomas got tree -R -r $testroot/repo-clone2 > $testroot/stdout
226 6110f5ef 2023-01-19 thomas cat > $testroot/stdout.expected <<EOF
227 6110f5ef 2023-01-19 thomas alpha
228 6110f5ef 2023-01-19 thomas beta
229 6110f5ef 2023-01-19 thomas gamma/
230 6110f5ef 2023-01-19 thomas gamma/delta
231 6110f5ef 2023-01-19 thomas psi/
232 6110f5ef 2023-01-19 thomas psi/new
233 6110f5ef 2023-01-19 thomas EOF
234 6110f5ef 2023-01-19 thomas cmp -s $testroot/stdout.expected $testroot/stdout
235 6110f5ef 2023-01-19 thomas ret=$?
236 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
237 6110f5ef 2023-01-19 thomas diff -u $testroot/stdout.expected $testroot/stdout
238 6110f5ef 2023-01-19 thomas test_done "$testroot" "$ret"
239 6110f5ef 2023-01-19 thomas return 1
240 6110f5ef 2023-01-19 thomas fi
241 6110f5ef 2023-01-19 thomas
242 6110f5ef 2023-01-19 thomas # Verify that git pull works, too
243 6110f5ef 2023-01-19 thomas (cd $testroot/repo-clone3 && git pull -q > $testroot/stdout \
244 6110f5ef 2023-01-19 thomas 2> $testroot/stderr)
245 6110f5ef 2023-01-19 thomas ret=$?
246 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
247 6110f5ef 2023-01-19 thomas echo "git pull failed unexpectedly" >&2
248 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
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 test_done "$testroot" "$ret"
253 6110f5ef 2023-01-19 thomas }
254 d98779cd 2023-01-19 thomas
255 d98779cd 2023-01-19 thomas test_send_new_empty_branch() {
256 d98779cd 2023-01-19 thomas local testroot=`test_init send_new_empty_branch 1`
257 d98779cd 2023-01-19 thomas
258 d98779cd 2023-01-19 thomas got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
259 d98779cd 2023-01-19 thomas ret=$?
260 d98779cd 2023-01-19 thomas if [ $ret -ne 0 ]; then
261 d98779cd 2023-01-19 thomas echo "got clone failed unexpectedly" >&2
262 d98779cd 2023-01-19 thomas test_done "$testroot" "1"
263 d98779cd 2023-01-19 thomas return 1
264 d98779cd 2023-01-19 thomas fi
265 d98779cd 2023-01-19 thomas local commit_id=`git_show_head $testroot/repo-clone`
266 6110f5ef 2023-01-19 thomas
267 d98779cd 2023-01-19 thomas got branch -r $testroot/repo-clone -c main newbranch2 >/dev/null
268 d98779cd 2023-01-19 thomas got send -b newbranch2 -q -r $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 send 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 6110f5ef 2023-01-19 thomas
276 d98779cd 2023-01-19 thomas # Verify that the send operation worked fine.
277 d98779cd 2023-01-19 thomas got clone -l ${GOTD_TEST_REPO_URL} | grep newbranch2 > $testroot/stdout
278 d98779cd 2023-01-19 thomas ret=$?
279 d98779cd 2023-01-19 thomas if [ $ret -ne 0 ]; then
280 d98779cd 2023-01-19 thomas echo "got clone -l failed unexpectedly" >&2
281 d98779cd 2023-01-19 thomas test_done "$testroot" "1"
282 d98779cd 2023-01-19 thomas return 1
283 d98779cd 2023-01-19 thomas fi
284 d98779cd 2023-01-19 thomas
285 d98779cd 2023-01-19 thomas echo "refs/heads/newbranch2: $commit_id" > $testroot/stdout.expected
286 d98779cd 2023-01-19 thomas cmp -s $testroot/stdout.expected $testroot/stdout
287 d98779cd 2023-01-19 thomas ret=$?
288 d98779cd 2023-01-19 thomas if [ $ret -ne 0 ]; then
289 d98779cd 2023-01-19 thomas diff -u $testroot/stdout.expected $testroot/stdout
290 d98779cd 2023-01-19 thomas fi
291 d98779cd 2023-01-19 thomas
292 d98779cd 2023-01-19 thomas test_done "$testroot" "$ret"
293 d98779cd 2023-01-19 thomas }
294 49563dfb 2023-01-28 thomas
295 49563dfb 2023-01-28 thomas test_delete_branch() {
296 49563dfb 2023-01-28 thomas local testroot=`test_init delete_branch 1`
297 49563dfb 2023-01-28 thomas
298 a9020bab 2023-01-28 thomas got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
299 49563dfb 2023-01-28 thomas ret=$?
300 49563dfb 2023-01-28 thomas if [ $ret -ne 0 ]; then
301 49563dfb 2023-01-28 thomas echo "got clone failed unexpectedly" >&2
302 49563dfb 2023-01-28 thomas test_done "$testroot" 1
303 49563dfb 2023-01-28 thomas return 1
304 49563dfb 2023-01-28 thomas fi
305 49563dfb 2023-01-28 thomas
306 49563dfb 2023-01-28 thomas got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
307 49563dfb 2023-01-28 thomas ret=$?
308 49563dfb 2023-01-28 thomas if [ $ret -ne 0 ]; then
309 49563dfb 2023-01-28 thomas echo "got checkout failed unexpectedly" >&2
310 49563dfb 2023-01-28 thomas test_done "$testroot" 1
311 49563dfb 2023-01-28 thomas return 1
312 49563dfb 2023-01-28 thomas fi
313 49563dfb 2023-01-28 thomas
314 49563dfb 2023-01-28 thomas (cd $testroot/wt && got branch foo) >/dev/null
315 49563dfb 2023-01-28 thomas ret=$?
316 49563dfb 2023-01-28 thomas if [ $ret -ne 0 ]; then
317 49563dfb 2023-01-28 thomas echo "got branch failed unexpectedly" >&2
318 49563dfb 2023-01-28 thomas test_done "$testroot" 1
319 49563dfb 2023-01-28 thomas return 1
320 49563dfb 2023-01-28 thomas fi
321 49563dfb 2023-01-28 thomas
322 49563dfb 2023-01-28 thomas echo modified alpha > $testroot/wt/alpha
323 49563dfb 2023-01-28 thomas (cd $testroot/wt && got commit -m 'edit alpha') >/dev/null
324 49563dfb 2023-01-28 thomas ret=$?
325 49563dfb 2023-01-28 thomas if [ $ret -ne 0 ]; then
326 49563dfb 2023-01-28 thomas echo "got commit failed unexpectedly" >&2
327 49563dfb 2023-01-28 thomas test_done "$testroot" 1
328 49563dfb 2023-01-28 thomas return 1
329 49563dfb 2023-01-28 thomas fi
330 a9020bab 2023-01-28 thomas
331 a9020bab 2023-01-28 thomas local foo_id=`git_show_branch_head "$testroot/repo-clone" foo`
332 a9020bab 2023-01-28 thomas local main_id=`git_show_branch_head "$testroot/repo-clone" main`
333 a9020bab 2023-01-28 thomas local nb_id=`git_show_branch_head "$testroot/repo-clone" newbranch`
334 a9020bab 2023-01-28 thomas local nb2_id=`git_show_branch_head "$testroot/repo-clone" newbranch2`
335 a9020bab 2023-01-28 thomas local tag_id=`got ref -r "$testroot/repo-clone" -l refs/tags/1.0 | \
336 a9020bab 2023-01-28 thomas awk '{print $2}'`
337 49563dfb 2023-01-28 thomas
338 49563dfb 2023-01-28 thomas if ! got send -q -r $testroot/repo-clone -b foo; then
339 49563dfb 2023-01-28 thomas echo "got send failed unexpectedly" >&2
340 49563dfb 2023-01-28 thomas test_done "$testroot" 1
341 49563dfb 2023-01-28 thomas return 1
342 49563dfb 2023-01-28 thomas fi
343 49563dfb 2023-01-28 thomas
344 a9020bab 2023-01-28 thomas got fetch -q -r $testroot/repo-clone -l >$testroot/refs
345 a9020bab 2023-01-28 thomas cat <<EOF >$testroot/refs.expected
346 a9020bab 2023-01-28 thomas HEAD: refs/heads/main
347 a9020bab 2023-01-28 thomas HEAD: $main_id
348 a9020bab 2023-01-28 thomas refs/heads/foo: $foo_id
349 a9020bab 2023-01-28 thomas refs/heads/main: $main_id
350 a9020bab 2023-01-28 thomas refs/heads/newbranch: $nb_id
351 a9020bab 2023-01-28 thomas refs/heads/newbranch2: $nb2_id
352 a9020bab 2023-01-28 thomas refs/tags/1.0: $tag_id
353 a9020bab 2023-01-28 thomas EOF
354 a9020bab 2023-01-28 thomas if ! cmp -s $testroot/refs.expected $testroot/refs; then
355 a9020bab 2023-01-28 thomas diff -u $testroot/refs.expected $testroot/refs
356 a9020bab 2023-01-28 thomas test_done "$testroot" 1
357 a9020bab 2023-01-28 thomas return 1
358 a9020bab 2023-01-28 thomas fi
359 a9020bab 2023-01-28 thomas
360 a9020bab 2023-01-28 thomas (cd $testroot/repo-clone && git push -d origin foo) >/dev/null 2>&1
361 49563dfb 2023-01-28 thomas ret=$?
362 49563dfb 2023-01-28 thomas if [ $ret -ne 0 ]; then
363 a9020bab 2023-01-28 thomas echo "git push -d failed unexpectedly" >&2
364 a9020bab 2023-01-28 thomas test_done "$testroot" 1
365 a9020bab 2023-01-28 thomas return 1
366 a9020bab 2023-01-28 thomas fi
367 a9020bab 2023-01-28 thomas
368 a9020bab 2023-01-28 thomas got fetch -q -r $testroot/repo-clone -l >$testroot/refs
369 a9020bab 2023-01-28 thomas cat <<EOF >$testroot/refs.expected
370 a9020bab 2023-01-28 thomas HEAD: refs/heads/main
371 a9020bab 2023-01-28 thomas HEAD: $main_id
372 a9020bab 2023-01-28 thomas refs/heads/main: $main_id
373 a9020bab 2023-01-28 thomas refs/heads/newbranch: $nb_id
374 a9020bab 2023-01-28 thomas refs/heads/newbranch2: $nb2_id
375 a9020bab 2023-01-28 thomas refs/tags/1.0: $tag_id
376 a9020bab 2023-01-28 thomas EOF
377 a9020bab 2023-01-28 thomas if ! cmp -s $testroot/refs.expected $testroot/refs; then
378 a9020bab 2023-01-28 thomas diff -u $testroot/refs.expected $testroot/refs
379 49563dfb 2023-01-28 thomas test_done "$testroot" 1
380 49563dfb 2023-01-28 thomas return 1
381 49563dfb 2023-01-28 thomas fi
382 d98779cd 2023-01-19 thomas
383 a9020bab 2023-01-28 thomas # try to delete multiple branches in one go
384 a9020bab 2023-01-28 thomas got send -r $testroot/repo-clone -d newbranch -d newbranch2 \
385 a9020bab 2023-01-28 thomas >$testroot/stdout
386 a9020bab 2023-01-28 thomas ret=$?
387 a9020bab 2023-01-28 thomas if [ $ret -ne 0 ]; then
388 a9020bab 2023-01-28 thomas echo "got send with multiple -d failed unexpectedly" >&2
389 a9020bab 2023-01-28 thomas test_done "$testroot" 1
390 a9020bab 2023-01-28 thomas return 1
391 a9020bab 2023-01-28 thomas fi
392 a9020bab 2023-01-28 thomas
393 49563dfb 2023-01-28 thomas cat <<EOF >$testroot/stdout.expected
394 49563dfb 2023-01-28 thomas Connecting to "origin" ${GOTD_TEST_REPO_URL}
395 a9020bab 2023-01-28 thomas Server has deleted refs/heads/newbranch2
396 a9020bab 2023-01-28 thomas Server has deleted refs/heads/newbranch
397 49563dfb 2023-01-28 thomas EOF
398 49563dfb 2023-01-28 thomas if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
399 49563dfb 2023-01-28 thomas diff -u $testroot/stdout.expected $testroot/stdout
400 49563dfb 2023-01-28 thomas test_done "$testroot" 1
401 49563dfb 2023-01-28 thomas return 1
402 49563dfb 2023-01-28 thomas fi
403 d98779cd 2023-01-19 thomas
404 a9020bab 2023-01-28 thomas got fetch -q -r $testroot/repo-clone -l >$testroot/refs
405 a9020bab 2023-01-28 thomas cat <<EOF >$testroot/refs.expected
406 a9020bab 2023-01-28 thomas HEAD: refs/heads/main
407 a9020bab 2023-01-28 thomas HEAD: $main_id
408 a9020bab 2023-01-28 thomas refs/heads/main: $main_id
409 a9020bab 2023-01-28 thomas refs/tags/1.0: $tag_id
410 a9020bab 2023-01-28 thomas EOF
411 a9020bab 2023-01-28 thomas if ! cmp -s $testroot/refs.expected $testroot/refs; then
412 a9020bab 2023-01-28 thomas diff -u $testroot/refs.expected $testroot/refs
413 a9020bab 2023-01-28 thomas test_done "$testroot" 1
414 a9020bab 2023-01-28 thomas return 1
415 a9020bab 2023-01-28 thomas fi
416 a9020bab 2023-01-28 thomas
417 49563dfb 2023-01-28 thomas # now try again but while also updating another branch
418 49563dfb 2023-01-28 thomas # other than deleting `foo'.
419 49563dfb 2023-01-28 thomas
420 49563dfb 2023-01-28 thomas (cd $testroot/wt && got up -b main && \
421 49563dfb 2023-01-28 thomas echo 'more alpha' > alpha && \
422 49563dfb 2023-01-28 thomas got commit -m 'edit alpha on main' && \
423 49563dfb 2023-01-28 thomas got send -q -b foo) >/dev/null
424 a9020bab 2023-01-28 thomas main_id=`git_show_branch_head "$testroot/repo-clone" main`
425 49563dfb 2023-01-28 thomas
426 49563dfb 2023-01-28 thomas got send -r $testroot/repo-clone -d foo -b main | \
427 49563dfb 2023-01-28 thomas grep '^Server has' >$testroot/stdout
428 49563dfb 2023-01-28 thomas ret=$?
429 49563dfb 2023-01-28 thomas if [ $ret -ne 0 ]; then
430 49563dfb 2023-01-28 thomas echo "got send -d foo -b main failed unexpectedly" >&2
431 49563dfb 2023-01-28 thomas test_done "$testroot" 1
432 49563dfb 2023-01-28 thomas return 1
433 49563dfb 2023-01-28 thomas fi
434 49563dfb 2023-01-28 thomas
435 49563dfb 2023-01-28 thomas cat <<EOF >$testroot/stdout.expected
436 49563dfb 2023-01-28 thomas Server has accepted refs/heads/main
437 49563dfb 2023-01-28 thomas Server has deleted refs/heads/foo
438 49563dfb 2023-01-28 thomas EOF
439 49563dfb 2023-01-28 thomas if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
440 49563dfb 2023-01-28 thomas diff -u $testroot/stdout.expected $testroot/stdout
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 a9020bab 2023-01-28 thomas got fetch -q -r $testroot/repo-clone -l >$testroot/refs
446 a9020bab 2023-01-28 thomas cat <<EOF >$testroot/refs.expected
447 a9020bab 2023-01-28 thomas HEAD: refs/heads/main
448 a9020bab 2023-01-28 thomas HEAD: $main_id
449 a9020bab 2023-01-28 thomas refs/heads/main: $main_id
450 a9020bab 2023-01-28 thomas refs/tags/1.0: $tag_id
451 a9020bab 2023-01-28 thomas EOF
452 a9020bab 2023-01-28 thomas if ! cmp -s $testroot/refs.expected $testroot/refs; then
453 a9020bab 2023-01-28 thomas diff -u $testroot/refs.expected $testroot/refs
454 a9020bab 2023-01-28 thomas test_done "$testroot" 1
455 a9020bab 2023-01-28 thomas return 1
456 a9020bab 2023-01-28 thomas fi
457 a9020bab 2023-01-28 thomas
458 49563dfb 2023-01-28 thomas test_done "$testroot" 0
459 49563dfb 2023-01-28 thomas }
460 49563dfb 2023-01-28 thomas
461 f2900386 2022-10-31 thomas test_parseargs "$@"
462 f2900386 2022-10-31 thomas run_test test_send_basic
463 6110f5ef 2023-01-19 thomas run_test test_fetch_more_history
464 d98779cd 2023-01-19 thomas run_test test_send_new_empty_branch
465 49563dfb 2023-01-28 thomas run_test test_delete_branch