Created
July 24, 2015 13:16
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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