Skip to content

Instantly share code, notes, and snippets.

@jailson
Forked from pgilad/Instructions.md
Last active June 13, 2017 20:01
Show Gist options
  • Select an option

  • Save jailson/74cbeedbf906f7a7dacfecd39b08a093 to your computer and use it in GitHub Desktop.

Select an option

Save jailson/74cbeedbf906f7a7dacfecd39b08a093 to your computer and use it in GitHub Desktop.
Hook script to validate any commit message checking for a JIRA Issue or 'Merge'.
#!/usr/bin/env bash
#
# HOW TO INSTALL
#
# 1. Copy the file commit-msg.sh to .git/hooks/commit-msg:
# curl https://gist.githubusercontent.com/jailson/74cbeedbf906f7a7dacfecd39b08a093/raw/21e8284398ba4fffd55faca3a8fb67a8ec3a9742/commit-msg.sh > .git/hooks/commit-msg
#
# 2. Delete the sample file:
# rm .git/hooks/commit-msg.sample
#
# 3. Make the script executable:
# chmod +x .git/hooks/commit-msg
#
commit_regex='([a-zA-Z]{1,10}-[0-9]+|merge)'
error_msg="⚠️ Commit aborted! Your commit message is missing either a JIRA Issue (eg. 'ABCD-1234') or 'Merge'."
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