#!/usr/bin/sh
#
# Copyright (c) 2006 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
# Author: Greg Nichols
#
# tag the test package release with the next availible release number.

# only tag the release for CVS and git, since svn uses repo versions for tags
if [ -d CVS ]; then
	NEXT_TAG=`rhts-mk-get-next-tag`

	if [ -n "$NEXT_TAG" ]; then
		echo Tagging release as $NEXT_TAG
		cvs tag $NEXT_TAG
	else
		echo Error: could not determine the next tag
	fi
fi


if git log -1 &>/dev/null; then
        CURRENT_TAG=`rhts-mk-get-current-tag`
	NEXT_TAG=`rhts-mk-get-next-tag`

	if [ -n "$NEXT_TAG" ]; then
		if [ -n "$CURRENT_TAG" ]; then
                	# Sanity check: is the current tag merged into this branch?
			# Only do this if $CURRENT_TAG is defined.
                        if ! git rev-list HEAD | grep -q $(git show-ref --dereference --hash --tags "$CURRENT_TAG" | tail -n 1 | awk {'print $1'}) ; then
                    		echo "Error: current tag $CURRENT_TAG is not an ancestor of HEAD"
                    		echo "(Hint: make sure it is merged into this branch)"
                    		exit 1
                	fi
                fi
		echo Tagging release as $NEXT_TAG
		git tag -m "$NEXT_TAG" $NEXT_TAG
	else
		echo Error: could not determine the next tag
	fi
fi
