-
-
Save hypermkt/8333495 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/bash | |
# 文法チェック対象の拡張子 | |
extensions='\.(php)$' | |
# トップレベルディレクトリを絶対パスで取得 例)/home/hoge/work/ | |
root=$(git rev-parse --show-toplevel) | |
# 1. コミットに登録されたファイル名一覧を取得 | |
# 2. 指定拡張子のみに絞り込み | |
# 3. ファイルを絶対パスに変換 | |
files=($(git diff --name-only --cached | egrep "$extensions" | sed -e "s|^|$root/|")) | |
# PHPバイナリーのパス | |
php=/usr/local/php5/bin/php | |
failed=0 | |
# 文法チェック | |
for f in "${files[@]}"; do | |
if [ -f $f ]; then | |
$php -l "$f" || failed=1 | |
fi | |
done | |
# 文法エラーがある場合は終了 | |
if [ $failed -ne 0 ]; then | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment