Skip to content

Instantly share code, notes, and snippets.

@afm-sayem
Created Dec 11, 2016
Embed
What would you like to do?
hooks
#!/usr/bin/env bash
# set this to your active development branch
develop_branch="master"
current_branch="$(git rev-parse --abbrev-ref HEAD)"
# only check commit messages on main development branch
[ "$current_branch" != "$develop_branch" ] && exit 0
# regex to validate in commit msg
commit_regex='((feat|fix|doc|style|refactor|perf|test|chore)\(.+\)\:|merge)'
error_msg="Aborting commit. Please follow appropriate commit message format:
<type>(<scope>): <message>
example:
fix(response): check data type before performing arithmatic
or Merge pull request from #234
Allowed types:
feat: A new feature
fix: A bug fix
doc: Documentation only changes
style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
refactor: A code change that neither fixes a bug or adds a feature
perf: A code change that improves performance
test: Adding missing tests
chore: Changes to the build process or auxiliary tools and libraries such as documentation generation
Commits starting with 'Merged' are passed through
"
if ! grep -iqE "$commit_regex" "$1"; then
echo "$error_msg" >&2
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment