Skip to content

Instantly share code, notes, and snippets.

@hypermkt
Forked from doloopwhile/gist:5115016
Last active January 2, 2016 16:59
Show Gist options
  • Save hypermkt/8333495 to your computer and use it in GitHub Desktop.
Save hypermkt/8333495 to your computer and use it in GitHub Desktop.
コメントを追加&自分用に改良
#!/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