Skip to content

Instantly share code, notes, and snippets.

@petRUShka
Last active September 22, 2016 12:43
Show Gist options
  • Save petRUShka/2f6d5e75f1e92dcd27e3 to your computer and use it in GitHub Desktop.
Save petRUShka/2f6d5e75f1e92dcd27e3 to your computer and use it in GitHub Desktop.
Git hook which is prevent you from commit code with breakpoints or focus
#!/bin/sh
# Should be placed in .git/hooks/pre-commit inside project dir
# Do not forget to install The Silver Search: https://github.com/ggreer/the_silver_searcher#linux
ag_output=$(ag --color "(:focus\b)|(^[^#\\n]+(byebug|binding\.pry))" `git diff-index --cached HEAD --no-commit-id --name-only | grep ".*rb$"` 2> /dev/null)
if [ $? == 0 ]
then
echo "There are undeleted :focus or breakpoint (byebug or pry-byebug) in following files:"
echo "$ag_output"
exit 1
fi
@lluis
Copy link

lluis commented Sep 22, 2016

had to made some changes for Debian (with sh linked to dash)

#!/bin/sh
# Should be placed in .git/hooks/pre-commit inside project dir
# https://gist.github.com/petRUShka/2f6d5e75f1e92dcd27e3
# Do not forget to install The Silver Search: https://github.com/ggreer/the_silver_searcher#linux
ag_output=$(ag -l "(:focus\b)|(^[^#\\n]*(byebug|binding\.pry))" `git diff-index --cached HEAD --no-commit-id --name-only | grep ".*rb$"` 2> /dev/null)

if [ $? -eq 0 ]
then
  echo "There are undeleted :focus or breakpoint (byebug or pry-byebug) in following files:"
  echo "$ag_output"
  exit 1
fi

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