Skip to content

Instantly share code, notes, and snippets.

@dpolivaev
Forked from pgilad/Instructions.md
Last active January 26, 2016 10:26
Show Gist options
  • Save dpolivaev/4d650d75d7b57d3e559a to your computer and use it in GitHub Desktop.
Save dpolivaev/4d650d75d7b57d3e559a to your computer and use it in GitHub Desktop.
Git commit-msg hook to validate for jira issue or the word merge
#!/usr/bin/env bash
# regex to validate in commit msg
commit_regex='^(ITD-[0-9]+ |Merge )'
error_msg="Aborting commit. Your commit message '$1' is missing either a JIRA Issue ('ITD-11111 ') or 'Merge '"
if ! grep -qE "$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/pgilad/5d7e4db725a906bd7aa7/raw/feba0ca462f87a382cfbc3eddfcc529ceb9b7350/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