Is there a faster way? using Find to update repositories

D

Dominic Sisneros

[Note: parts of this message were removed to make it a legal post.]

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
 
R

Robert Klemme

2008/2/13 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top