#! /bin/sh

set -e

NAME=$1
VERSION=$2
REVISION=$3
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
git remote add origin ssh://git@salsa.debian.org/python-team/applications/${NAME}.git
git checkout -b upstream
echo debian > .git/info/exclude
git add .
git commit -m "import ${TARBALL}"
pristine-tar commit ../${TARBALL} upstream

git checkout -b debian/master
rm .git/info/exclude
git add debian/*
git commit -a -m 'add initial Debian packaging'

echo 'I: to create remote repository go to https://salsa.debian.org/python-team/applications/ and click on "New project" link'
echo '   (https://salsa.debian.org/projects/new?namespace_id=2782)'

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