#!/usr/bin/env bash

# Bash sets the BASH environment variable, so if it is not set, then we
# are running in a different shell, so manually run ourselves in BASH.
if [ -z "${BASH:-}" ]; then
  exec bash "$0" "$@"
fi

. "$(dirname "$0")/_/husky.sh"

BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
COMMIT_MESSAGE_TEXT=$(cat "$1")

# check if commit with feat: feature: update: on branch fix
RE="_(fix|hotfix|bug|bugfix|fixed)/"
if [[ $BRANCH_NAME =~ $RE ]]; then
    COMMIT_MESSAGE_TEXT_LOWER=$(echo "$COMMIT_MESSAGE_TEXT" | sed -e 's/\(.*\)/\L\1/')
    RE="(breaking:|upgrade:|perf:|perfect:|breaking change:|breakingchange:|update:|feat:|feature:)"
    if [[ $COMMIT_MESSAGE_TEXT_LOWER =~ $RE ]]; then
          echo "Your current branch is \"$BRANCH_NAME\", cannot commit with commit message prefix \"breaking, upgrade, perf, perfect, breaking change, breakingchange, update, feat, feature\". If there is a problem, contact Arnut@DevOps."
          exit 1
    fi
fi

exit 0