Skip to content

Instantly share code, notes, and snippets.

@EpeeCheeze
Created November 14, 2011 19:00
Show Gist options
  • Save EpeeCheeze/1364784 to your computer and use it in GitHub Desktop.
Save EpeeCheeze/1364784 to your computer and use it in GitHub Desktop.
Bash script to prevent committing debug code in Git
#!/bin/bash
for args in $@
do
case "$args" in
"-f"|"--force")
force=true
;;
esac
done
debugCode=$(git diff --staged | egrep 'dump|print_r|nocommit|console.log|die|{debug}' -i)
if [ ${#debugCode} -gt 0 ]; then
echo You have debugging code that you are trying to commit
commit=false
else
commit=true
fi
if [ $force -o $commit ]; then
git commit
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment