Skip to content

Instantly share code, notes, and snippets.

@AfonsoTsukamoto
Last active August 29, 2015 14:11
Show Gist options
  • Save AfonsoTsukamoto/a88a51332de9dfa62f46 to your computer and use it in GitHub Desktop.
Save AfonsoTsukamoto/a88a51332de9dfa62f46 to your computer and use it in GitHub Desktop.
A git hook to stop commits with binding pry... for now. Easy to add more expressions.
#!/usr/bin/env ruby
##
# This file must be renamed to pre-commit without extension and
# added to your .git/hooks directory
# After that, run `chmod 755 pre-commit` to make it executable
$user = ENV['USER']
def added_line_regex(string)
/^[+].*#{string}.*$/
end
def stop_commit(message)
puts message
exit 1
end
def diff
@diff ||= `git diff --cached`
end
def has_binding_pry?
(diff =~ added_line_regex('binding.pry')) != nil
end
def has_debugger?
(diff =~ added_line_regex('debugger;')) != nil
end
def has_trace?
(diff =~ added_line_regex('pdb.set_trace()')) != nil
end
def should_stop?
has_trace? || has_debugger? || has_binding_pry?
end
stop_commit("#{$user} - breakpoint in the code!") if should_stop?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment