Add post-merge capability to pre-commit-hook.rb

This will make it possible to run a post-merge check when
pre-commit-hook.rb is referenced as a symlink from .git/hooks/post-merge

The kind of check you're going to do is entirely dependant on the
basename of the file, which is a little weird but convenient.

Verification is a little tricky on this. Coming soon.
bug/bundler_fix
Tod Beardsley 2014-04-02 10:19:43 -05:00
parent 5397fdbf02
commit eb2e4cbdef
No known key found for this signature in database
GPG Key ID: 1EFFB682ADB9F193
1 changed files with 41 additions and 9 deletions

View File

@ -18,12 +18,38 @@
#
# ln -sf <this file> <path to commit hook>
def merge_error_message
msg = []
msg << "[*] This merge contains modules failing msftidy.rb"
msg << "[*] Please fix this if you intend to publish these"
msg << "[*] modules to a popular metasploit-framework repo"
puts "-" * 72
puts msg.join("\n")
puts "-" * 72
end
valid = true # Presume validity
files_to_check = []
results = %x[git diff --cached --name-only]
# Who called us? If it's a post-merge check things operate a little
# differently.
results.each_line do |fname|
case $0
when /post-merge/
base_caller = :post_merge
when /pre-commit/
base_caller = :post_commit
else
base_caller = :msftidy
end
if base_caller == :post_merge
changed_files = %x[git diff --name-only HEAD^ HEAD]
else
changed_files = %x[git diff --cached --name-only]
end
changed_files.each_line do |fname|
fname.strip!
next unless File.exist?(fname) and File.file?(fname)
next unless fname =~ /modules.+\.rb/
@ -31,9 +57,9 @@ results.each_line do |fname|
end
if files_to_check.empty?
puts "--- No Metasploit modules to check, committing. ---"
puts "--- No Metasploit modules to check ---"
else
puts "--- Checking module syntax with tools/msftidy.rb ---"
puts "--- Checking new and changed module syntax with tools/msftidy.rb ---"
files_to_check.each do |fname|
cmd = "ruby ./tools/msftidy.rb #{fname}"
msftidy_output= %x[ #{cmd} ]
@ -43,12 +69,18 @@ else
puts line
end
end
puts "-" * 52
puts "-" * 72
end
unless valid
puts "msftidy.rb objected, aborting commit"
puts "To bypass this check use: git commit --no-verify"
puts "-" * 52
exit(1)
if base_caller == :post_merge
puts merge_error_message
exit(0x10)
else
puts "[!] msftidy.rb objected, aborting commit"
puts "[!] To bypass this check use: git commit --no-verify"
puts "-" * 72
exit(0x01)
end
end