Commit ff46da8d authored by Michael Achenbach's avatar Michael Achenbach Committed by Commit Bot

Presubmit: Fix relative owners check

This ensures relative file: directives in OWNERS files also work if
the directory of the owners file gets deleted.

Bug: 1015444
Change-Id: I9471a28a7246513120dd3ebb924f6d64eb50c2df
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1870249Reviewed-by: 's avatarTamer Tas <tmrts@chromium.org>
Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@google.com>
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
parent 5b929a49
......@@ -441,7 +441,7 @@ class Database(object):
else:
assert start.startswith(self.root)
start = self.os_path.dirname(self.os_path.relpath(start, self.root))
include_path = self.os_path.join(start, path)
include_path = self.os_path.normpath(self.os_path.join(start, path))
if include_path in self.override_files:
return include_path
......
......@@ -77,6 +77,19 @@ class MockFileSystem(object):
def open_for_reading(self, path):
return StringIO.StringIO(self.read_binary_file(path))
def normpath(self, path):
# This is not a complete implementation of normpath. Only covers what we
# use in tests.
result = []
for part in path.split(self.sep):
if part == '..':
result.pop()
elif part == '.':
continue
else:
result.append(part)
return self.sep.join(result)
def read_binary_file(self, path):
# Intentionally raises KeyError if we don't recognize the path.
if self.files[path] is None:
......
......@@ -52,6 +52,7 @@ def test_repo():
'/chrome/renderer/OWNERS': owners_file(peter),
'/chrome/renderer/gpu/gpu_channel_host.h': '',
'/chrome/renderer/safe_browsing/scorer.h': '',
'/chrome/tools/OWNERS': owners_file(file='../OWNERS'),
'/content/OWNERS': owners_file(john, darin, comment='foo', noparent=True),
'/content/comment/OWNERS': owners_file(john + ' # for comments',
darin + ' # for everything else'),
......@@ -415,6 +416,10 @@ class ReviewersForTest(_BaseTestCase):
[[john],
[darin]])
def test_reviewers_for__relative_owners_file(self):
self.assert_reviewers_for(['chrome/tools/OWNERS'],
[[ben], [brett]])
def test_reviewers_for__valid_inputs(self):
db = self.db()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment