From 2d5c673fdb0072bb7b0c7463e6e7e18d0170b288 Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Mon, 21 Aug 2023 23:16:18 +0000 Subject: [PATCH] [scm] Fix list all files when filename has space Off by one - we should have 4 parts, so we need maxsplit=3. R=aravindvasudev@google.com, jojwang Fixed: 1474283 Change-Id: I13b568feb8ee2aa307a2267c43765c1749b77c90 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4799773 Auto-Submit: Josip Sokcevic Reviewed-by: Aravind Vasudevan Commit-Queue: Aravind Vasudevan --- scm.py | 2 +- testing_support/fake_repos.py | 25 ++++++++++++++----------- tests/scm_unittest.py | 3 ++- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/scm.py b/scm.py index ee9102510..85033937e 100644 --- a/scm.py +++ b/scm.py @@ -385,7 +385,7 @@ class GIT(object): command = ['-c', 'core.quotePath=false', 'ls-files', '-s', '--', '.'] files = GIT.Capture(command, cwd=cwd).splitlines(False) # return only files - return [f.split(maxsplit=4)[-1] for f in files if f.startswith('100')] + return [f.split(maxsplit=3)[-1] for f in files if f.startswith('100')] @staticmethod def GetPatchName(cwd): diff --git a/testing_support/fake_repos.py b/testing_support/fake_repos.py index 72bab68f2..31c5a3d27 100755 --- a/testing_support/fake_repos.py +++ b/testing_support/fake_repos.py @@ -233,8 +233,10 @@ class FakeRepos(FakeReposBase): 'origin': 'git/repo_3@2\n', }) - self._commit_git('repo_1', { - 'DEPS': """ + self._commit_git( + 'repo_1', + { + 'DEPS': """ vars = { 'DummyVariable': 'repo', 'false_var': False, @@ -272,15 +274,16 @@ deps_os = { 'src/repo4': '/repo_4', }, }""" % { - 'git_base': self.git_base, - # See self.__init__() for the format. Grab's the hash of the first - # commit in repo_2. Only keep the first 7 character because of: - # TODO(maruel): http://crosbug.com/3591 We need to strip the hash.. - # duh. - 'hash3': self.git_hashes['repo_3'][1][0][:7] - }, - 'origin': 'git/repo_1@1\n', - }) + 'git_base': self.git_base, + # See self.__init__() for the format. Grab's the hash of the + # first commit in repo_2. Only keep the first 7 character + # because of: TODO(maruel): http://crosbug.com/3591 We need to + # strip the hash.. duh. + 'hash3': self.git_hashes['repo_3'][1][0][:7] + }, + 'origin': 'git/repo_1@1\n', + 'foo bar': 'some file with a space', + }) self._commit_git('repo_2', { 'origin': 'git/repo_2@1\n', diff --git a/tests/scm_unittest.py b/tests/scm_unittest.py index 52d560d3c..661a9f3d0 100755 --- a/tests/scm_unittest.py +++ b/tests/scm_unittest.py @@ -170,7 +170,8 @@ class RealGitTest(fake_repos.FakeReposTestBase): self.assertFalse(scm.GIT.IsAncestor(self.githash('repo_1', 1), 'zebra')) def testGetAllFiles(self): - self.assertEqual(['DEPS','origin'], scm.GIT.GetAllFiles(self.cwd)) + self.assertEqual(['DEPS', 'foo bar', 'origin'], + scm.GIT.GetAllFiles(self.cwd)) def testGetSetConfig(self): key = 'scm.test-key'