fix previous version detection for repos with no tags

Change-Id: I38084753f3ba11bb28b1faee99e3cd23766f6162
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2016-05-09 14:52:09 -04:00
parent 604896d7e2
commit c5357e4f9d
2 changed files with 10 additions and 7 deletions

View File

@ -49,11 +49,14 @@ function setup_temp_space {
function get_last_tag {
# Print the most recent tag on a branch. If no branch is
# specified, the currently checked out branch is examined.
typeset branch="$1"
git describe --abbrev=0 $branch || return 0
# Print the most recent tag for a ref. If no ref is specified, the
# currently checked out branch is examined.
local ref="$1"
if ! git describe --abbrev=0 --first-parent ${ref} >/dev/null 2>&1; then
echo ""
else
git describe --abbrev=0 --first-parent ${ref}
fi
}

View File

@ -62,7 +62,7 @@ cd $REPODIR
TARGETSHA=`git log -1 $SHA --format='%H'`
# Determine the most recent tag before we add the new one.
PREVIOUS=$(git describe --abbrev=0 --first-parent ${TARGETSHA})
PREVIOUS=$(get_last_tag $TARGETSHA)
title "Tagging $TARGETSHA as $VERSION"
if git show-ref "$VERSION"; then
@ -70,7 +70,7 @@ if git show-ref "$VERSION"; then
# Reset the notion of "previous" to the version associated with
# the parent of the commit being tagged, since the tag we're
# applying already exists.
PREVIOUS=$(git describe --abbrev=0 --first-parent ${TARGETSHA}^1)
PREVIOUS=$(get_last_tag ${TARGETSHA}^1)
else
# WARNING(dhellmann): announce.sh expects to be able to parse this
# commit message, so if you change the format you may have to