Last active
December 18, 2015 13:19
-
-
Save gnarl/5788956 to your computer and use it in GitHub Desktop.
Find JAR file differences between git commits. Usage: ruby jar_compare.rb current_commit prev_commit git_directory
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
require 'fileutils' | |
require 'awesome_print' | |
def find_jars(revision, path) | |
FileUtils.cd path | |
puts %x{git checkout #{revision}} | |
result = [] | |
jars = Dir['**/*.jar'].sort | |
jars.each do |x| | |
md5sum = %x{md5 -q #{x}}.chomp | |
x.match(/(.*)\/(.*\.jar)\Z/) | |
result << "#{$1}:#{$2}:#{md5sum}" | |
end | |
puts %x{git checkout main} | |
result | |
end | |
def md5_matches(current, previous) | |
matches = [] | |
non_matches = [] | |
current.each do |cur| | |
cur_md5 = cur.split(':')[2] | |
matched = false | |
previous.each do |prev| | |
if prev.include? cur_md5 | |
matches << "#{cur} => #{prev}" | |
matched = true | |
end | |
end | |
non_matches << cur unless matched | |
end | |
return matches, non_matches | |
end | |
####################################### | |
current_rev = ARGV.shift | |
prev_rev = ARGV.shift | |
root_dir = ARGV.shift | |
abort "Usage: jar_compare.rb current_commit prev_commit git_directory" if current_rev.nil? || prev_rev.nil? | |
current_jar_list = find_jars(current_rev, root_dir) | |
#ap current_jar_list | |
prev_jar_list = find_jars(prev_rev, root_dir) | |
#ap prev_jar_list | |
matches, non_matches = md5_matches(current_jar_list, prev_jar_list) | |
puts "#############################################################" | |
puts "# MATCHES #" | |
puts "#############################################################" | |
ap matches | |
puts "#############################################################" | |
puts "# NEW #" | |
puts "#############################################################" | |
ap non_matches | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment