Last active
December 3, 2020 14:29
-
-
Save stulentsev/2458d72702e05b29ea56d8beb96e8057 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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