view tools/get_version.sh @ 36:a464bd43b76c 1.0.0

clean documentation rewrite
author ark
date 2026-10-21 22:34 +0200
parents 28e1fc486be5
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