Skip to content

Instantly share code, notes, and snippets.

@jonatasnona
Forked from bcmiller/pre-commit
Created July 7, 2012 14:58
Show Gist options
  • Save jonatasnona/3066774 to your computer and use it in GitHub Desktop.
Save jonatasnona/3066774 to your computer and use it in GitHub Desktop.
Git: pre-commit
#!/bin/sh
# Place as .git/hooks/pre-commit
#Reject any commit that would have PHP syntaz errors on .php , .module, .install, .inc files
####
# Reject any commit that would add a line with tabs.
#
# You can enable this as a repo policy with
#
# git config hooks.allowtabs true
####
#f=`echo $GIT_DIR|sed s/\.git//`
#echo $f
#exit 1
FILES=`git diff --cached --numstat|egrep '\.(php|module|install|inc)$' |awk '{print $3}'`
for file_name in $FILES
do
php -l $file_name
if [ $? -ne 0 ]
then
echo $file_name
echo $file
cat<<END
Error: THis commit has PHP parse errors.
If you really know what your doing you can force this commit with:
git commit --no-verify
But really you should fix your PHP errors first which you can check with 'php -l fname', and then recommit.
END
exit 1
fi
done
allowtabs=$(git config hooks.allowtabs)
if [ "$allowtabs" != "true" ] &&
git diff --cached | egrep '^\+.* '>/dev/null
then
cat<<END;
Error: This commit would contain a tab, which is against this repo's policy.
If you know what you are doing you can force this commit with:
git commit --no-verify
Or change the repo policy like so:
git config hooks.allowtabs true
Tabs:
END
git grep -n --cached ' '
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment