Git hooks for use enforcing code quality, for use with pre-commit.
Ensures that branch names comply with at least one regex.
Every team will have different requirements. At windpioneers, we use something like:
masterfor the master branchstagingfor the staging branchreview/xyzfor review brancheshotfix/xyzfor emergency fix branches directly off masterlearning/xyzfor @nvn-nil's learning / experimentationdevops/xyzfor devops related improvementsfeature/xyzfor new featuresfix/xyz forspecific bug fixesdevelop/xyzfor general experimentation or work not related to a specific feature, e.g. refactoring or testingdoc/xyzfor work improving or developing documentation
Our xyz descriptor is in kebab-case (([a-z][a-z0-9]*)(-[a-z0-9]+)*) as in the example below.
Other useful regexes you might need for your team are snake_case (([a-z][a-z0-9]*)(_[a-z0-9]+)*) and
lowerCamelCase ([a-z][a-zA-Z0-9]+).
You can play with regexes (make sure to use the python flavour) at regex101.com
Use this hook in your .pre-commit-config.yaml file like:
- repo: https://github.com/windpioneers/pre-commit-hooks
rev: 0.0.1
hooks:
- id: check-branch-name
args:
- '^master$'
- '^dev$'
- '^staging$'
- '^develop/([a-z][a-z0-9]*)(-[a-z0-9]+)*$'
- '^devops/([a-z][a-z0-9]*)(-[a-z0-9]+)*$'
- '^doc/([a-z][a-z0-9]*)(-[a-z0-9]+)*$'
- '^feature/([a-z][a-z0-9]*)(-[a-z0-9]+)*$'
- '^fix/([a-z][a-z0-9]*)(-[a-z0-9]+)*$'
- '^hotfix/([a-z][a-z0-9]*)(-[a-z0-9]+)*$'
- '^learning/([a-z][a-z0-9]*)(-[a-z0-9]+)*$'
- '^review/([a-z][a-z0-9]*)(-[a-z0-9]+)*$'
language_version: python3