git hooksのpre-commitを用いるとコミット時、jshintやテストを通してコミットを自動でチェックすることができます。
.git/hooks/pre-commitに処理を書く
pre-commit.sampleというファイルがあるので参考にして下さい。
今回書いたのはgrunt jshint
でjshintエラーが出た場合にコミットを取りやめるというものです。
# !/bin/sh
grunt jshint
if ["$?" -ne 0]; then
exit 1
fi
実行権限を付与
pre-commitに実行権限がないので付与しておきます。
% ls -ll .git/hooks/pre-commit
-rw-r--r-- 1 ■■■ ■■■ 67 11 18 12:30 .git/hooks/pre-commit
chmod a+x .git/hooks/pre-commit
% ls -ll .git/hooks/pre-commit
-rwx-r--r-- 1 ■■■ ■■■ 67 11 18 12:30 .git/hooks/pre-commit
実行権限が付与されました。これで準備OK。