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 <sokcevic@chromium.org>
Commit-Queue: Joanna Wang <jojwang@chromium.org>
changes/97/5236697/4
Joanna Wang 1 year ago committed by LUCI CQ
parent 3c8baffa8d
commit b25b4680f2

@ -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):

@ -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'), [])

Loading…
Cancel
Save