| 1 | #! /bin/sh |
| 2 | |
| 3 | LC_ALL=C |
| 4 | export LC_ALL |
| 5 | |
| 6 | srcdir="$(dirname "$0")" |
| 7 | test -z "$srcdir" && srcdir=. |
| 8 | |
| 9 | cd "$srcdir" |
| 10 | |
| 11 | if test -f version; then |
| 12 | printf '%s' "$(cat version)" |
| 13 | exit 0 |
| 14 | fi |
| 15 | |
| 16 | if ! test -d .git || ! git log -n1 --pretty='%h' >/dev/null 2>&1; then |
| 17 | printf 'UNVERSIONED' |
| 18 | exit 0 |
| 19 | fi |
| 20 | |
| 21 | tmpfile="$(mktemp)" |
| 22 | |
| 23 | if ! git describe --exact-match --tags $(git log -n1 --pretty='%h') >"$tmpfile" 2>/dev/null; then |
| 24 | echo g$(git log -n1 --pretty='%h') >"$tmpfile" |
| 25 | fi |
| 26 | |
| 27 | printf '%s' "$(sed 's/^v//g' <"$tmpfile")" |
| 28 | |
| 29 | rm -f "$tmpfile" |