Skip to content

Instantly share code, notes, and snippets.

@joxxoxo
Created October 18, 2012 17:41
Show Gist options
  • Save joxxoxo/3913639 to your computer and use it in GitHub Desktop.
Save joxxoxo/3913639 to your computer and use it in GitHub Desktop.
git pre commit hook
#!/bin/bash
## START PRECOMMIT HOOK
# git commit .... <-- run with check
# NOCHECK=1 git commit ... <-- run without check
if [ ! "${NOCHECK}" ]; then
files_modified=`git status --porcelain | egrep "^(A |M |R ).*" | awk ' { if ($3 == "->") print $4; else print $2 } '`
for f in $files_modified; do
echo "Checking ${f}..."
if grep --color -n "console.log" $f; then
echo "File ${f} failed - found 'console.log'"
exit 1
fi
if grep --color -n "binding.pry" $f; then
echo "File ${f} failed - found 'binding.pry'"
exit 1
fi
done
fi
exit
## END PRECOMMIT HOOK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment