Skip to content

Instantly share code, notes, and snippets.

@raggi
Created March 8, 2011 18:06
Show Gist options
  • Save raggi/860670 to your computer and use it in GitHub Desktop.
Save raggi/860670 to your computer and use it in GitHub Desktop.
Tools of the trade. Update all repositories in a subdirectory, with faster github pulls.
#!/usr/bin/env ruby
gc = ARGV.shift if ARGV.first == "-gc"
Dir.chdir ARGV.first || File.expand_path(File.dirname(__FILE__))
io = IO.popen('exec ssh -MNqv git@github.com 2>&1')
waited = 0
until io.readline =~ /Entering interactive session/
sleep 0.01
waited += 1
if waited > 100
puts "github ssh still starting up"
break
end
end
Thread.new do
until io.eof?
line = io.readline
puts line unless line =~ /^debug1:/
end
end.abort_on_exception = true
io_shutdown = lambda do
system "kill #{io.pid}"
end
at_exit { io_shutdown.call }
trap(:INT) { exit }
require 'find'
def repo?(f)
%w(git/svn git svn hg).find do |type|
File.directory? File.join(f, ".#{type}")
end or
%w(darcs).find do |type|
File.directory? File.join(f, "_#{type}")
end
end
todo, skip = [], []
count = 0
current = nil
begin
Find.find('.') do |f|
next unless File.directory? f
if type = repo?(f)
todo << [type, f]
Find.prune
else
skip << f
end
end
puts "Updating #{todo.size} repositories"
trap(:INFO) do
puts "Repositories updated: #{count}/#{todo.size}\tCurrent: #{current}"
end
todo.each do |type, f|
print '.'; $stdout.flush
current = f
Dir.chdir(f) do
case type
when 'git/svn'
system "git svn fetch"
system "git svn rebase"
system "git gc --aggressive --prune" if gc
when 'git'
system "git fetch --all --tags -q --progress --prune"
system "git gc --aggressive --prune" if gc
when 'svn'
system 'svn up'
when 'hg'
system 'hg pull'
system 'hg update'
when 'darcs'
system 'darcs pull'
end
end
count += 1
end
puts
ensure
io_shutdown.call
end
puts
unless skip.empty?
puts "Skipped:"
require 'yaml'
y skip
end
puts
puts "Completed #{count} repositories"
@shwoodard
Copy link

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment