Created
October 28, 2011 12:31
-
-
Save dave1010/1322160 to your computer and use it in GitHub Desktop.
pre-commit PHP link and check for merge conflicts
This file contains hidden or 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 | |
conflicts=`git diff --cached --name-only -S'<<<<<<'` | |
for i in `git diff --cached --name-only | grep '.php'`; | |
do | |
thisphperror=`php -l $i | grep -v 'No syntax errors detected in'` | |
if [ -n "$thisphperror" ]; then | |
echo "PHP errors added in file: " $i | |
phperrors='true' | |
fi | |
done | |
if [ -n "$conflicts" ]; then | |
echo "Unresolved merge conflicts added in this commit:" | |
echo $conflicts | |
fi | |
if [[ -n "$conflicts" || -n "$phperrors" ]]; then | |
echo | |
echo "Commit with '-n' to bypass checks" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment