mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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:
parent
fec4b2225e
commit
f798ff4c43
1 changed files with 5 additions and 1 deletions
|
@ -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}"
|
||||
|
|
Loading…
Reference in a new issue