Skip to content

Instantly share code, notes, and snippets.

@McRipper
Created April 19, 2013 11:54
Show Gist options
  • Save McRipper/5419879 to your computer and use it in GitHub Desktop.
Save McRipper/5419879 to your computer and use it in GitHub Desktop.
Git Hook to increment version in file
#!/bin/sh
MESSAGE="$1"
VERSION_PATH=`git rev-parse --show-toplevel`"/config/initializers/version.rb"
VER_TOKEN="Version"
VER_STR=$(grep "$VER_TOKEN" $VERSION_PATH | awk '{print $3}' | tr -d '"')
VER_MAJ=$(echo $VER_STR | awk -F. '{print $1}')
VER_MIN=$(echo $VER_STR | awk -F. '{print $2}')
VER_PAT=$(echo $VER_STR | awk -F. '{print $3}')
applyVersion()
{
VER_STR=$VER_MAJ"."$VER_MIN"."$VER_PAT
VER_LINE=$VER_TOKEN" = "\"$VER_STR\"
sed -i "" 's/'"$VER_TOKEN"'.*/'"$VER_LINE"'/g' $VERSION_PATH
git add $VERSION_PATH
#git commit -m "version update: "$VER_STR
}
onVMAJ()
{
let VER_MAJ++
VER_MIN=0
VER_PAT=0
applyVersion
}
onVMIN()
{
let VER_MIN++
VER_PAT=0
applyVersion
}
onVPAT()
{
let VER_PAT++
applyVersion
}
case "$MESSAGE" in
*vmaj++* ) onVMAJ;;
*vmin++* ) onVMIN;;
*vpat++* ) onVPAT;;
* ) onVPAT;;
esac
exit
# Place this file in the initializers folder
# Version can be called: Fashionbi::Version
#
module Fashionbi
Version = "3.2.1"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment