Skip to content

Instantly share code, notes, and snippets.

@vimishor
Created April 14, 2015 19:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vimishor/457ed8af24b9ebf6cba0 to your computer and use it in GitHub Desktop.
Save vimishor/457ed8af24b9ebf6cba0 to your computer and use it in GitHub Desktop.
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