-
-
Save waako/2167f45b6637a2a2b0e82139e503be23 to your computer and use it in GitHub Desktop.
Check for Drupal Debugging Statements Before Committing Code
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/bash | |
# | |
# Check for debugging statements before commiting your code. | |
# Place this file in the .git/hooks directory of your project. | |
# List of function names to search for in regex format | |
FUNCTIONS='dpm|kpr|qpr|kint|dd|console\.log' | |
# If any functions are found as executable, prevent the commit. | |
DIEONFAIL=true | |
echo "Running the debugger check..." | |
RES=`egrep -nr --exclude-dir="*devel*" "^(\s*)?[^/{2}]($FUNCTIONS)\(.*\)" $(git diff --cached --name-only)` | |
if [[ -n "$RES" ]]; then | |
echo | |
echo "$RES" | |
echo | |
echo "Debugging functions were found in your code!" | |
if [[ $DIEONFAIL == true ]]; then | |
echo "Changes were not committed." | |
exit 1; | |
else | |
echo "You may want to clean these up before you push those changes." | |
echo "Changes were committed anyway." | |
exit 0; | |
fi | |
else | |
echo | |
echo "No debugging functions were found. Nice job, Ace!"; | |
exit 0; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment