#!/bin/bash -e
#=============================================================================#
#                         Release package                                     #
#=============================================================================#
# (c) Denis Smirnov <mithraen@freesource.info>                   06 Feb 2007  #
#=============================================================================#
. /usr/bin/mithraen-build-utils-functions

if [ "$1" = "-f" ]; then
    force=-f
fi

# TODO: add support for branch repos
if [ ! -d .git ]; then
    echo "You must run this script from root of git repo"
    exit -1
fi

# Add changelog to spec-file if not added before
cl-edit --add
# Commit this version
gear-commit -a --no-edit ||:

# Get version
VERSION=`rpmbuild -bE *.spec | grep Version: | sed 's/Version:[[:space:]]*//' | head -n1`
RELEASE=`rpmbuild -bE *.spec | grep Release: | sed 's/Release:[[:space:]]*//' | head -n1`
PACKAGE=`rpmbuild -bE *.spec | grep Name: | sed 's/Name:[[:space:]]*//' | head -n1`

tag="$PACKAGE/$VERSION-$RELEASE"

git tag -s -m "$tag" "$tag" $force

remote=`gitalt_get_remote`

git_alt_pre
git push "$remote" ||:
git push $force "$remote" "$tag"
