Skip to content

Instantly share code, notes, and snippets.

@abhay-work
Forked from pgilad/Instructions.md
Last active July 4, 2018 17:41
Show Gist options
  • Select an option

  • Save abhay-work/9fa2895f081f208990bcc2e0aabf59d2 to your computer and use it in GitHub Desktop.

Select an option

Save abhay-work/9fa2895f081f208990bcc2e0aabf59d2 to your computer and use it in GitHub Desktop.
Git commit-msg hook to validate for Jira issue (FS-XXX) at the beginning of every commit
#!/usr/bin/env bash
current_branch="$(git rev-parse --abbrev-ref HEAD)"
# regex to validate in commit msg
commit_regex='(^FS-[0-9]+)'
error_msg="Aborting commit. Your commit message is missing a JIRA Issue ('FS-XXX') at the beginning."
if ! grep -iqE "$commit_regex" "$1"; then
echo "$error_msg" >&2
exit 1
fi

Setup

cd <your-git-repo>

curl https://gist.githubusercontent.com/abhay-work/9fa2895f081f208990bcc2e0aabf59d2/raw/1bb266b327742efc27eb2fb736b8befa1f2aa645/commit-msg.sh > .git/hooks/commit-msg

rm .git/hooks/commit-msg.sample

chmod +x .git/hooks/commit-msg
Note: If you want to bypass the check when committing, add the --no-verify flag to your git commit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment