#!/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