#!/usr/bin/env bash # # Usage: get-scala-revision [dir] # Figures out current scala revision of a git clone. # If no dir is given, current working dir is used. # # Example build version string: # v2.10.0-M1-0098-g6f1c486d0b-2012-02-01 # [[ $# -eq 0 ]] || cd "$1" ensure_tag () { # v2.10.0-M1 fallback=58cb15c40d [[ -n $(git tag -l v2.10.0-M1) ]] || { git tag -a -m "generated by get-scala-revision" v2.10.0-M1 $fallback } } ensure_tag # the closest tag, obtained separately because we have to # reconstruct the string around the padded distance. tag=$(git describe --match 'v2*' --abbrev=0) # the full string - padding correctness depends on abbrev=10. described=$(git describe --match 'v2*' --abbrev=10) suffix="${described##${tag}-}" counter=$(echo $suffix | cut -d - -f 1) hash=$(echo $suffix | cut -d - -f 2) # 016 is rocket-surgically-calibrated to pad the distance from the # tag to the current commit into a 4-digit number - since maven # will be treating this as a string, the ide depends on # 10 being greater than 9 (thus 0010 and 00009.) printf "%s-%04d-%10s-%s\n" "$tag" "$counter" "$hash" $(date "+%Y-%m-%d")