1#!/bin/sh
2# Get the current version using various methods.
3
4# The following will serve as a fallback version string (which is the short
5# hash of the latest commit before the application was packaged (if it was
6# packaged)). You will find that this file is listed inside the .gitattributes
7# file like so:
8#
9#   ./build-utils/getversion.sh export-subst
10#
11# This tells git to replace the format string in the following line with the
12# current short hash upon the calling of the `git archive <hash/tag>` command.
13VERSION_FROM_ARCHIVE=6f69789a
14
15# The preferred method is to use the git describe command but this is only
16# possible if the .git directory is present.
17if [ -d .git -a -r .git ]
18then
19    VERSION_FROM_GIT=$(git describe --tags --always)
20fi
21
22if [ x"$VERSION_FROM_GIT" != x ]; then
23    echo $VERSION_FROM_GIT; exit 0;
24fi
25
26if [ "$VERSION_FROM_ARCHIVE" != ':%h$' ]; then
27    echo $VERSION_FROM_ARCHIVE; exit 0;
28fi
29
30echo "ERROR: Commit hash detection failure. Dear packager, please figure out"\
31     "what has gone wrong and or get in touch with us." >&2
32
33exit 2
34
35# vim: ft=sh:et:sw=4:ts=8:sts=4:tw=80
36