Skip to content

Instantly share code, notes, and snippets.

@Max95Cohen
Created January 27, 2023 18:01
Show Gist options
  • Save Max95Cohen/520f25bc8471c6ca4e78d7245350e044 to your computer and use it in GitHub Desktop.
Save Max95Cohen/520f25bc8471c6ca4e78d7245350e044 to your computer and use it in GitHub Desktop.
commit-msg git hook
#!/bin/bash
REGEX_ISSUE_ID="^((ISSUE|TASK)\-[0-9]+)"
ISSUE_ID_IN_COMMIT=$(echo $(cat "$1") | grep -o -E "$REGEX_ISSUE_ID")
if [[ -z "$ISSUE_ID_IN_COMMIT" ]]; then
BRANCH_NAME=$(git symbolic-ref --short HEAD)
RED='\033[0;31m'
NC='\033[0m' # No Color
printf "\nYour commit message is illegal. Please add branch name \"${RED}$BRANCH_NAME: ${NC}\" to start of messagei as prefix.\n\n"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment