Created
April 14, 2015 19:31
-
-
Save vimishor/457ed8af24b9ebf6cba0 to your computer and use it in GitHub Desktop.
Prevents debug traces and sensitive data to be commited.
This file contains 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/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