Created
October 1, 2008 02:04
-
-
Save therealadam/14004 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 | |
# | |
# Seeking to answer man's eternal question "I wonder how many little Git | |
# repositories I have just floating around in my home directory. Further, I | |
# wonder how many actually have a remote somewhere." | |
# | |
# Usage: | |
# | |
# Search for Git repositories in the specified directory | |
# > ruby git_finder.rb some_dir another_dir ... | |
# | |
# (c) Copyright 2008 Adam Keys. MIT licensed or some-such. | |
class GitFinder | |
def self.run(dirs) | |
dirs.each do |dir| | |
Dir.chdir(dir) do | |
gf = new | |
gf.find_repos | |
puts "#{dir},#{gf.repos.length},#{gf.repos.select { |r| r.has_remote? }.length}" | |
end | |
end | |
end | |
attr_reader :repos | |
def initialize | |
@repos = [] | |
end | |
def find_repos | |
@repos = Dir['**/.git'].map { |dir| print '.'; Repository.new(dir) } | |
puts | |
end | |
class Repository | |
def initialize(dir) | |
@dir = dir | |
end | |
def has_remote? | |
Dir.chdir(File.join(@dir, '..')) do | |
puts "In #{@dir}" if ENV['DEBUG'] | |
`git remote`.length > 0 | |
end | |
end | |
end | |
end | |
GitFinder.run(ARGV) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment