Last active
January 4, 2016 04:59
-
-
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…
This file contains 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/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Kudos! Nice catch with the "php -l".