Skip to content

Instantly share code, notes, and snippets.

@afm-sayem
Created December 11, 2016 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afm-sayem/2cb8343d92f1415e64b90e1ba7cea35e to your computer and use it in GitHub Desktop.
Save afm-sayem/2cb8343d92f1415e64b90e1ba7cea35e to your computer and use it in GitHub Desktop.
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