-
-
Save todb-r7/4422771 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
#!/usr/bin/env ruby | |
# Check that modules actually pass msftidy checks first. | |
# To install this script, copy it to ".git/hooks/pre-commit" and | |
# make it executable | |
valid = true # Presume validity | |
files_to_check = [] | |
results = %x[git diff --cached --name-only] | |
results.each_line do |fname| | |
fname.strip! | |
next unless File.exist?(fname) and File.file?(fname) | |
next unless fname =~ /modules.+\.rb/ | |
files_to_check << fname | |
end | |
if files_to_check.empty? | |
puts "--- No Metasploit modules to check, committing. ---" | |
else | |
puts "--- Checking module syntax with tools/msftidy.rb ---" | |
files_to_check.each do |fname| | |
cmd = "ruby ./tools/msftidy.rb #{fname}" | |
msftidy_output= %x[ #{cmd} ] | |
puts "#{fname} - msftidy check passed" if msftidy_output.empty? | |
msftidy_output.each_line do |line| | |
valid = false | |
puts line | |
end | |
end | |
puts "-" * 52 | |
end | |
unless valid | |
puts "msftidy.rb objected, aborting commit" | |
puts "To bypass this check use: git commit --no-verify" | |
puts "-" * 52 | |
exit(1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Originally by @h0ng10