Created
November 23, 2022 13:04
-
-
Save umutdz/12408a7c6931f62f0c901b50d6e5b965 to your computer and use it in GitHub Desktop.
Add your own custom commit message check into git hooks. The checker control commit messages whether correct according to conventional commit .
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ ! -x .git/hooks/commit-msg ] || [ ! -f .git/hooks/commit-msg ] || ! cmp ./hooks/commit-msg.sh .git/hooks/commit-msg | |
then | |
echo -e "\033[33m Setting Up Git commit Hook..." | |
mkdir -p .git/hooks/ | |
cp ./hooks/commit-msg.sh .git/hooks/commit-msg | |
chmod +x .git/hooks/commit-msg | |
echo -e "\033[32m Done" | |
echo -e "\033[33m You can make commit now." | |
exit 1 | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MESSAGE=$(cat $1) | |
COMMITFORMAT="^(feat|fix|build|chore|docs|style|refactor|perf|test|merge)?(\(.+\))?!?: (.+[^.\r\n])([\r\n]+(.+[\r\n]+)+)?$" | |
if ! [[ "$MESSAGE" =~ $COMMITFORMAT ]]; then | |
echo "Your commit was rejected due to the commit message. Skipping..." | |
echo "" | |
echo "Please use the following format:" | |
echo "feat: feature example comment" | |
echo "fix(ui): bugfix example comment" | |
echo "" | |
echo "More details on https://www.conventionalcommits.org/en/v1.0.0/" | |
exit 1 | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- repos: | |
- repo: local | |
hooks: | |
- id: commit-msg-checker | |
name: commit-msg-checker | |
entry: ./hooks/commit-msg-checker.sh | |
language: script | |
exclude: ^\.pre-commit-config$ | |
pass_filenames: false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment