-
-
Save maxy/205605 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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