Skip to content

Instantly share code, notes, and snippets.

@kalaiselvan369
Last active April 17, 2020 11:04
Show Gist options
  • Save kalaiselvan369/c9c5bfb91519d14a6031d995c9bfafd3 to your computer and use it in GitHub Desktop.
Save kalaiselvan369/c9c5bfb91519d14a6031d995c9bfafd3 to your computer and use it in GitHub Desktop.
Precommit hooks that runs spotless code formatter.
#!/bin/bash
LC_ALL=C
RED='\033[0;1;31m'
NC='\033[0m' # No Color
echo "Running git pre-commit hook"
local_branch="$(git rev-parse --abbrev-ref HEAD)"
valid_branch_regex="^(feature|bugfix|improvement|library|prerelease|release|hotfix)\/[a-z0-9._-]+$"
message="Branch names in this project must adhere to this contract: $valid_branch_regex. Your commit is aborted. You should rename your branch to a valid name and try again."
if [[ ! $local_branch =~ $valid_branch_regex ]]
then
echo -e "${RED}ERROR:${NC} $message"
exit 1
fi
./gradlew spotlessCheck
RESULT=$?
exit $RESULT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment