#!/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}"