Last active
December 18, 2015 12:49
-
-
Save mparker17/5785316 to your computer and use it in GitHub Desktop.
Pre-commit hook to prevent me from checking in syntax errors on my Drupal projects. Put in `.git/hooks` and remove the `.sh` from the filename.
This file contains hidden or 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/sh | |
| # | |
| # An example hook script to verify what is about to be committed. | |
| # Called by "git commit" with no arguments. The hook should | |
| # exit with non-zero status after issuing an appropriate message if | |
| # it wants to stop the commit. | |
| # | |
| # Put this file in .git/hooks and name it pre-commit | |
| # Redirect output to stderr. | |
| exec 1>&2 | |
| # If there are whitespace errors, print the offending file names and fail. | |
| #exec git diff-index --check --cached $against -- | |
| # Lint PHP files | |
| for file in `git diff --name-only --cached | grep -E '\.(php|inc|module|install|profile|test)'` | |
| do | |
| if [[ -f $file ]] | |
| then | |
| php -l $file | |
| if [[ $? -ne 0 ]] | |
| then | |
| exit 1 | |
| fi | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cool!