version.sh (725B)
1 #!/bin/sh 2 set -ex 3 # This file is in the public domain. 4 # Determines the current version of our code. 5 6 BRANCH=$(git name-rev --name-only HEAD) 7 if [ -z "${BRANCH}" ]; then 8 exit 1 9 else 10 # "Unshallow" our checkout, but only our current branch, and exclude the submodules. 11 git fetch --no-recurse-submodules --tags --depth=1000 origin "${BRANCH}" 12 RECENT_VERSION_TAG=$(git describe --tags --match 'v*.*.*' --exclude '*-dev*' --always --abbrev=0 HEAD || exit 1) 13 commits="$(git rev-list ${RECENT_VERSION_TAG}..HEAD --count)" 14 if [ "${commits}" = "0" ]; then 15 git describe --tag HEAD | sed -r 's/^v//' || exit 1 16 else 17 echo $(echo ${RECENT_VERSION_TAG} | sed -r 's/^v//')-${commits}-$(git rev-parse --short=8 HEAD) 18 fi 19 fi