summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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}"