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