Commit 98cfac11 authored by Edward Lemur's avatar Edward Lemur Committed by LUCI CQ

scm: Add GetAllFiles method.

Will be used by presubmit_support to run checks over all files on a repo.

Bug: 1042324
Change-Id: I872b4eb7f287f3a4b14d753cad73d0c5d7beb00c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2002961Reviewed-by: 's avatarAnthony Polito <apolito@google.com>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent a5799e3b
......@@ -321,6 +321,12 @@ class GIT(object):
'--name-only', branch + "..." + branch_head]
return GIT.Capture(command, cwd=cwd).splitlines(False)
@staticmethod
def GetAllFiles(cwd):
"""Returns the list of all files under revision control."""
command = ['-c', 'core.quotePath=false', 'ls-files', '--', '.']
return GIT.Capture(command, cwd=cwd).splitlines(False)
@staticmethod
def GetPatchName(cwd):
"""Constructs a name for this patch."""
......
......@@ -85,10 +85,10 @@ class RealGitTest(fake_repos.FakeReposTestBase):
self.enabled = self.FAKE_REPOS.set_up_git()
if self.enabled:
self.clone_dir = scm.os.path.join(self.FAKE_REPOS.git_base, 'repo_1')
else:
self.skipTest('git fake repos not available')
def testIsValidRevision(self):
if not self.enabled:
return
# Sha1's are [0-9a-z]{32}, so starting with a 'z' or 'r' should always fail.
self.assertFalse(scm.GIT.IsValidRevision(cwd=self.clone_dir, rev='zebra'))
self.assertFalse(scm.GIT.IsValidRevision(cwd=self.clone_dir, rev='r123456'))
......@@ -98,8 +98,6 @@ class RealGitTest(fake_repos.FakeReposTestBase):
self.assertTrue(scm.GIT.IsValidRevision(cwd=self.clone_dir, rev='HEAD'))
def testIsAncestor(self):
if not self.enabled:
return
self.assertTrue(scm.GIT.IsAncestor(
self.clone_dir, self.githash('repo_1', 1), self.githash('repo_1', 2)))
self.assertFalse(scm.GIT.IsAncestor(
......@@ -107,6 +105,9 @@ class RealGitTest(fake_repos.FakeReposTestBase):
self.assertFalse(scm.GIT.IsAncestor(
self.clone_dir, self.githash('repo_1', 1), 'zebra'))
def testGetAllFiles(self):
self.assertEqual(['DEPS','origin'], scm.GIT.GetAllFiles(self.clone_dir))
if __name__ == '__main__':
if '-v' in sys.argv:
......
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