summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-10 01:58:28 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-10 01:58:28 +0000
commitf798ff4c43fc8cf7b00bd770d7eb78c0af664eee (patch)
tree7d5d5ef311da970680ff115f66ea5cd71e0acee3
parentfec4b2225eb9764c4de260562806e76a1264c530 (diff)
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
-rw-r--r--tool/vcs.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/tool/vcs.rb b/tool/vcs.rb
index db3e5cf4bc..b97334ecfb 100644
--- a/tool/vcs.rb
+++ b/tool/vcs.rb
@@ -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}"