2022-07-07 15:58:39 -04:00
|
|
|
COMMIT_MSG_FILE=$1
|
|
|
|
|
COMMIT_SOURCE=$2
|
|
|
|
|
SHA1=$3
|
2023-08-04 14:37:55 -04:00
|
|
|
# Gets the current branch name but if we're in a detached head state, return "HEAD"
|
|
|
|
|
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
|
2023-10-24 13:07:27 -04:00
|
|
|
# Regex to match the ICU-#### branch name pattern we use
|
|
|
|
|
ISSUE_REGEX="^(ICU-[0-9]+)"
|
2022-07-07 15:58:39 -04:00
|
|
|
|
2023-08-04 14:37:55 -04:00
|
|
|
# Don't run commitizen for merge or squash commits, as well as when rebasing
|
|
|
|
|
if [ "${COMMIT_SOURCE}" = merge ] || [ "${COMMIT_SOURCE}" = squash ] || [ "${COMMIT_SOURCE}" = "message" -a "${BRANCH_NAME}" = "HEAD" ];then
|
2022-07-07 15:58:39 -04:00
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
2023-10-24 13:07:27 -04:00
|
|
|
# If the branch name matches, set the JIRA link automatically
|
|
|
|
|
if [[ $BRANCH_NAME =~ $ISSUE_REGEX ]]
|
|
|
|
|
then
|
|
|
|
|
issue="${BASH_REMATCH[1]}"
|
|
|
|
|
url="https://hashicorp.atlassian.net/browse/${issue}"
|
|
|
|
|
exec < /dev/tty && npx git-cz --issues="$url" --hook || true
|
|
|
|
|
else
|
|
|
|
|
# This is to allow interaction with the terminal for commitizen
|
|
|
|
|
exec < /dev/tty && npx git-cz --hook || true
|
|
|
|
|
fi
|
|
|
|
|
|