Skip to content

Instantly share code, notes, and snippets.

@Max95Cohen
Created February 9, 2023 05:17
Show Gist options
  • Save Max95Cohen/62e21668be547346fc70df98ecb54bf6 to your computer and use it in GitHub Desktop.
Save Max95Cohen/62e21668be547346fc70df98ecb54bf6 to your computer and use it in GitHub Desktop.
prepare-commit-msg git hook to add prefix for commit message
#!/bin/bash
FILE=$1
MESSAGE=$(cat $FILE)
REGEX_ISSUE_ID="^((ISSUE|TASK)\-[0-9]+:\s)"
ISSUE_ID_IN_COMMIT=$(echo $MESSAGE | grep -o -E "$REGEX_ISSUE_ID")
if [[ -z "$ISSUE_ID_IN_COMMIT" ]]; then
BRANCH_NAME=$(git symbolic-ref --short HEAD)
echo "$BRANCH_NAME: $MESSAGE" > $FILE
else
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment