Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pre_commit_hooks/check-branch-name.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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