3 # Copyright (c) 2022 Stefan Sperling <stsp@openbsd.org>
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ../cmdline/common.sh
21 local testroot=`test_init send_basic 1`
23 ls -R ${GOTD_TEST_REPO}/objects/pack > $testroot/repo-list.before
25 got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
27 if [ $ret -ne 0 ]; then
28 echo "got clone failed unexpectedly" >&2
29 test_done "$testroot" "1"
33 # create a second clone to test an incremental fetch with later
34 got clone -q -m ${GOTD_TEST_REPO_URL} $testroot/repo-clone2
36 if [ $ret -ne 0 ]; then
37 echo "got clone failed unexpectedly" >&2
38 test_done "$testroot" "1"
42 git clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone3 \
43 >$testroot/stdout 2>$testroot/stderr
45 if [ $ret -ne 0 ]; then
46 echo "git clone failed unexpectedly" >&2
47 test_done "$testroot" "1"
51 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
53 if [ $ret -ne 0 ]; then
54 echo "got checkout failed unexpectedly" >&2
55 test_done "$testroot" "1"
59 mkdir $testroot/wt/psi
60 echo "new" > $testroot/wt/psi/new
61 (cd $testroot/wt && got add psi/new > /dev/null)
62 echo "more alpha" >> $testroot/wt/alpha
63 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
64 (cd $testroot/wt && got branch newbranch >/dev/null)
65 echo "even more alpha" >> $testroot/wt/alpha
66 (cd $testroot/wt && got commit -m 'more changes' > /dev/null)
67 got tag -r $testroot/repo-clone -m "tagging 1.0" 1.0 >/dev/null
69 got send -b main -b newbranch -q -r $testroot/repo-clone -t 1.0
71 if [ $ret -ne 0 ]; then
72 echo "got send failed unexpectedly" >&2
73 test_done "$testroot" "1"
77 # Verify that the send operation worked fine.
78 got fetch -q -r $testroot/repo-clone2
80 if [ $ret -ne 0 ]; then
81 echo "got fetch failed unexpectedly" >&2
82 test_done "$testroot" "1"
86 got tree -R -r $testroot/repo-clone2 > $testroot/stdout
87 cat > $testroot/stdout.expected <<EOF
97 cmp -s $testroot/stdout.expected $testroot/stdout
99 if [ $ret -ne 0 ]; then
100 diff -u $testroot/stdout.expected $testroot/stdout
101 test_done "$testroot" "$ret"
105 # Verify that git pull works, too
106 (cd $testroot/repo-clone3 && git pull -q > $testroot/stdout \
109 if [ $ret -ne 0 ]; then
110 echo "git pull failed unexpectedly" >&2
111 test_done "$testroot" "1"
115 # Verify that git push reports no changes to send and no error.
116 (cd $testroot/repo-clone3 && git push -q > $testroot/stdout \
119 if [ $ret -ne 0 ]; then
120 echo "git push failed unexpectedly" >&2
121 test_done "$testroot" "1"
125 # sending to a repository should result in a new pack file
126 ls -R ${GOTD_TEST_REPO}/objects/pack > $testroot/repo-list.after
127 diff -u $testroot/repo-list.before $testroot/repo-list.after \
128 > $testroot/repo-list.diff
129 grep '^+[^+]' < $testroot/repo-list.diff > $testroot/repo-list.newlines
130 nplus=`wc -l < $testroot/repo-list.newlines | tr -d ' '`
131 if [ "$nplus" != "2" ]; then
132 echo "$nplus new files created:"
133 cat $testroot/repo-list.diff
134 test_done "$testroot" "$ret"
137 egrep -q '\+pack-[a-f0-9]{40}.pack' $testroot/repo-list.newlines
139 if [ $ret -ne 0 ]; then
140 echo "new pack file not found in ${GOTD_TEST_REPO}"
141 cat $testroot/repo-list.newlines
142 test_done "$testroot" "$ret"
145 egrep -q '\+pack-[a-f0-9]{40}.idx' $testroot/repo-list.newlines
147 if [ $ret -ne 0 ]; then
148 echo "new pack index not found in ${GOTD_TEST_REPO}"
149 test_done "$testroot" "$ret"
153 test_done "$testroot" "$ret"
156 test_fetch_more_history() {
157 local testroot=`test_init fetch_more_history 1`
159 got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
161 if [ $ret -ne 0 ]; then
162 echo "got clone failed unexpectedly" >&2
163 test_done "$testroot" "1"
167 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
169 if [ $ret -ne 0 ]; then
170 echo "got checkout failed unexpectedly" >&2
171 test_done "$testroot" "1"
175 # Create some more commit history on the main branch.
176 # History needs to be deep enough to trick 'git pull' into sending
177 # a lot of 'have' lines, which triggered a bug in gotd.
178 for i in `jot 50`; do
179 echo "more alpha" >> $testroot/wt/alpha
180 (cd $testroot/wt && got commit -m 'more changes' > /dev/null)
182 got send -b main -q -r $testroot/repo-clone
184 if [ $ret -ne 0 ]; then
185 echo "got send failed unexpectedly" >&2
186 test_done "$testroot" "1"
190 # create a second clone to test an incremental fetch with later
191 got clone -q -m ${GOTD_TEST_REPO_URL} $testroot/repo-clone2
193 if [ $ret -ne 0 ]; then
194 echo "got clone failed unexpectedly" >&2
195 test_done "$testroot" "1"
198 # same for Git, which used to fail:
199 # fetch-pack: protocol error: bad band #69
200 # fatal: protocol error: bad pack header
201 # gotsh: unexpected 'have' packet
202 git clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone3 \
203 >$testroot/stdout 2>$testroot/stderr
205 if [ $ret -ne 0 ]; then
206 echo "git clone failed unexpectedly" >&2
207 test_done "$testroot" "1"
211 # Create more commit history on the main branch
212 echo "more alpha" >> $testroot/wt/alpha
213 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
214 echo "more beta" >> $testroot/wt/beta
215 (cd $testroot/wt && got commit -m 'more changes' > /dev/null)
216 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
217 (cd $testroot/wt && got commit -m 'rm epsilon/zeta' > /dev/null)
218 got send -b main -q -r $testroot/repo-clone
220 if [ $ret -ne 0 ]; then
221 echo "got send failed unexpectedly" >&2
222 test_done "$testroot" "1"
226 # Verify that the new changes can be fetched
227 got fetch -q -r $testroot/repo-clone2
229 if [ $ret -ne 0 ]; then
230 echo "got fetch failed unexpectedly" >&2
231 test_done "$testroot" "1"
235 got tree -R -r $testroot/repo-clone2 > $testroot/stdout
236 cat > $testroot/stdout.expected <<EOF
244 cmp -s $testroot/stdout.expected $testroot/stdout
246 if [ $ret -ne 0 ]; then
247 diff -u $testroot/stdout.expected $testroot/stdout
248 test_done "$testroot" "$ret"
252 # Verify that git pull works, too
253 (cd $testroot/repo-clone3 && git pull -q > $testroot/stdout \
256 if [ $ret -ne 0 ]; then
257 echo "git pull failed unexpectedly" >&2
258 test_done "$testroot" "1"
262 test_done "$testroot" "$ret"
265 test_send_new_empty_branch() {
266 local testroot=`test_init send_new_empty_branch 1`
268 got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
270 if [ $ret -ne 0 ]; then
271 echo "got clone failed unexpectedly" >&2
272 test_done "$testroot" "1"
275 local commit_id=`git_show_head $testroot/repo-clone`
277 got branch -r $testroot/repo-clone -c main newbranch2 >/dev/null
278 got send -b newbranch2 -q -r $testroot/repo-clone
280 if [ $ret -ne 0 ]; then
281 echo "got send failed unexpectedly" >&2
282 test_done "$testroot" "1"
286 # Verify that the send operation worked fine.
287 got clone -l ${GOTD_TEST_REPO_URL} | grep newbranch2 > $testroot/stdout
289 if [ $ret -ne 0 ]; then
290 echo "got clone -l failed unexpectedly" >&2
291 test_done "$testroot" "1"
295 echo "refs/heads/newbranch2: $commit_id" > $testroot/stdout.expected
296 cmp -s $testroot/stdout.expected $testroot/stdout
298 if [ $ret -ne 0 ]; then
299 diff -u $testroot/stdout.expected $testroot/stdout
302 test_done "$testroot" "$ret"
305 test_delete_branch() {
306 local testroot=`test_init delete_branch 1`
308 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
310 if [ $ret -ne 0 ]; then
311 echo "got clone failed unexpectedly" >&2
312 test_done "$testroot" 1
316 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
318 if [ $ret -ne 0 ]; then
319 echo "got checkout failed unexpectedly" >&2
320 test_done "$testroot" 1
324 (cd $testroot/wt && got branch foo) >/dev/null
326 if [ $ret -ne 0 ]; then
327 echo "got branch failed unexpectedly" >&2
328 test_done "$testroot" 1
332 echo modified alpha > $testroot/wt/alpha
333 (cd $testroot/wt && got commit -m 'edit alpha') >/dev/null
335 if [ $ret -ne 0 ]; then
336 echo "got commit failed unexpectedly" >&2
337 test_done "$testroot" 1
341 local foo_id=`git_show_branch_head "$testroot/repo-clone" foo`
342 local main_id=`git_show_branch_head "$testroot/repo-clone" main`
343 local nb_id=`git_show_branch_head "$testroot/repo-clone" newbranch`
344 local nb2_id=`git_show_branch_head "$testroot/repo-clone" newbranch2`
345 local tag_id=`got ref -r "$testroot/repo-clone" -l refs/tags/1.0 | \
348 if ! got send -q -r $testroot/repo-clone -b foo; then
349 echo "got send failed unexpectedly" >&2
350 test_done "$testroot" 1
354 got fetch -q -r $testroot/repo-clone -l >$testroot/refs
355 cat <<EOF >$testroot/refs.expected
356 HEAD: refs/heads/main
358 refs/heads/foo: $foo_id
359 refs/heads/main: $main_id
360 refs/heads/newbranch: $nb_id
361 refs/heads/newbranch2: $nb2_id
362 refs/tags/1.0: $tag_id
364 if ! cmp -s $testroot/refs.expected $testroot/refs; then
365 diff -u $testroot/refs.expected $testroot/refs
366 test_done "$testroot" 1
370 (cd $testroot/repo-clone && git push -d origin foo) >/dev/null 2>&1
372 if [ $ret -ne 0 ]; then
373 echo "git push -d failed unexpectedly" >&2
374 test_done "$testroot" 1
378 got fetch -q -r $testroot/repo-clone -l >$testroot/refs
379 cat <<EOF >$testroot/refs.expected
380 HEAD: refs/heads/main
382 refs/heads/main: $main_id
383 refs/heads/newbranch: $nb_id
384 refs/heads/newbranch2: $nb2_id
385 refs/tags/1.0: $tag_id
387 if ! cmp -s $testroot/refs.expected $testroot/refs; then
388 diff -u $testroot/refs.expected $testroot/refs
389 test_done "$testroot" 1
393 # try to delete multiple branches in one go
394 got send -r $testroot/repo-clone -d newbranch -d newbranch2 \
397 if [ $ret -ne 0 ]; then
398 echo "got send with multiple -d failed unexpectedly" >&2
399 test_done "$testroot" 1
403 cat <<EOF >$testroot/stdout.expected
404 Connecting to "origin" ${GOTD_TEST_REPO_URL}
405 Server has deleted refs/heads/newbranch2
406 Server has deleted refs/heads/newbranch
408 if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
409 diff -u $testroot/stdout.expected $testroot/stdout
410 test_done "$testroot" 1
414 got fetch -q -r $testroot/repo-clone -l >$testroot/refs
415 cat <<EOF >$testroot/refs.expected
416 HEAD: refs/heads/main
418 refs/heads/main: $main_id
419 refs/tags/1.0: $tag_id
421 if ! cmp -s $testroot/refs.expected $testroot/refs; then
422 diff -u $testroot/refs.expected $testroot/refs
423 test_done "$testroot" 1
427 # now try again but while also updating another branch
428 # other than deleting `foo'.
430 (cd $testroot/wt && got up -b main && \
431 echo 'more alpha' > alpha && \
432 got commit -m 'edit alpha on main' && \
433 got send -q -b foo) >/dev/null
434 main_id=`git_show_branch_head "$testroot/repo-clone" main`
436 got send -r $testroot/repo-clone -d foo -b main | \
437 grep '^Server has' >$testroot/stdout
439 if [ $ret -ne 0 ]; then
440 echo "got send -d foo -b main failed unexpectedly" >&2
441 test_done "$testroot" 1
445 cat <<EOF >$testroot/stdout.expected
446 Server has accepted refs/heads/main
447 Server has deleted refs/heads/foo
449 if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
450 diff -u $testroot/stdout.expected $testroot/stdout
451 test_done "$testroot" 1
455 got fetch -q -r $testroot/repo-clone -l >$testroot/refs
456 cat <<EOF >$testroot/refs.expected
457 HEAD: refs/heads/main
459 refs/heads/main: $main_id
460 refs/tags/1.0: $tag_id
462 if ! cmp -s $testroot/refs.expected $testroot/refs; then
463 diff -u $testroot/refs.expected $testroot/refs
464 test_done "$testroot" 1
468 test_done "$testroot" 0
471 test_rewind_branch() {
472 local testroot=`test_init rewind_branch 1`
474 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
476 if [ $ret -ne 0 ]; then
477 echo "got clone failed unexpectedly" >&2
478 test_done "$testroot" 1
482 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
484 if [ $ret -ne 0 ]; then
485 echo "got checkout failed unexpectedly" >&2
486 test_done "$testroot" 1
490 (cd $testroot/wt && got branch foo) >/dev/null
492 if [ $ret -ne 0 ]; then
493 echo "got branch failed unexpectedly" >&2
494 test_done "$testroot" 1
498 echo modified alpha > $testroot/wt/alpha
499 (cd $testroot/wt && got commit -m 'edit alpha') >/dev/null
501 if [ $ret -ne 0 ]; then
502 echo "got commit failed unexpectedly" >&2
503 test_done "$testroot" 1
507 if ! got send -q -r $testroot/repo-clone -b foo; then
508 echo "got send failed unexpectedly" >&2
509 test_done "$testroot" 1
513 local foo_id=`git_show_branch_head "$testroot/repo-clone" foo`
514 local main_id=`git_show_branch_head "$testroot/repo-clone" main`
515 local tag_id=`got ref -r "$testroot/repo-clone" -l refs/tags/1.0 | \
518 (cd $testroot/wt && got update -c $main_id) >/dev/null
520 if [ $ret -ne 0 ]; then
521 echo "got update failed unexpectedly" >&2
522 test_done "$testroot" 1
526 (cd $testroot/wt && got histedit -d) >/dev/null
528 if [ $ret -ne 0 ]; then
529 echo "got histedit failed unexpectedly" >&2
530 test_done "$testroot" 1
534 if ! got send -q -r $testroot/repo-clone -f -b foo; then
535 echo "got send failed unexpectedly" >&2
536 test_done "$testroot" 1
540 got fetch -q -r $testroot/repo-clone -l >$testroot/refs
541 cat <<EOF >$testroot/refs.expected
542 HEAD: refs/heads/main
544 refs/heads/foo: $main_id
545 refs/heads/main: $main_id
546 refs/tags/1.0: $tag_id
548 if ! cmp -s $testroot/refs.expected $testroot/refs; then
549 diff -u $testroot/refs.expected $testroot/refs
550 test_done "$testroot" 1
554 test_done "$testroot" 0
558 run_test test_send_basic
559 run_test test_fetch_more_history
560 run_test test_send_new_empty_branch
561 run_test test_delete_branch
562 run_test test_rewind_branch