Skip to content

Instantly share code, notes, and snippets.

@skwashd
Last active January 4, 2016 04:59
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save skwashd/8572382 to your computer and use it in GitHub Desktop.
Save skwashd/8572382 to your computer and use it in GitHub Desktop.
Git pre-commit hook for checking files with coder-review and php lint. This prevents developers committing broken PHP or code that doesn't comply with the Drupal coding standards.Add this file to .git/hooks/pre-commit in the root of your doc repo and make it executable (chmod +x .git/hooks/pre-commit).You must have the coder module in ~/.drush/T…
#!/bin/bash
#
# Git pre-commit hook for Drupal projects.
# Created by Dave Hall - http://davehall.com.au
# Distributed under the terms of the WTFPL - http://www.wtfpl.net/
#
set -e
#exit 0
ROOT_DIR=$(git rev-parse --show-toplevel)
CODE_FILES=("php" "module" "inc")
for file in $(git diff --cached --name-only --diff-filter=ACM); do
if [[ $file =~ (README.|LICENSE|.png|.jpg|.gif|.txt|.sql) ]]; then
continue;
fi
echo "Cheking $file";
drush coder-review --minor --comment --i18n --release --security --sql --style --no-empty "$ROOT_DIR/$file"
ext="${file##*.}"
if [[ ${CODE_FILES[*]} =~ "$ext" ]]; then
php -l $file
fi
done
@handrus
Copy link

handrus commented Jan 28, 2014

Kudos! Nice catch with the "php -l".

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