Created
December 19, 2020 23:41
-
-
Save GabrielMMelo/3a5cf8cac04935abcb7d3fa104c27ef8 to your computer and use it in GitHub Desktop.
Hook for validating a commit
This file contains hidden or 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 | |
branch="$(git rev-parse --abbrev-ref HEAD)"; | |
commit_regex='((CDW-)([1-9][0-9])|((feat|fix|chore|refactor|style|test|docs)(((\w{0,15})))?))(:.\S.*)'; | |
error_msg="Aborting commit. Your commit message format is invalid, please check the references." | |
commit_message="$1"; | |
if ! grep -iqE "$commit_regex" <<<"${commit_message}"; then | |
echo "$error_msg" >&2 | |
exit 1 | |
fi | |
if [ "$branch" = "master" ]; then | |
echo "You can't commit directly to master branch" | |
exit 1 | |
fi | |
if [ "$branch" = "develop" ]; then | |
echo "You can't commit directly to develop branch" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment