#!/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)