Skip to content

Instantly share code, notes, and snippets.

@Andrew8xx8
Created May 27, 2013 12:30
Show Gist options
  • Select an option

  • Save Andrew8xx8/5656831 to your computer and use it in GitHub Desktop.

Select an option

Save Andrew8xx8/5656831 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'fileutils'
require 'optparse'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: #{__FILE__} -r REGEXP START_PATH"
opts.on("-r", "Pattern") do |v|
options[:regexp] = v
end
end.parse!
unless ARGV[0] && options[:regexp]
puts "Usage: #{__FILE__} -r REGEXP START_PATH"
exit
end
def search_submodules(start_dir, options)
Dir.glob(File.join(start_dir, "*/")) do |dir|
if File.exists?(File.join(dir, ".git")) || File.exists?(File.join(dir, "HEAD"))
count_objects = `cd #{dir} && git count-objects -v`
unless /count:\s0.*?size:\s0.*?packs:\s0/m =~ count_objects
puts "Repository: #{dir}"
objects = `cd #{dir} && git grep #{options[:regexp]} HEAD`
puts objects
end
else
search_submodules(dir, options)
end
end
end
search_submodules(ARGV[0], options)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment