Skip to content

Instantly share code, notes, and snippets.

@danjohnson95
Created October 6, 2017 13:39
Show Gist options
  • Save danjohnson95/163f3976acbf5cb2a52b8d2ba8bdf291 to your computer and use it in GitHub Desktop.
Save danjohnson95/163f3976acbf5cb2a52b8d2ba8bdf291 to your computer and use it in GitHub Desktop.
A git hook for enforcing a commit message standard
#!/bin/bash
#
# The link to the wiki page detailing these standards
url='https://github.com/designmynight/dmn/wiki/Semantic-Commit-Messages'
# The regular expression in which the commit message should match
regex='^(fix|feat|chore|refactor|test|style|docs)(:\s)([\S].{1,60}[\S])'
# What we'll say
error_msg="Aborting commit due to incorrect message format.\nPlease see $url"
if ! grep -iqE "$regex" "$1"; then
echo 'Aborting commit due to incorrect message format.' >&2
echo "Please see $url" >&2
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment