Last active
July 9, 2020 06:48
-
-
Save inverse/d0de698a88bfc7e392daec12b0d028f5 to your computer and use it in GitHub Desktop.
Git hook for adding branch name to commit message if it conforms to ticket naming convention
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Prepend branch name to commit message in [] if matching regex. e.g. DEN-123 | |
BRANCH_NAME=$(git symbolic-ref --short HEAD) | |
BRANCH_NAME="${BRANCH_NAME##*/}" | |
BRANCH_IN_COMMIT=$(grep -c "\[$BRANCH_NAME\]" $1) | |
if [ -n "$BRANCH_NAME" ] && [[ $BRANCH_NAME =~ ^([A-Z]+-[0-9]+)(\-.+)?$ ]] && ! [[ $BRANCH_IN_COMMIT -ge 1 ]]; then | |
sed -i.bak -e "1s/^/[${BASH_REMATCH[1]}] /" $1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment