vcs.rb: git worktree

* tool/vcs.rb (VCS.detect, VCS::GIT): support working directory
  created by `git worktree`.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53601 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-01-20 08:17:57 +00:00
parent 131f699d98
commit 1bdc2d5150
1 changed files with 7 additions and 5 deletions

View File

@ -67,13 +67,15 @@ class VCS
class NotFoundError < RuntimeError; end class NotFoundError < RuntimeError; end
@@dirs = [] @@dirs = []
def self.register(dir) def self.register(dir, &pred)
@@dirs << [dir, self] @@dirs << [dir, self, pred]
end end
def self.detect(path) def self.detect(path)
@@dirs.each do |dir, klass| @@dirs.each do |dir, klass, pred|
return klass.new(path) if File.directory?(File.join(path, dir)) if pred ? pred[path, dir] : File.directory?(File.join(path, dir))
return klass.new(path)
end
prev = path prev = path
loop { loop {
curr = File.realpath(File.join(prev, '..')) curr = File.realpath(File.join(prev, '..'))
@ -282,7 +284,7 @@ class VCS
end end
class GIT < self class GIT < self
register(".git") register(".git") {|path, dir| File.exist?(File.join(path, dir))}
def self.get_revisions(path, srcdir = nil) def self.get_revisions(path, srcdir = nil)
gitcmd = %W[git] gitcmd = %W[git]