summaryrefslogtreecommitdiff
path: root/version
diff options
context:
space:
mode:
Diffstat (limited to 'version')
-rwxr-xr-xversion27
1 files changed, 27 insertions, 0 deletions
diff --git a/version b/version
new file mode 100755
index 0000000..b967060
--- /dev/null
+++ b/version
@@ -0,0 +1,27 @@
+#!/bin/sh
+# TODO: Think of a way to generate version without git repository for source tarballs. Making the script overwrite
+# itself with a static version sounds good enough, really.
+try_tag() {
+ local tag
+ if tag=$(git describe --exact-match --tags --dirty=-dirty 2>/dev/null); then
+ case "${tag}" in
+ *-dirty) return 1;;
+ *) echo "${tag}"; return 0;;
+ esac
+ fi
+ return 1
+}
+
+
+if ! version=$(try_tag); then
+ fmt=%Y%m%d
+ set -- $(git rev-list --date=format:${fmt} --pretty=%ad --no-commit-header --since=yesterday HEAD)
+ if [ $# -gt 0 ]; then
+ suffix=$#
+ git diff-index --quiet HEAD -- || suffix=$(( $# + 1 ))
+ version="$1.${suffix}"
+ else
+ version="$(date +${fmt}).1"
+ fi
+fi
+echo "${version}"