Skip to content

Instantly share code, notes, and snippets.

Created Jul 25, 2020
What would you like to do?
Git Commit Message Hook for JIRA Issue Keys
# The script below adds the branch name automatically to
# every one of your commit messages. The regular expression
# below searches for JIRA issue key's. The issue key will
# be extracted out of your branch name
# A variant of grep support the -P flag for PCRE is required
# Find current branch name
BRANCH_NAME=$(git symbolic-ref --short HEAD)
if [[ -z "$BRANCH_NAME" ]]; then
echo "No branch name... "; exit 1
# Extract issue id from branch name
ISSUE_ID=$(echo "$BRANCH_NAME" | LC_ALL=en_US.utf8 grep -o -P "$REGEX_ISSUE_ID")
# Prepend issue id if it was found
if [[ -z "$ISSUE_ID" ]]; then
echo $(cat "$1") > "$1"
echo "$ISSUE_ID"': '$(cat "$1") > "$1"

This comment has been minimized.

Copy link
Owner Author

@mobeigi mobeigi commented Jul 25, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment