Created
March 1, 2018 18:55
-
-
Save sgdavis1/d31f2383a5ecf245c642069f1eedb1fb to your computer and use it in GitHub Desktop.
pre-commit hook for ensuring consistent naming in build.gradle
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/sh | |
version=$(grep "^version" build.gradle | awk -F "=" '{print $2}' | sed 's/[ \"]*//g') | |
branch=$(git branch |grep "*"|awk '{print $2}') | |
target_branch=$branch | |
skipversioncheck=$(git config --bool hooks.skipversioncheck) | |
if [[ $branch != "master" ]]; then | |
target_branch="devel" | |
fi | |
if [[ $target_branch == "master" ]] && [[ $version == "*_work" ]]; then | |
echo " version = \"$version\"" | |
echo "Version string indicates this is a devel commit, but you are on the master branch" | |
exit 1 | |
elif [[ $skipversioncheck == "true" ]]; then | |
# Skip the check only on "devel" (cannot disable for the master branch) | |
exit 0 | |
elif [[ $target_branch == "devel" ]] && [[ ! $version =~ .*_work$ ]]; then | |
echo " version = \"$version\"" | |
echo " branch = \"$branch\"" | |
echo "Version string does not indicate a devel version (should be ending in '_work')" | |
echo "It appears you are on a development branch, but this might not be correct." | |
echo | |
echo "If you know what you are doing you can disable this check using:" | |
echo " git config hooks.skipversioncheck true" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment