Created
November 8, 2018 06:59
-
-
Save Na0ki/2620ee07c6894d490379523484c077dc to your computer and use it in GitHub Desktop.
コミット時にブランチの命名規則のチェックをするやつ
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/sh | |
# | |
# An hook script to check branch name convention. | |
# Called by "git commit" with no arguments. The hook should | |
# exit with non-zero status if you are not following | |
# branch name convention. | |
pattern='^((bug|feature|hotfix)/\d+-|junk/)[\w\d\-]+' | |
git rev-parse --abbrev-ref HEAD|perl -nle "print if m{$pattern} or exit 1" > /dev/null 2>&1 | |
if [ $? -ne 0 ]; then | |
cat <<EOF | |
ERROR: invalid branch name | |
Branch name convention is $pattern | |
Examples: | |
bugs bug/123-fix-loading (number is issue number) | |
feature feature/234-add-login (number is issue number) | |
hotfix hotfix/345-fix-mem-leak (number is issue number) | |
junk junk/testing-new-lib | |
Skip pre-commit hooks with --no-verify (not recommended). | |
EOF | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
/path/to/project/hooks/pre-commit
にでも設置してバージョン管理に含めておいて、チェックアウト時にgit config core.hooksPath hooks
でも実行すると比較的楽な気がする