Skip to content

Instantly share code, notes, and snippets.

@kysnm
Forked from naoty/pre-commit
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kysnm/e5c289b2f64712a0706a to your computer and use it in GitHub Desktop.
Save kysnm/e5c289b2f64712a0706a to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# filter by extension
def extname_filter(files, extnames = ['.rb'])
files.split($/).select do |path|
extnames.include?(File.extname(path))
end
end
# grep 'binding.pry' (avoid a comment out)
def include_debug_code?(files)
extname_filter(files).any? do |path|
return false unless File.exist? path
!File.readlines(path).grep(/\A\s*(?!#\s*)binding.pry/).empty?
end
end
# check binding.pry
cached_files = `git diff --cached --name-only`
if include_debug_code?(cached_files)
puts 'ERROR: binding.pry is found.'
exit 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment