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