#!/usr/bin/env bash

set -ex

# The command `git describe --match v0.0` will return a string like
#
# v0.0-856-g329708b
#
# where 856 is the number of commits since the v0.0 tag. It will always
# find the v0.0 tag and will always return the total number of commits (even
# if the tag is v0.0.1).
MAJOR="1"
MINOR="11"
REVISION=`git --no-replace-objects describe --match v$MAJOR.$MINOR`

# Extract the version number from the string. Do this in two steps so
# it is a little easier to understand.
REVISION=${REVISION:5} # drop the first 5 characters
REVISION=${REVISION:0:${#REVISION}-9} # drop the last 9 characters
REVISION=${REVISION/\-/}
