#! /bin/sh

set -e

NAME=$1
VERSION=$2
REVISION=$3
PY2DST_VERSION=$4
TARBALL=`find .. -maxdepth 1 -type f -name "${NAME}_${VERSION}.orig.tar.*" -printf %f -quit`

# do nothing if .git directory exists
test \! -d .git || exit 0
# make sure needed tools are installed
test -x "/usr/bin/pristine-tar" || (echo "E: please install pristine-tar package"; exit 1)
test -x "/usr/bin/gbp" || (echo "E: please install git-buildpackage package"; exit 1)

git init --initial-branch=debian/master
git remote add origin ssh://git@salsa.debian.org/python-team/packages/${NAME}.git
gbp import-orig "../$TARBALL" --pristine-tar --upstream-version=${VERSION}

git add debian/*
git commit -a -m "add initial Debian packaging; autogenerated by py2dsp/${PY2DST_VERSION}"

if grep -q SALSA_TOKEN $HOME/.devscripts
then
  salsa --group python-team/packages --kgb --irc-channel=debian-python-changes --tagpending create_repo ${NAME}
  echo 'I: repository created on Salsa.debian.org'
  git push --all --set-upstream
  git push --tags
  echo 'I: pushed to salsa the current package and tags'
else
  echo 'I: to create remote repository go to https://salsa.debian.org/python-team/packages and click on "New project" link'
  echo '   (https://salsa.debian.org/projects/new?namespace_id=9360)'
fi

echo "I: to push (after reviewing all files) changes to DPT's repo:"
echo "   git push --set-upstream origin --all"
