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:
Joanna Wang
2024-01-18 19:53:42 +00:00
committed by LUCI CQ
parent 580b4ff3f5
commit 5400d9ef5a
3 changed files with 27 additions and 0 deletions

11
scm.py
View File

@@ -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|."""