Skip to content

Instantly share code, notes, and snippets.

@subicura
Forked from pgilad/Instructions.md
Last active August 29, 2015 14:27
Show Gist options
  • Save subicura/1782fbbd39f0fe05a992 to your computer and use it in GitHub Desktop.
Save subicura/1782fbbd39f0fe05a992 to your computer and use it in GitHub Desktop.
Git commit-msg hook to validate for issue number(#1234) or the word merge
#!/usr/bin/env bash
# regex to validate in commit msg
commit_regex='(#[0-9]+|merge)'
error_msg="Aborting commit. Your commit message is missing either a Issue Number ('#1111') or 'Merge'"
if ! grep -iqE "$commit_regex" "$1"; 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.githubusercontent.com/subicura/1782fbbd39f0fe05a992/raw/546c228d739996409f89218df285de8375536e33/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