# Is there a faster way? using Find to update repositories

**URL:** <https://www.ruby-forum.com/t/is-there-a-faster-way-using-find-to-update-repositories/129050>\
**Category:** Ruby\
**Created:** [February 13, 2008, 8:38pm UTC](https://www.ruby-forum.com/t/is-there-a-faster-way-using-find-to-update-repositories/129050 "2008-02-13T20:38:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![3nd3r](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/3/c4cdca/32.png) [@3nd3r](https://www.ruby-forum.com/u/3nd3r)\
**Post date:** [February 13, 2008, 8:38pm UTC](https://www.ruby-forum.com/t/is-there-a-faster-way-using-find-to-update-repositories/129050/1 "2008-02-13T20:38:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![3nd3r](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/3/c4cdca/32.png) [@3nd3r](https://www.ruby-forum.com/u/3nd3r)\
**Post date:** [February 14, 2008, 11:28am UTC](https://www.ruby-forum.com/t/is-there-a-faster-way-using-find-to-update-repositories/129050/2 "2008-02-14T11:28:12Z")

</div>

2008/2/13, Dominic S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Find.find(dir) do |f |
> 
> 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
