#!/usr/bin/env bash

set -eo pipefail

base_dir=`dirname $0`
if test ! -d $base_dir/../.hg -o -n "$CI"; then
   echo -n "heptapod-"
   cat $base_dir/../HEPTAPOD_VERSION
   exit 0
fi

# disable mercurial output customization 
export HGPLAIN=

exact_tag=$(hg log -r . -T '{tags}\n' | grep -E '^heptapod-[0-9]+[.][0-9]+[.][0-9]+' | sed -e 's/heptapod/hpd/g'|| echo "")

if test -n "$exact_tag"; then
    echo $exact_tag
else
    hg log -r . -T "{latesttag(r're:^heptapod')}~dev.{changessincelatesttag}.{node|short}"
fi
