зеркало из https://github.com/github/ruby.git
Limit uplevel travarsing
* tool/vcs.rb (VCS.detect): limit level of travarsing parent directories, 0 by the default. curretly always detecting at the source directory itself. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66305 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
fec4b2225e
Коммит
f798ff4c43
|
@ -124,12 +124,16 @@ class VCS
|
|||
@@dirs << [dir, self, pred]
|
||||
end
|
||||
|
||||
def self.detect(path)
|
||||
def self.detect(path, uplevel_limit: 0)
|
||||
curr = path
|
||||
begin
|
||||
@@dirs.each do |dir, klass, pred|
|
||||
return klass.new(curr) if pred ? pred[curr, dir] : File.directory?(File.join(curr, dir))
|
||||
end
|
||||
if uplevel_limit
|
||||
break if uplevel_limit.zero?
|
||||
uplevel_limit -= 1
|
||||
end
|
||||
prev, curr = curr, File.realpath(File.join(curr, '..'))
|
||||
end until curr == prev # stop at the root directory
|
||||
raise VCS::NotFoundError, "does not seem to be under a vcs: #{path}"
|
||||
|
|
Загрузка…
Ссылка в новой задаче