Skip to content

Instantly share code, notes, and snippets.

@valotas valotas/pre-push.sh
Created Jul 24, 2015

Embed
What would you like to do?
git-hooks: check if branch name is on par with pom's version
#!/bin/bash
# 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)
fi
BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_NAME="${BRANCH_NAME##*/}"
BRANCH_EXCLUDED=$(printf "%s\n" "$BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$")
if [ $BRANCE_EXCLUDED -eq 1 ]; then
exit 0;
fi
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;
fi
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.