Skip to content

Instantly share code, notes, and snippets.

@Na0ki
Created November 8, 2018 06:59
Show Gist options
  • Save Na0ki/2620ee07c6894d490379523484c077dc to your computer and use it in GitHub Desktop.
Save Na0ki/2620ee07c6894d490379523484c077dc to your computer and use it in GitHub Desktop.
コミット時にブランチの命名規則のチェックをするやつ
#!/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
@Na0ki
Copy link
Author

Na0ki commented Nov 8, 2018

/path/to/project/hooks/pre-commit にでも設置してバージョン管理に含めておいて、チェックアウト時に git config core.hooksPath hooks でも実行すると比較的楽な気がする

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment