mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
Add ListSubmodules helper for presubmits.
We need this for this presubmit otherwise we cannot remove git deps from DEPS: http://shortn/_P7Xkt33SRx We will also be able to reuse this and replace: http://shortn/_WYBIUC9pa4 Bug: 1475770 Change-Id: I4cea689d130df77c344d82d4d8f9db02d42cd847 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5209098 Commit-Queue: Joanna Wang <jojwang@chromium.org> Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
This commit is contained in:
@@ -1336,6 +1336,10 @@ class Change(object):
|
||||
"""Convenience function."""
|
||||
return [af.AbsoluteLocalPath() for af in self.AffectedFiles()]
|
||||
|
||||
def ListSubmodules(self):
|
||||
"""Returns submodule paths for current change's repo."""
|
||||
return scm.GIT.ListSubmodules(self.change.RepositoryRoot())
|
||||
|
||||
def RightHandSideLines(self):
|
||||
"""An iterator over all text lines in 'new' version of changed files.
|
||||
|
||||
|
||||
11
scm.py
11
scm.py
@@ -455,6 +455,17 @@ class GIT(object):
|
||||
return VERSIONED_SUBMODULE
|
||||
return VERSIONED_DIR
|
||||
|
||||
@staticmethod
|
||||
def ListSubmodules(repo_root):
|
||||
# type: (str) -> Collection[str]
|
||||
"""Returns the list of submodule paths for the given repo."""
|
||||
if not os.path.exists(os.path.join(repo_root, '.gitmodules')):
|
||||
return []
|
||||
config_output = GIT.Capture(
|
||||
['git', 'config', '--file', '.gitmodules', '--get-regexp', 'path'],
|
||||
cwd=repo_root)
|
||||
return [line.split()[-1] for line in config_output.splitlines()]
|
||||
|
||||
@staticmethod
|
||||
def CleanupDir(cwd, relative_dir):
|
||||
"""Cleans up untracked file inside |relative_dir|."""
|
||||
|
||||
@@ -132,6 +132,18 @@ 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):
|
||||
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'])
|
||||
|
||||
def testListSubmodules_missing(self):
|
||||
self.assertEqual(scm.GIT.ListSubmodules('root'), [])
|
||||
|
||||
|
||||
class RealGitTest(fake_repos.FakeReposTestBase):
|
||||
def setUp(self):
|
||||
|
||||
Reference in New Issue
Block a user