Skip to content

Instantly share code, notes, and snippets.

@rahularyan
Created October 1, 2018 14:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahularyan/c897dca3f3a34ed8215c1f7289c6a188 to your computer and use it in GitHub Desktop.
Save rahularyan/c897dca3f3a34ed8215c1f7289c6a188 to your computer and use it in GitHub Desktop.
Auto increment version number using git-hook on commit
#!/bin/sh
MESSAGE="$1"
VERSION_PATH=`git rev-parse --show-toplevel`"/style.css"
VER_TOKEN="Version:"
VER_STR=$(grep "$VER_TOKEN" $VERSION_PATH | awk '{print $2}' | 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 $VERSION_PATH -e 's/'"$VER_TOKEN"'\(\s*\).*/'"$VER_TOKEN"'\1'"$VER_STR"'/g'
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment