File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010 entry : pre_commit_hooks/check-comments.sh
1111 language : script
1212 types : [python]
13+ - id : check-branch-name
14+ name : Check the compliance of your branch name
15+ description : Checks that the name of the branch you are committing to is compliant with a given regex
16+ entry : pre_commit_hooks/check-branch-name.sh
17+ language : script
18+ pass_filenames : false
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ while getopts r: flag
4+ do
5+ case " ${flag} " in
6+ r) BRANCH_NAME_REGEX=${OPTARG} ;;
7+ * ) echo " Invalid flag provided ($flag )" ; exit 1;
8+ esac
9+ done
10+
11+ if [[ $BRANCH_NAME_REGEX == " " ]]; then
12+ echo " No regular expression provided to validate the branch name..."
13+ echo " Please provide one using the '-r' argument."
14+ echo " "
15+ echo " Sample 'repo' section of your '.pre-commit-config.yaml' file:"
16+ echo " - repo: https://github.com/alma/pre-commit-hooks"
17+ echo " rev: v1.1.0"
18+ echo " hooks:"
19+ echo " - id: check-branch-name"
20+ echo " args:"
21+ echo ' - "-r^(((ci|docs|feature|fix|hotfix|perf|refactor|test)\/.*)|main)$"'
22+ exit 1
23+ fi
24+
25+ BRANCH_NAME=$( git rev-parse --abbrev-ref HEAD)
26+
27+ if ! [[ $BRANCH_NAME =~ $BRANCH_NAME_REGEX ]]; then
28+ echo " *** Commit interrupted ***"
29+ echo " Your branch name does not match the naming convention."
30+ echo " Branch names should match \" $BRANCH_NAME_REGEX \" ..."
31+
32+ exit 1
33+ fi
You can’t perform that action at this time.
0 commit comments