Skip to content

Instantly share code, notes, and snippets.

@dave1010
Created October 28, 2011 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dave1010/1322160 to your computer and use it in GitHub Desktop.
Save dave1010/1322160 to your computer and use it in GitHub Desktop.
pre-commit PHP link and check for merge conflicts
#!/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