This is a very easy way to check your PHP syntax before each commit. Git will call the script before it runs your commit. If there are syntax errors found, they won't be committed and they will be reported.
It will only check files that have one of the extensions listed in the $extensions
array. It's a pretty simple script and comes in handy if you are working locally before you push to a remote for testing.
Things to note:
- You may have to change the
#!/usr/bin/php
to point to your path for PHP - If you don't want to check untracked files, remove the
$untracked
variable. - Place
pre-commit
file in your.git/hooks
folder andchmod +x .git/hooks/pre-commit