Skip to content

Instantly share code, notes, and snippets.

@mparker17
Last active December 18, 2015 12:49
Show Gist options
  • Select an option

  • Save mparker17/5785316 to your computer and use it in GitHub Desktop.

Select an option

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.
#!/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
@cleaver

cleaver commented Jun 14, 2013

Copy link
Copy Markdown

cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment