Skip to content

Instantly share code, notes, and snippets.

@salvatorecordiano
Last active November 21, 2017 09:02
Show Gist options
  • Save salvatorecordiano/ff73d811c8933c08ea68c1177f3db6c9 to your computer and use it in GitHub Desktop.
Save salvatorecordiano/ff73d811c8933c08ea68c1177f3db6c9 to your computer and use it in GitHub Desktop.
Prepending Git commit messages with Jira IDs
#!/bin/bash
# curl -s https://gist.githubusercontent.com/salvatorecordiano/ff73d811c8933c08ea68c1177f3db6c9/raw/6312ceaa840928164afa06e0e42968753b745f61/prepare-commit-msg > .git/hooks/prepare-commit-msg && chmod +x .git/hooks/prepare-commit-msg
COMMIT_MESSAGE=$(cat $1)
PRECOMMIT_MESSAGE=$(git symbolic-ref --short HEAD | grep -Eo "[A-Z0-9]+-[A-Z0-9]+")
RED=`tput setaf 1`
GREEN=`tput setaf 2`
RESET=`tput sgr0`
if [ ! -z "$PRECOMMIT_MESSAGE" ]; then
echo "[${PRECOMMIT_MESSAGE}] ${COMMIT_MESSAGE}" > $1
echo "${GREEN}Jira reference [${PRECOMMIT_MESSAGE}], matched in current branch name and prepended to commit message.${RESET}"
else
echo "${RED}Jira reference not matched.${RESET}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment