Skip to content

Instantly share code, notes, and snippets.

@BGuimberteau
Created July 25, 2015 09:20
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 BGuimberteau/ee9c4e77fa9705b3b5c8 to your computer and use it in GitHub Desktop.
Save BGuimberteau/ee9c4e77fa9705b3b5c8 to your computer and use it in GitHub Desktop.
hook for pre-commit and not commit if found some strings
#!/usr/bin/env ruby
exit 0 if ARGV.include?('--no-verify')
keywords = %w(\.pry console.log)
files_changed = %x(git diff-index --name-only HEAD --).split
%x(git grep -q -E "#{keywords.join('|')}" #{files_changed.join(' ')})
if $?.exitstatus.zero?
puts "# Check following lines:"
files_changed.each do |file|
keywords.each do |keyword|
%x(git grep -q #{keyword} #{file})
if $?.exitstatus.zero?
line = %x(git grep -n #{keyword} #{file} | awk -F ":" '{print $2}').split.join(', ')
puts "#\t\033[31m#{file}\033[0m contains #{keyword} at line \033[33m#{line}\033[0m."
end
end
end
exit 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment