-
-
Save yoppi/1119921 to your computer and use it in GitHub Desktop.
update any repositories.
This file contains hidden or 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
#!/usr/bin/env ruby | |
# -*- coding:utf-8 -*- | |
require 'pathname' | |
module VCSCommand | |
@@vcs_update_table = { | |
'.git' => 'git pull', | |
'.hg' => 'hg pull -u', | |
'.svn' => 'svn up', | |
'.bzr' => 'bzr up', | |
} | |
def repository? | |
self.directory? && metadata? | |
end | |
def metadata? | |
@@vcs_update_table.has_key?(File.basename(self)) | |
end | |
def update | |
Dir::chdir(File.dirname(File.expand_path(self))) { | |
puts "UPDATE #{Pathname::pwd()}" | |
system(update_comamnd()) | |
} | |
end | |
def update_comamnd | |
@@vcs_update_table[File.basename(self)] | |
end | |
end | |
class Pathname; include VCSCommand; end | |
dir = ARGV.shift || '.' | |
Pathname.new(dir).each_child.select {|file| file.repository? }. | |
each {|repository| repository.update } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment