From: Stefan Sperling Subject: Re: gotd: initial implementation of the delete-refs capability To: Omar Polo Cc: gameoftrees@openbsd.org Date: Sat, 28 Jan 2023 12:16:54 +0100 On Sat, Jan 28, 2023 at 10:11:04AM +0100, Omar Polo wrote: > On 2023/01/27 20:37:02 +0100, Stefan Sperling wrote: > > Could we verify the ref-list reported by the server via got clone -l, > > before and after deletion? > > Sure, it's a good idea. While here I've noticed that in the repo > there are also two other branches so diff belows extend the test to > also try deleting multiple references in one go. > Great, thanks! Ok. The more test coverage, the better. > diff /home/op/w/gotd > commit - 9a8e357c727600cb61ac6ec4c83259fa6d9a3081 > path + /home/op/w/gotd > blob - b48e2b54f360c89a3ce5d4c9e38d4dd5a7a3532f > file + regress/gotd/repo_write.sh > --- regress/gotd/repo_write.sh > +++ regress/gotd/repo_write.sh > @@ -295,7 +295,7 @@ test_delete_branch() { > test_delete_branch() { > local testroot=`test_init delete_branch 1` > > - got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone > + got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone > ret=$? > if [ $ret -ne 0 ]; then > echo "got clone failed unexpectedly" >&2 > @@ -328,12 +328,35 @@ test_delete_branch() { > return 1 > fi > > + local foo_id=`git_show_branch_head "$testroot/repo-clone" foo` > + local main_id=`git_show_branch_head "$testroot/repo-clone" main` > + local nb_id=`git_show_branch_head "$testroot/repo-clone" newbranch` > + local nb2_id=`git_show_branch_head "$testroot/repo-clone" newbranch2` > + local tag_id=`got ref -r "$testroot/repo-clone" -l refs/tags/1.0 | \ > + awk '{print $2}'` > + > if ! got send -q -r $testroot/repo-clone -b foo; then > echo "got send failed unexpectedly" >&2 > test_done "$testroot" 1 > return 1 > fi > > + got fetch -q -r $testroot/repo-clone -l >$testroot/refs > + cat <$testroot/refs.expected > +HEAD: refs/heads/main > +HEAD: $main_id > +refs/heads/foo: $foo_id > +refs/heads/main: $main_id > +refs/heads/newbranch: $nb_id > +refs/heads/newbranch2: $nb2_id > +refs/tags/1.0: $tag_id > +EOF > + if ! cmp -s $testroot/refs.expected $testroot/refs; then > + diff -u $testroot/refs.expected $testroot/refs > + test_done "$testroot" 1 > + return 1 > + fi > + > got send -r $testroot/repo-clone -d foo >$testroot/stdout > ret=$? > if [ $ret -ne 0 ]; then > @@ -352,6 +375,55 @@ EOF > return 1 > fi > > + got fetch -q -r $testroot/repo-clone -l >$testroot/refs > + cat <$testroot/refs.expected > +HEAD: refs/heads/main > +HEAD: $main_id > +refs/heads/main: $main_id > +refs/heads/newbranch: $nb_id > +refs/heads/newbranch2: $nb2_id > +refs/tags/1.0: $tag_id > +EOF > + if ! cmp -s $testroot/refs.expected $testroot/refs; then > + diff -u $testroot/refs.expected $testroot/refs > + test_done "$testroot" 1 > + return 1 > + fi > + > + # try to delete multiple branches in one go > + got send -r $testroot/repo-clone -d newbranch -d newbranch2 \ > + >$testroot/stdout > + ret=$? > + if [ $ret -ne 0 ]; then > + echo "got send with multiple -d failed unexpectedly" >&2 > + test_done "$testroot" 1 > + return 1 > + fi > + > + cat <$testroot/stdout.expected > +Connecting to "origin" ${GOTD_TEST_REPO_URL} > +Server has deleted refs/heads/newbranch2 > +Server has deleted refs/heads/newbranch > +EOF > + if ! cmp -s $testroot/stdout.expected $testroot/stdout; then > + diff -u $testroot/stdout.expected $testroot/stdout > + test_done "$testroot" 1 > + return 1 > + fi > + > + got fetch -q -r $testroot/repo-clone -l >$testroot/refs > + cat <$testroot/refs.expected > +HEAD: refs/heads/main > +HEAD: $main_id > +refs/heads/main: $main_id > +refs/tags/1.0: $tag_id > +EOF > + if ! cmp -s $testroot/refs.expected $testroot/refs; then > + diff -u $testroot/refs.expected $testroot/refs > + test_done "$testroot" 1 > + return 1 > + fi > + > # now try again but while also updating another branch > # other than deleting `foo'. > > @@ -359,6 +431,7 @@ EOF > echo 'more alpha' > alpha && \ > got commit -m 'edit alpha on main' && \ > got send -q -b foo) >/dev/null > + main_id=`git_show_branch_head "$testroot/repo-clone" main` > > got send -r $testroot/repo-clone -d foo -b main | \ > grep '^Server has' >$testroot/stdout > @@ -379,6 +452,19 @@ EOF > return 1 > fi > > + got fetch -q -r $testroot/repo-clone -l >$testroot/refs > + cat <$testroot/refs.expected > +HEAD: refs/heads/main > +HEAD: $main_id > +refs/heads/main: $main_id > +refs/tags/1.0: $tag_id > +EOF > + if ! cmp -s $testroot/refs.expected $testroot/refs; then > + diff -u $testroot/refs.expected $testroot/refs > + test_done "$testroot" 1 > + return 1 > + fi > + > test_done "$testroot" 0 > } > > >