#!/bin/sh -euf

set -euf

BASE="$(dirname $0)"

if [ $# -ne 1 ]; then
	echo "usage: git-version-get fallback-file" >&2
	exit 2
fi

generate() {
	if desc=$(git -C "$BASE/.." describe); then
		echo "$desc" | sed 's/-[0-9]\+-g.*/.x/'
	else
		cat $1
	fi
}

# Omit the trailing new line, so this can be used directly
generate $1 | tr -d "\n\r"
