blob: e7c6cb3d15620596f7c443c3e8d2492e8ed6f780 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#!/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
if git diff-index --quiet HEAD --; then
latest="$(git rev-list -1 --date=format:${fmt} --pretty=%ad --no-commit-header HEAD)"
modified=0
else
latest="$(date +${fmt})"
modified=1
fi
count=$(git rev-list --date=format:${fmt} --pretty=%ad --no-commit-header HEAD | sed -n /${latest}/p | wc -l)
count=$(( ${count} + ${modified} ))
version="${latest}.${count}"
fi
echo "${version}"
|