Skip to content

Instantly share code, notes, and snippets.

@maxy
Forked from walf443/git-update.rb
Created October 9, 2009 01:20
Show Gist options
  • Save maxy/205605 to your computer and use it in GitHub Desktop.
Save maxy/205605 to your computer and use it in GitHub Desktop.
require 'pathname'
require 'logger'
require 'thread'
require 'open3'
class App
def initialize args
@logger = args[:logger] or raise "no logger"
@ignore = args[:ignore] || []
end
def run base
targets = Pathname.glob("#{base}/**/.git").sort
threads = []
targets.each do |dir|
next if @ignore.any? {|i| i =~ dir.to_s }
threads << Thread.new do |t|
@logger.info("start update #{dir}")
git_update dir.parent.realpath
@logger.info("end update #{dir}")
end
sleep 1 # stop too many access to github.
end
threads.each {|th| th.join }
end
private
def git_update dir
git_cmd = "git --git-dir=#{dir}/.git"
Open3.popen3 "#{git_cmd} remote update && #{git_cmd} config --get-regexp svn-remote > /dev/null && #{git_cmd} svn fetch" do |stdin, stdout, stderr|
stdout.each_line do |line|
@logger.info("#{dir}: #{line}")
end
stderr.each_line do |line|
@logger.error("#{dir}: #{line}")
end
end
end
end
def main
app = App.new(:logger => Logger.new($stderr), :ignore => [ %r{ruby/(pathobserver|rubycocoa)} ])
app.run Pathname(__FILE__).parent.realpath
end
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment