Skip to content

Instantly share code, notes, and snippets.

@timsweb
Created July 9, 2013 11:12
Embed
What would you like to do?
Git hook to prevent committing xdebug_break() functions. Save as .git/hooks/pre-commit then chmod +x it. Submodules also have their own hooks folder: ".git/modules/submodule/path/here/hooks".
#!/bin/sh
if git-rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
else
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
for FILE in `git diff --cached --name-only` ; do
# Check if the file contains 'debugger'
grep -qE '^[ \t]*xdebug_break()' $FILE
if [[ $? -eq 0 ]]
then
echo $FILE ' contains xdebug_break()! To commit retry with --no-verify'
exit 1
fi
done
exit
@scottsb
Copy link

scottsb commented Jul 15, 2017

This is perfect. Exactly what I was looking for. Thanks! (Note that it doesn't seem that the initial conditional serves any purpose, so I have removed that on my fork.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment