- Create a
.githooks
directory in the root directory. - Add githook files to it.
- Ask developers to run this command to use those githooks.
git config core.hooksPath .githooks
#!/usr/bin/env bash | |
# Adapted from https://gist.github.com/pgilad/5d7e4db725a906bd7aa7 | |
# Make sure to add execute permissions using: chmod +x <file-name> | |
develop_branch="main" | |
current_branch="$(git rev-parse --abbrev-ref HEAD)" | |
# don't check commit messages on main development branch | |
[ "$current_branch" == "$develop_branch" ] && exit 0 | |
# regex to validate in commit msg | |
commit_regex='^(\w{2,3}-\d+)(, )?(?:\w{2,3}-\d+)*: |^NOTICKET: |^WIP|merge' | |
error_msg="Aborting commit. Your commit message is not conforming to 'PRJCODE-1111: ', 'merge' or 'NOTICKET'." | |
if ! grep -iqE "$commit_regex" "$1"; then | |
echo "$error_msg" >&2 | |
exit 1 | |
fi | |
.githooks
directory in the root directory.git config core.hooksPath .githooks
#!/bin/sh | |
# Make sure to add execute permissions using: chmod +x <file-name> | |
source ~/.zshrc | |
dart format lib/ test/ |