Skip to content

Instantly share code, notes, and snippets.

@yoppi
Forked from troter/update
Created August 2, 2011 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoppi/1119921 to your computer and use it in GitHub Desktop.
Save yoppi/1119921 to your computer and use it in GitHub Desktop.
update any repositories.
#!/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