Skip to content

Instantly share code, notes, and snippets.

Created Jul 24, 2015
What would you like to do?
git-hooks: check if branch name is on par with pom's version
# Run the following command in the root of your project to install this pre-push hook:
# cp git-hooks/pre-push .git/hooks/pre-push; chmod 700 .git/hooks/pre-push
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master develop test)
BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_EXCLUDED=$(printf "%s\n" "$BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$")
if [ $BRANCE_EXCLUDED -eq 1 ]; then
exit 0;
cd `git root`
CURRENT_VERSION=$(grep "<version>.*</version>" pom.xml | grep $BRANCH_NAME-SNAPSHOT)
if [ -z "$CURRENT_VERSION" ]; then
echo "Your current version is not on par with your branchname"
echo "Please set a version containing the your branchname and ending with SNAPSHOT: "
echo " ex:"
echo " mvn versions:set -DnewVersion=x.y.$BRANCH_NAME-SNAPSHOT"
echo ""
exit 1;
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment