wobblyhead hg > wobbly_ssg
diff tools/get_version.sh @ 0:71dd8d58a8e5 default tip
cleaned up re-init from net_wobblyhead_www project tooling
| author | ark |
|---|---|
| date | 2026-10-22 14:59 +0200 |
| parents | |
| children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/get_version.sh Thu Oct 22 14:59:43 2026 +0200 @@ -0,0 +1,65 @@ +#!/bin/sh +USAGE="$0 [-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 "unrecognized 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 +
