Skip to content

Instantly share code, notes, and snippets.

@barend
Last active April 19, 2016 14:37
Show Gist options
  • Save barend/c92d39f9ba73c8d3f771765e46e75a0d to your computer and use it in GitHub Desktop.
Save barend/c92d39f9ba73c8d3f771765e46e75a0d to your computer and use it in GitHub Desktop.
Git hook to check each commit starts with a JIRA issue key.
#!/bin/sh
#
# A hook script to check the commit log message. Called by "git commit" with
# one argument, the name of the file that has the commit message. The hook
# should exit with non-zero status after issuing an appropriate message if it
# wants to stop the commit. The hook is allowed to edit the commit message
# file.
#
test "" = "$(cat $1 | head -n1 | egrep -v '^[A-Z]+-[0-9]+\b')" || {
echo >&2 ''
echo >&2 ''
echo >&2 *** Missing JIRA issue key. ***
echo >&2 ''
echo >&2 ''
# exit 1 # enable if you want to prevent the commit
}
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment