Created
May 27, 2013 12:30
-
-
Save Andrew8xx8/5656831 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/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