Skip to content

Instantly share code, notes, and snippets.

@tdeschamps
Created November 2, 2016 08:51
Show Gist options
  • Save tdeschamps/f3a9900ea587aad9a21718390ac06cbb to your computer and use it in GitHub Desktop.
Save tdeschamps/f3a9900ea587aad9a21718390ac06cbb to your computer and use it in GitHub Desktop.
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
FILES_PATTERN='\.rb$'
FORBIDDEN='binding.pry'
files=$(git diff --cached --name-only | grep -E $FILES_PATTERN)
if [ -n "$files" ]
then
echo $files | \
GREP_COLOR='4;5;37;41' xargs grep --color --with-filename -n $FORBIDDEN && echo "COMMIT REJECTED Found $FORBIDDEN references. Please remove them before commiting" && exit 1;
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment