Skip to content

Instantly share code, notes, and snippets.

@vimishor vimishor/pre-commit
Created Apr 14, 2015

Embed
What would you like to do?
Prevents debug traces and sensitive data to be commited.
#!/bin/sh
#
# Prevents debug traces and sensitive data to be commited.
#
# What to search for
FUNCTIONS='var_dump\(|phpinfo\(|print_r\('
# Prevent the commit if something is found.
# default: true
DIEONFAIL=true
if git-rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
else
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
# Redirect output to stderr.
exec 1>&2
for FILE in $(git diff-index --name-status $against -- | cut -c3-) ; do
if [ "$(egrep -n --regexp="(${FUNCTIONS})" "${FILE}")" ]
then
echo "${FILE} contains debug traces!"
if [ $DIEONFAIL = true ]
then
echo "Changes not committed."
exit 1;
else
echo "You may want to clean these up before push these changes."
exit 0;
fi
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.