view tools/get_version.sh @ 37:a88effe4831e default tip

Added tag 1.0.0 for changeset a464bd43b76c
author ark
date 2026-10-21 22:36 +0200
parents a464bd43b76c
children
line wrap: on
line source

#!/bin/sh
USAGE="usage: ./get_version.sh [-f]

parses tags, status and summary of current repository, prints current version.

if the current repo revision is the tagging revision, the tag is the version.

otherwise the script aborts with an error, unless forced with -f flag. in that
case the version is the latest tag with -<timestamp> appended.

options:
    -f      force version output even if not on tagged revision or dirty repo

"

VERBOSE=1
FORCE=0
TIMESTAMP=$(date "+%Y%m%d_%H%M")

while [ $# != 0 ]
do
    case $1 in
        -f)
            FORCE=1
            ;;
        *)
            echo "unrecognised option '$1'"
            echo "$USAGE"
            exit 1
    esac
    shift
done

# parse hg su, hg tags
SUMMARY=$(LC_ALL=C hg su)
PARENT=$(echo "$SUMMARY" | grep "parent:" | cut -b 9- | cut -d : -f 1)
LATESTTAG=$(hg log -r$PARENT -T "{latesttag}")
TAGGEDREV=$(hg tags -T "{rev},{tag}\n"| grep ",$LATESTTAG" | cut -d , -f 1)
TAGGINGREV=$(( $TAGGEDREV + 1 ))
CLEAN=$(echo "$SUMMARY" | grep -c "commit: (clean)")

VERSION=$LATESTTAG

if [ "$PARENT" != "$TAGGEDREV" ] && [ "$PARENT" != "$TAGGINGREV" ] ; then
    if [ $FORCE = 1 ] ; then
        (>&2 echo "warning: not a tagged revision")
        VERSION="${LATESTTAG}.${TIMESTAMP}"
    else
        (>&2 echo "error: not a tagged revision")
        exit 1
    fi
fi

if [ $CLEAN = 0 ] ; then
    if [ $FORCE = 1 ] ; then
        (>&2 echo "warning: working directory not clean")
        VERSION="${LATESTTAG}.${TIMESTAMP}"
    else
        (>&2 echo "error: working directory not clean")
        exit 1
    fi
fi

echo $VERSION