Blame


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