Skip to content

Instantly share code, notes, and snippets.

@stulentsev

stulentsev/pre-commit.rb

Last active Dec 3, 2020
Embed
What would you like to do?
% cat .git/hooks/pre-commit
#! /usr/bin/env ruby
puts "pre-commit hook: checking for forgotten debug statements"
debug_statements = [
'binding.pry',
'console.log',
':focus',
'focus: true',
'# !!!',
]
valid = true
debug_statements.each do |stmnt|
puts "\nstatement: #{stmnt}"
git_cmd = 'git diff --cached'
grep_cmd = "grep -e '^+.*#{Regexp.escape(stmnt)}'"
output = `#{git_cmd} | #{grep_cmd}`.chomp
puts output if output.length > 0
if output.split("\n").length > 0
valid = false
else
puts ' no matches'
end
end
if valid
exit(0)
else
puts ""
puts "\aRemove debug statements before commit"
exit(1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment