diff options
Diffstat (limited to 'GIT-VERSION-GEN')
-rwxr-xr-x | GIT-VERSION-GEN | 60 |
1 files changed, 24 insertions, 36 deletions
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN index 4a466ed..dd9ca07 100755 --- a/GIT-VERSION-GEN +++ b/GIT-VERSION-GEN @@ -1,40 +1,28 @@ -#!/bin/sh - -GVF=GIT-VERSION-FILE -DEF_VER=v0.4.0.GIT - -LF=' -' +#!/usr/bin/env ruby +CONSTANT = "Kcar::VERSION" +RVF = "lib/kcar/version.rb" +DEF_VER = "v0.4.0" +vn = DEF_VER # First see if there is a version file (included in release tarballs), # then try git-describe, then default. -if test -f version -then - VN=$(cat version) || VN="$DEF_VER" -elif test -d .git -o -f .git && - VN=$(git describe --abbrev=4 HEAD 2>/dev/null) && - case "$VN" in - *$LF*) (exit 1) ;; - v[0-9]*) - git update-index -q --refresh - test -z "$(git diff-index --name-only HEAD --)" || - VN="$VN-dirty" ;; - esac -then - VN=$(echo "$VN" | sed -e 's/-/./g'); -else - VN="$DEF_VER" -fi - -VN=$(expr "$VN" : v*'\(.*\)') +if File.exist?(".git") + describe = `git describe --abbrev=4 HEAD 2>/dev/null`.strip + case describe + when /\Av[0-9]*/ + vn = describe + system(*%w(git update-index -q --refresh)) + unless `git diff-index --name-only HEAD --`.chomp.empty? + vn << "-dirty" + end + vn.tr!('-', '.') + end +end -if test -r $GVF -then - VC=$(sed -e 's/^GIT_VERSION = //' <$GVF) -else - VC=unset -fi -test "$VN" = "$VC" || { - echo >&2 "GIT_VERSION = $VN" - echo "GIT_VERSION = $VN" >$GVF -} +vn = vn.sub!(/\Av/, "") +new_ruby_version = "#{CONSTANT} = '#{vn}'\n" +cur_ruby_version = File.read(RVF) rescue nil +if new_ruby_version != cur_ruby_version + File.open(RVF, "w") { |fp| fp.write(new_ruby_version) } +end +puts vn if $0 == __FILE__ |