- 下記のシェルスクリプトを ~/.git_tempalte/hooks/pre-commit として保存
DIR=$(pwd)
EMAIL=$(git config user.email)
if [[ "$DIR" =~ ^/home/hogehoge/private/ ]]
then
if [[ ! "$EMAIL" =~ @users.noreply.github.com$ ]]
then
echo "Error: git config user.email = $EMAIL"
exit 1
fi
fi
- ファイル実行権限をつける (chmod 755)
- git のテンプレートに設定する。git init 等で自動的に .git/hooks にコピーされる。
git config --global init.templatedir '~/.git_template'
- /home/hogehoge/private/ 以下にあるフォルダで git commit する場合、その git の user.email が @users.noreplay.github.com を含んでなければエラーとなる。 (フォルダと email の規則は例です)