Robert Klemme
2/14/2008 10:27:00 AM
2008/2/13, Dominic Sisneros <dsisnero@gmail.com>:
> require 'fileutils'
> require 'find'
>
> include FileUtils::Verbose
>
> GIT_DIR = File.expand_path("~/programming/repos")
>
> def find_git(dir)
> git_repo = lambda{|d| Dir.entries(d).include?('.git') }
> dirs = []
> Find.find(dir) do |f |
> Find.prune if f == "."
> next if dirs.include? File.basename(f)
> if FileTest.directory? f
> dirs << f if git_repo[f]
> end
> end
> dirs
> end
>
> git_dirs = find_git(GIT_DIR)
>
> puts git_dirs.inspect
> git_dirs.each do |repo|
> cd repo do
> system('git pull')
> end
> end
Not sure whether this is faster but it's shorter:
dirs = Hash.new do |h,dir|
Dir.chdir dir { system 'git pull' }
h[dir] = true
end
Dir[File.join(File.expand_path("~/programming/repos"), "**",
"*.git")].each do |gf|
dirs[File.basename(gf)]
end
Alternative
require 'set'
dirs = Set.new
Find.find File.expand_path("~/programming/repos") do |f|
dir = File.dirname f
if File.file? f and /\.git$/ =~ f and dirs.add? dir
Dir.chdir dir { system 'git pull' }
end
end
Cheers
robert
--
use.inject do |as, often| as.you_can - without end