Skip to content

Instantly share code, notes, and snippets.

@UnderpantsGnome
Last active September 27, 2015 00:47
Show Gist options
  • Save UnderpantsGnome/1184743 to your computer and use it in GitHub Desktop.
Save UnderpantsGnome/1184743 to your computer and use it in GitHub Desktop.
My pre-commit hook
#!/bin/bash
debug=`git diff --cached | grep -C 2 -E '+\s*And (open|show me the page|save_and_open_page)'`
pry=`git diff --cached | grep -C 2 -E 'binding.pry'`
debugger=`git diff --cached | grep -C 2 debugger`
console_log=`git diff --cached | grep -C 2 console.log`
conflicts=`git diff --cached | grep -C 2 -E '<<<|>>>'`
if [ -n "$debug" ]; then
echo "debugging statements added in this commit"
echo $debug
fi
if [ -n "$pry" ]; then
echo "binding.pry added in this commit"
echo $debug
fi
if [ -n "$conflicts" ]; then
echo "unresolved merge conflicts added in this commit"
echo $conflicts
fi
if [ -n "$debugger" ]; then
echo "JS debugging statements added in this commit"
echo $debugger
fi
if [ -n "$console_log" ]; then
echo "JS debugging statements added in this commit"
echo $console_log
fi
if [[ -n "$conflicts" || -n "$debug" || -n "$debugger" || -n "$console_log" ]]; then
exit 1
fi
@millisami
Copy link

But how to integrate with the git would be more helpful?

@UnderpantsGnome
Copy link
Author

http://book.git-scm.com/5_git_hooks.html

GIT_DIR in that link is a git repo, each repo will have its own hooks.

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