Created
July 25, 2015 09:20
-
-
Save BGuimberteau/ee9c4e77fa9705b3b5c8 to your computer and use it in GitHub Desktop.
hook for pre-commit and not commit if found some strings
This file contains hidden or 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
#!/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