From b25b4680f223bad2492341a77ddf69cb684aa3f4 Mon Sep 17 00:00:00 2001 From: Joanna Wang Date: Fri, 26 Jan 2024 16:48:40 +0000 Subject: [PATCH] Make scm.ListSubmodules return paths for the OS. Bug: 1522071 Change-Id: Ifbdfc456fbfb0a74d68c7109aa8bd3deae612e39 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5236697 Reviewed-by: Josip Sokcevic Commit-Queue: Joanna Wang --- scm.py | 10 ++++++++-- tests/scm_unittest.py | 11 ++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/scm.py b/scm.py index b84662add..f40b79e9d 100644 --- a/scm.py +++ b/scm.py @@ -463,13 +463,19 @@ class GIT(object): @staticmethod def ListSubmodules(repo_root): # type: (str) -> Collection[str] - """Returns the list of submodule paths for the given repo.""" + """Returns the list of submodule paths for the given repo. + + Path separators will be adjusted for the current OS. + """ if not os.path.exists(os.path.join(repo_root, '.gitmodules')): return [] config_output = GIT.Capture( ['config', '--file', '.gitmodules', '--get-regexp', 'path'], cwd=repo_root) - return [line.split()[-1] for line in config_output.splitlines()] + return [ + line.split()[-1].replace('/', os.path.sep) + for line in config_output.splitlines() + ] @staticmethod def CleanupDir(cwd, relative_dir): diff --git a/tests/scm_unittest.py b/tests/scm_unittest.py index b46b387de..7cc43595c 100755 --- a/tests/scm_unittest.py +++ b/tests/scm_unittest.py @@ -132,14 +132,19 @@ class GitWrapperTestCase(unittest.TestCase): actual_state = scm.GIT.IsVersioned('cwd', 'dir') self.assertEqual(actual_state, scm.VERSIONED_DIR) - @mock.patch('scm.GIT.Capture') @mock.patch('os.path.exists', return_value=True) - def testListSubmodules(self, mockExists, mockCapture): + @mock.patch('scm.GIT.Capture') + def testListSubmodules(self, mockCapture, *_mock): mockCapture.return_value = ( 'submodule.submodulename.path foo/path/script' '\nsubmodule.submodule2name.path foo/path/script2') actual_list = scm.GIT.ListSubmodules('root') - self.assertEqual(actual_list, ['foo/path/script', 'foo/path/script2']) + if sys.platform.startswith('win'): + self.assertEqual(actual_list, + ['foo\\path\\script', 'foo\\path\\script2']) + else: + self.assertEqual(actual_list, + ['foo/path/script', 'foo/path/script2']) def testListSubmodules_missing(self): self.assertEqual(scm.GIT.ListSubmodules('root'), [])