#!/usr/bin/env bash

# regex to validate the branch name
BRANCH_NAME_REGEX="^((feature\/|hotfix\/|bugfix\/|(((backport\/)?)FIX-|ENH-|SNR-)|(backport\/))([A-Z0-9]{3,10}-[0-9]{1,8}-)[a-z0-9()\._-]+)|((backport\/)?(ENH-|SNR-|MERGE-)([a-z0-9()\._-]+))|(^release\/[0-9]{1,3}\.[0-9]{1,3}.x$)|^develop$"

local_branch="$(git rev-parse --abbrev-ref HEAD)"

message="\n\n\n###############################################\n\n\n"
message="${message}There is something wrong with your branch name. You must adhere to this convention: \n\n\n"
message="${message}    ${BRANCH_NAME_REGEX}\n\n\n"
message="${message}Your commit will be rejected. You should rename your branch and try again."
message="${message}\n\n\n###############################################\n\n"

if [[ ! $local_branch =~ $BRANCH_NAME_REGEX ]]; then
  echo -e "$message"
  exit 1
fi

exit 0
