Last active
August 29, 2015 14:27
-
-
Save Jiggins/e93945a87eb35ddf47f8 to your computer and use it in GitHub Desktop.
ruby compare_dirs.rb /path/to/dir1 /path/to/dir2
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 'pp' | |
# https://gist.github.com/awesome/3842062 | |
def dirHash(path) | |
Dir["#{path}/**/*"].inject({}) {|h,i| t = h; i.split("/").each {|n| t[n] ||= {}; t = t[n]}; h} | |
end | |
# https://gist.github.com/henrik/146844 | |
def deep_diff(a,b) | |
(a.keys | b.keys).inject({}) do |diff, k| | |
if a[k] != b[k] | |
if a[k].respond_to?(:deep_diff) && b[k].respond_to?(:deep_diff) | |
diff[k] = a[k].deep_diff(b[k]) | |
else | |
diff[k] = [a[k], b[k]] | |
end | |
end | |
diff | |
end | |
end | |
pp deep_diff(dirHash(ARGV[0]), dirHash(ARGV[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment