From 98cfac11bd02507564d03ff5c3d328c97ab9abdf Mon Sep 17 00:00:00 2001 From: Edward Lemur Date: Fri, 17 Jan 2020 19:27:01 +0000 Subject: [PATCH] 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/+/2002961 Reviewed-by: Anthony Polito Commit-Queue: Edward Lesmes --- scm.py | 6 ++++++ tests/scm_unittest.py | 9 +++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/scm.py b/scm.py index a1699fb6d..a34111304 100644 --- a/scm.py +++ b/scm.py @@ -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.""" diff --git a/tests/scm_unittest.py b/tests/scm_unittest.py index 279aecf82..03fc43291 100755 --- a/tests/scm_unittest.py +++ b/tests/scm_unittest.py @@ -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: