LoginSignup
15
12

More than 5 years have passed since last update.

pre-commitでコミットをチェックする

Last updated at Posted at 2014-11-27

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。

15
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
12