Skip to content

Instantly share code, notes, and snippets.

@doloopwhile
Last active December 14, 2015 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save doloopwhile/5115016 to your computer and use it in GitHub Desktop.
Save doloopwhile/5115016 to your computer and use it in GitHub Desktop.
コミット時にPHPファイルに文法エラーが無いかチェックする、git pre-commitスクリプト
#!/bin/bash
p1='\.(php|inc|view|edit|check|wui|mod|cnf|hlp|)$'
p2='resource/.*/locale/'
root=$(git rev-parse --show-toplevel)
files=($(git diff --name-only --cached | egrep "$p1|$p2" | sed -e "s|^|$root/|"))
failed=0
for f in "${files[@]}"; do
php -l "$f" > /dev/null || failed=1
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