Skip to content

Commit 88a6f26

Browse files
authored
Improving error message + Adding exclude regex (#3)
1 parent 6c2330f commit 88a6f26

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

pre_commit_hooks/check-branch-name.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/bin/bash
22

3-
while getopts r: flag
3+
while getopts r:e: flag
44
do
55
case "${flag}" in
66
r) BRANCH_NAME_REGEX=${OPTARG};;
7+
e) EXCLUDE_BRANCH_REGEX=${OPTARG};;
78
*) echo "Invalid flag provided ($flag)"; exit 1;
89
esac
910
done
@@ -24,10 +25,15 @@ fi
2425

2526
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
2627

28+
if [[ $BRANCH_NAME =~ $EXCLUDE_BRANCH_REGEX ]]; then
29+
exit 0
30+
fi
31+
2732
if ! [[ $BRANCH_NAME =~ $BRANCH_NAME_REGEX ]]; then
2833
echo "*** Commit interrupted ***"
2934
echo "Your branch name does not match the naming convention."
30-
echo "Branch names should match \"$BRANCH_NAME_REGEX\"..."
35+
echo "Branch names should match \"$BRANCH_NAME_REGEX\"."
36+
echo "Your branch is named \"$BRANCH_NAME\"..."
3137

3238
exit 1
3339
fi

0 commit comments

Comments
 (0)