Skip to content

Instantly share code, notes, and snippets.

@kunicmarko20
Last active July 9, 2019 15:30
Show Gist options
  • Save kunicmarko20/1f0ce2ad6ca37854e5fdea8071556b70 to your computer and use it in GitHub Desktop.
Save kunicmarko20/1f0ce2ad6ca37854e5fdea8071556b70 to your computer and use it in GitHub Desktop.
Prefix commit with ticket number from the branch if it isn't already prefixed
#./.git/hooks/prepare-commit-msg
COMMIT_PREFIX=$(git symbolic-ref --short HEAD | grep -Po 'PROJECT-([0-9]+)');
HAS_TICKET_NUMBER=$(grep -Po 'PROJECT-([0-9]+)' $1);
if [ -n "$HAS_TICKET_NUMBER" ]; then
return;
fi
if [ -n "$COMMIT_PREFIX" ]; then
sed -i.bak -e "1s/^/[$COMMIT_PREFIX] /" $1;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment