Skip to content

Instantly share code, notes, and snippets.

@tdeschamps
tdeschamps / pre-commit
Created November 2, 2016 08:51
A pre-commit hook which saves you from committing ruby files with `binding.pry` of `:focus` within them. You can customise it to fit your needs and project.
#!/bin/sh
SPEC_FILES_PATTERN='_spec\.rb$'
FORBIDDEN_SPEC=':focus'
files=$(git diff --cached --name-only | grep -E $SPEC_FILES_PATTERN)
if [ -n "$files" ]
then
echo $files | \
GREP_COLOR='4;5;37;41' xargs grep --color --with-filename -n $FORBIDDEN_SPEC && echo "COMMIT REJECTED Found "$FORBIDDEN_SPEC" references. Please remove them before commiting" && exit 1;
fi