comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:71dd8d58a8e5
1 #!/bin/sh
2 USAGE="$0 [-f]
3
4 parses tags, status and summary of current repository, prints current version.
5
6 if the current repo revision is the tagging revision, the tag is the version.
7
8 otherwise the script aborts with an error, unless forced with -f flag. in that
9 case the version is the latest tag with -<timestamp> appended.
10
11 options:
12 -f force version output even if not on tagged revision or dirty repo
13
14 "
15
16 VERBOSE=1
17 FORCE=0
18 TIMESTAMP=$(date "+%Y%m%d_%H%M")
19
20 while [ $# != 0 ]
21 do
22 case $1 in
23 -f)
24 FORCE=1
25 ;;
26 *)
27 echo "unrecognized option '$1'"
28 echo "$USAGE"
29 exit 1
30 esac
31 shift
32 done
33
34 # parse hg su, hg tags
35 SUMMARY=$(LC_ALL=C hg su)
36 PARENT=$(echo "$SUMMARY" | grep "parent:" | cut -b 9- | cut -d : -f 1)
37 LATESTTAG=$(hg log -r$PARENT -T "{latesttag}")
38 TAGGEDREV=$(hg tags -T "{rev},{tag}\n"| grep ",$LATESTTAG" | cut -d , -f 1)
39 TAGGINGREV=$(( $TAGGEDREV + 1 ))
40 CLEAN=$(echo "$SUMMARY" | grep -c "commit: (clean)")
41
42 VERSION=$LATESTTAG
43
44 if [ "$PARENT" != "$TAGGEDREV" ] && [ "$PARENT" != "$TAGGINGREV" ] ; then
45 if [ $FORCE = 1 ] ; then
46 (>&2 echo "warning: not a tagged revision")
47 VERSION="${LATESTTAG}.${TIMESTAMP}"
48 else
49 (>&2 echo "error: not a tagged revision")
50 exit 1
51 fi
52 fi
53
54 if [ $CLEAN = 0 ] ; then
55 if [ $FORCE = 1 ] ; then
56 (>&2 echo "warning: working directory not clean")
57 VERSION="${LATESTTAG}.${TIMESTAMP}"
58 else
59 (>&2 echo "error: working directory not clean")
60 exit 1
61 fi
62 fi
63
64 echo $VERSION
65