#!/bin/bash -e
WORK=$(pwd)
TOP=$(cd `dirname $0` ; pwd)
. $TOP/bloom_util.sh

_track_all

if ! git show-ref refs/heads/bloom >/dev/null
then
    bailout "This does not appear to be a bloom release repo. Please initialize it first using:

   git bloom-set-upstream <UPSTREAM_VCS_URL> <VCS_TYPE>"
fi
git checkout master

LASTTAG=$(git for-each-ref --sort='*authordate' --format='%(refname:short)' refs/tags/upstream | tail -1)
if [ "$LASTTAG" = "" ]
then
    bailout "There are is no upstream version imported into this repo. Try:

  git bloom-import-upstream
"
else
    status "The latest upstream tag in the release repo is ${boldon}$LASTTAG${reset}"
    extract_gbp_upstream_version $LASTTAG
    status "Upstream version is: ${boldon}$GBP_MAJOR.$GBP_MINOR.$GBP_PATCH${reset}"
fi

$TOP/bloom-generate-debian $@

exit 0
