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
parent
5397fdbf02
commit
eb2e4cbdef
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue