Skip to content

Instantly share code, notes, and snippets.

@evergosu
Last active November 18, 2020 12:54
Show Gist options
  • Select an option

  • Save evergosu/12e81769d38d930958fad18722c47de9 to your computer and use it in GitHub Desktop.

Select an option

Save evergosu/12e81769d38d930958fad18722c47de9 to your computer and use it in GitHub Desktop.
prepare-commit-msg
#!/bin/bash
FILE=$1
MESSAGE=$(cat $FILE)
TICKET=$(git rev-parse --abbrev-ref HEAD | grep -Eo '^(\w+/)?(\w+[-_])?[0-9]+' | grep -Eo '(\w+[-])?[0-9]+' | tr "[:lower:]" "[:upper:]")
if [[ $TICKET == "" || "$MESSAGE" == "$TICKET"* ]];then
exit 0;
fi
echo "$TICKET: $MESSAGE" > $FILE
# then run to make it exe: chmod +x .git/hooks/prepare-commit-msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment