Add AffectedSubmodules() to presubmit change.

+ Change scm GetAllFiles back to returning all files
  + should be safe to do since it's only used by presubmit code
+  add ignore_submodules option to CaptureStatus
  + It's used by other parts of depot_tools code
+ Add AffectedSubmodules to return submodules only
+ AffectedFiles still only returns non-submodule files.

Bug: 1475770
Change-Id: I457ad96099fb20eff4cc1a4fc84f59e7ae707abe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5216005
Auto-Submit: Joanna Wang <jojwang@chromium.org>
Commit-Queue: Joanna Wang <jojwang@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
This commit is contained in:
Joanna Wang
2024-01-19 19:47:44 +00:00
committed by LUCI CQ
parent 9a16009d09
commit 46cb7d0aca
3 changed files with 44 additions and 14 deletions

19
scm.py
View File

@@ -127,7 +127,10 @@ class GIT(object):
return output.strip() if strip_out else output
@staticmethod
def CaptureStatus(cwd, upstream_branch, end_commit=None):
def CaptureStatus(cwd,
upstream_branch,
end_commit=None,
ignore_submodules=True):
# type: (str, str, Optional[str]) -> Sequence[Tuple[str, str]]
"""Returns git status.
@@ -138,11 +141,15 @@ class GIT(object):
upstream_branch = GIT.GetUpstreamBranch(cwd)
if upstream_branch is None:
raise gclient_utils.Error('Cannot determine upstream branch')
command = [
'-c', 'core.quotePath=false', 'diff', '--name-status',
'--no-renames', '--ignore-submodules=all', '-r',
'%s...%s' % (upstream_branch, end_commit)
'--no-renames'
]
if ignore_submodules:
command.append('--ignore-submodules=all')
command.extend(['-r', '%s...%s' % (upstream_branch, end_commit)])
status = GIT.Capture(command, cwd)
results = []
if status:
@@ -398,10 +405,8 @@ class GIT(object):
@staticmethod
def GetAllFiles(cwd):
"""Returns the list of all files under revision control."""
command = ['-c', 'core.quotePath=false', 'ls-files', '-s', '--', '.']
files = GIT.Capture(command, cwd=cwd).splitlines(False)
# return only files
return [f.split(maxsplit=3)[-1] for f in files if f.startswith('100')]
command = ['-c', 'core.quotePath=false', 'ls-files', '--', '.']
return GIT.Capture(command, cwd=cwd).splitlines(False)
@staticmethod
def GetSubmoduleCommits(cwd, submodules):