Skip to content

Instantly share code, notes, and snippets.

@ottok
Created May 9, 2015 09:06
Show Gist options
  • Save ottok/ee1384d8229e83b6486e to your computer and use it in GitHub Desktop.
Save ottok/ee1384d8229e83b6486e to your computer and use it in GitHub Desktop.
Example of a .git/hooks/pre-commit for PHP developers
#!/bin/bash
for FILE in $(git diff --cached --name-only); do
if [[ "$FILE" =~ \.php$ ]]; then
php -l "$FILE" 1> /dev/null
if [[ $? -ne 0 ]]; then
echo -e "\e[1;33mAborting commit: PHP code contains syntax errors\e[0m" >&2
exit 1
fi
fi
done
for FILE in $(git diff --cached --name-only); do
if [[ "$FILE" =~ \.php$ ]]; then
phpcs -n "$FILE"
if [ $? -ne 0 ]; then
echo -e "\e[1;33mAborting commit: PHP code violates coding standards\e[0m" >&2
exit 1
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment