From 7a91bf841c0f3b3bee25112ca4eef9c6a2ce0ab9 Mon Sep 17 00:00:00 2001 From: Jean-Michel Cazaux Date: Tue, 23 Nov 2021 08:02:22 +0100 Subject: [PATCH] Improving error message + Adding exclude regex --- pre_commit_hooks/check-branch-name.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pre_commit_hooks/check-branch-name.sh b/pre_commit_hooks/check-branch-name.sh index 4a4952c..b80db7e 100755 --- a/pre_commit_hooks/check-branch-name.sh +++ b/pre_commit_hooks/check-branch-name.sh @@ -1,9 +1,10 @@ #!/bin/bash -while getopts r: flag +while getopts r:e: flag do case "${flag}" in r) BRANCH_NAME_REGEX=${OPTARG};; + e) EXCLUDE_BRANCH_REGEX=${OPTARG};; *) echo "Invalid flag provided ($flag)"; exit 1; esac done @@ -24,10 +25,15 @@ fi BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) +if [[ $BRANCH_NAME =~ $EXCLUDE_BRANCH_REGEX ]]; then + exit 0 +fi + if ! [[ $BRANCH_NAME =~ $BRANCH_NAME_REGEX ]]; then echo "*** Commit interrupted ***" echo "Your branch name does not match the naming convention." - echo "Branch names should match \"$BRANCH_NAME_REGEX\"..." + echo "Branch names should match \"$BRANCH_NAME_REGEX\"." + echo "Your branch is named \"$BRANCH_NAME\"..." exit 1 fi