#!/bin/bash
set -e
. tests/lib

t-dependencies git-debpush DEBORIG python3-pygit2

# So far we just test that dgit can be made to invoke
# 'mini-git-tag-fsck --prepare' and that doing so produces something.
# Once we have 'mini-git-tag-fsck --audit', we will also want these:
#
# - test an rpush, either here or in tests/tests/{rpush,rpush-*},
#   and check the .git.tar.xz ends up on the (fake) mirror
#
# - for (at least) linear, gbp and gdr workflows with nonempty deltas,
#   in t-splitbrain-pushed-good-start or similar,
#
#   * run 'mini-git-tag-fsck --audit',
#     and check the output is right given the thing we pushed
#
#   * unpack the .git.tar.xz and check that we have enough history to
#     reproduce the maintainer view.
#     For linear, we should test empty d/patches, since that requires
#     the linearisation algorithm to walk back to the upstream.
#     For gdr, we will want to start with d/patches not generated too,
#     e.g. by doing
#       % git debrebase
#       % gbp dch --commit --qa --ignore-branch debian/changelog
#       % git debrebase stitch
#     before the push.  Then when we unpack the .git.tar.xz, we can
#     test whether we have enough history by seeing whether
#     'git debrebase make-patches' succeeds.

t-setup-import gbp

t-debpolicy

cd $p

git deborig

${DGIT_DEBPUSH_TEST-git debpush} \
    --distro=test-dummy -u Senatus --gbp --no-push

utag="upstream/${v%-*}"
t-dgit -wgf --quilt=gbp --tag2upload-builder-mode \
       --tag2upload-upstream="$utag" \
       --tag2upload-upstream-commit="$(git rev-list -1 "$utag")" \
       build-source

cd ..

gtx="${p}_${v}.git.tar.xz"
test -f "$gtx"
fgrep "$gtx" "${p}_${v}_source.changes"

t-ok
