Skip to content

Instantly share code, notes, and snippets.

@revagomes
Forked from skwashd/pre-commit
Created May 6, 2014 20:37
Show Gist options
  • Save revagomes/852fcf4cdadbcb065e33 to your computer and use it in GitHub Desktop.
Save revagomes/852fcf4cdadbcb065e33 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment