Skip to content

Instantly share code, notes, and snippets.

@radzio
Last active March 8, 2018 19:33
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 radzio/0ba5bc285cc84bad15be1d3eae9fbb16 to your computer and use it in GitHub Desktop.
Save radzio/0ba5bc285cc84bad15be1d3eae9fbb16 to your computer and use it in GitHub Desktop.
commit-msg.sh
#!/bin/sh
# .git/hooks/commit-msg
commit_regex='([A-Z]+-[0-9]+|merge)'
error_msg="Aborting commit. Your commit message is missing either a JIRA Issue or 'Merge'"
if ! grep -iqE "$commit_regex" "$0"; then
echo "$error_msg" >&2
exit 1
fi

Instructions

  • copy the file commit-msg to .git/hooks/commit-msg
  • make sure your delete the sample file .git/hooks/commit-msg.sample
  • Make commit msg executable. chmod +x .git/hooks/commit-msg
  • Edit commit-msg to better fit your development branch, commit regex and error message
  • Profit $$

Shell example

curl https://gist.github.com/radzio/0ba5bc285cc84bad15be1d3eae9fbb16/raw/a4244a7e05e9428f7d616dfbc2d860ae111299c7/commit-msg.sh > .git/hooks/commit-msg

rm .git/hooks/commit-msg.sample

chmod +x .git/hooks/commit-msg

vim .git/hooks/commit-msg

echo "Profit $$"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment