Skip to content

Instantly share code, notes, and snippets.

@valotas
Created July 24, 2015 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valotas/225d59730a89710e93e6 to your computer and use it in GitHub Desktop.
Save valotas/225d59730a89710e93e6 to your computer and use it in GitHub Desktop.
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