Skip to content

Instantly share code, notes, and snippets.

@rthor
Last active November 15, 2018 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rthor/dcc3bb44f33648274b1db7dba1540681 to your computer and use it in GitHub Desktop.
Save rthor/dcc3bb44f33648274b1db7dba1540681 to your computer and use it in GitHub Desktop.
git hook for adding a jira ticket number to relevant commits.

git hook for adding a jira ticket number to relevant commits.

Note: It expects relevant branches to have this naming pattern: PREFIX/USER_NAME/JIRA-TICKET

Steps to include:

> cd PROJECT_ROOT/.git/hooks/

Replace the prepare-commit-msg.example with the prepare-commit-msg file in this gist.

Make the script executable:

> chmod +x prepare-commit-msg

Enjoy!

#!/bin/sh
COMMIT_EDITMSG=$1
MERGE=$(cat $COMMIT_EDITMSG | grep -i 'merge' | wc -l)
SPECIAL=$(git branch | grep \* | cut -d ' ' -f2 | grep -e 'release/' -e 'feature/' | wc -l)
if [ $MERGE -eq 0 ] && [ $SPECIAL -eq 0 ]; then
TICKET=$(git branch | grep \* | cut -d ' ' -f2 | cut -d '/' -f3 | cut -d '-' -f -2)
echo "$TICKET $(cat $COMMIT_EDITMSG)" > $COMMIT_EDITMSG
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment