Skip to content

Instantly share code, notes, and snippets.

@dnlserrano
Created July 7, 2017 23:33
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 dnlserrano/2a3783aa7f2e324a574c8c22f6ced751 to your computer and use it in GitHub Desktop.
Save dnlserrano/2a3783aa7f2e324a574c8c22f6ced751 to your computer and use it in GitHub Desktop.
prepare-commit-msg git hook
#!/bin/sh
ticket=$(git symbolic-ref --short HEAD | sed 's/.*\/\([a-zA-Z]*\)-\([0-9]*\).*/JIRA \1-\2/g')
original_msg=$(cat $1)
echo "\n\n$ticket\n$original_msg" > $1
@amalbuquerque
Copy link

If you want to use this with vim fugitive, you have to check if the message already has the ticket (vim fugitive does its commit using git commit -F file_with_commit_msg):

#!/bin/sh

ticket=$(git symbolic-ref --short HEAD | sed 's/.*\/\([a-zA-Z]*\)-\([0-9]*\).*/JIRA \1-\2/g')
original_msg=$(cat $1)
if ! [[ ${original_msg} =~ ${ticket} ]]; then
    echo "\n\n$ticket\n$original_msg" > $1
fi

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