Skip to content

Instantly share code, notes, and snippets.

@therealadam
Created October 1, 2008 02:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save therealadam/14004 to your computer and use it in GitHub Desktop.
Save therealadam/14004 to your computer and use it in GitHub Desktop.
#!/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