Skip to content

Instantly share code, notes, and snippets.

Created December 30, 2012 19:12
Show Gist options
  • Save anonymous/4414461 to your computer and use it in GitHub Desktop.
Save anonymous/4414461 to your computer and use it in GitHub Desktop.
This git hook script checks every file in the commit with msftidy.rb from the metasploit framework If msftidy.rb complains the commit is aborted. To install this script, copy it to ".git/hooks/pre-commit" and make it executeable
#!/usr/bin/env ruby
# This git hook script checks every file in the commit with msftidy.rb
# If msftidy.rb complains the commit is aborted.
#
# To install this script, copy it to ".git/hooks/pre-commit" and make it executeable
invalid = false
puts "--- msftidy.rb ---------------------------------------------"
results = %x[git diff --cached --name-only]
results.each_line do |script|
script.strip!
next unless File.exist?(script) and File.file?(script)
cmd = "./tools/msftidy.rb #{script}"
msftidy_output= %x[ #{cmd} ]
msftidy_output.each_line do |line|
invalid = true
puts line
end
end
puts "------------------------------------------------------------"
if invalid then
puts "msftidy.rb says no, aborting commit"
puts "To bypass this check use: git commit --no-verify"
puts "------------------------------------------------------------"
exit(1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment