Skip to content

Instantly share code, notes, and snippets.

@KeyboardCowboy
Last active February 6, 2021 18:09
Show Gist options
  • Save KeyboardCowboy/9102798 to your computer and use it in GitHub Desktop.
Save KeyboardCowboy/9102798 to your computer and use it in GitHub Desktop.
Check for Drupal Debugging Statements Before Committing Code
#!/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|console\.log'
# If any functions are found as executable, prevent the commit.
DIEONFAIL=false
echo "Running the debugger check..."
RES=`egrep -nr --exclude-dir=".git" --exclude-dir="*devel*" "^(\s*)?[^/{2}]($FUNCTIONS)\(.*\)" .`
if [[ -n "$RES" ]]; then
echo "\n$RES"
echo "\nDebugging 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.\nChanges were committed anyway.\n"
exit 0;
fi
else
echo "\n No debugging functions were found. Nice job, Ace!\n";
exit 0;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment