Skip to content

Instantly share code, notes, and snippets.

@stulentsev
Last active December 3, 2020 14:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stulentsev/2458d72702e05b29ea56d8beb96e8057 to your computer and use it in GitHub Desktop.
Save stulentsev/2458d72702e05b29ea56d8beb96e8057 to your computer and use it in GitHub Desktop.
% 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