[presubmit] Check if .gitmodules diverges from DEPS

Raise presubmit error if .gitmodules file contains entry that doesn't
have gitlink, nor DEPS entry. This is desired as some tooling started to
depend on .gitmodules to learn about git dependencies.

Tested manually on chromium/src, based on the bug report test case.

R=ddoman@google.com

Bug: 392766700
Change-Id: I9dd8e03503b151f75e548acd0af098f342fc77a6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6219822
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
changes/22/6219822/4
Josip Sokcevic 3 months ago committed by LUCI CQ
parent ce598256f2
commit 9fd46c2b6b

@ -2061,8 +2061,17 @@ def CheckForCommitObjects(input_api, output_api):
gitmodules_file = input_api.os_path.join(input_api.PresubmitLocalPath(),
'.gitmodules')
with open(gitmodules_file) as f:
gitmodules_content = f.read()
import configparser
config = configparser.ConfigParser()
config.read(gitmodules_file)
gitmodule_paths = set([])
for name, section in config.items():
if not name.startswith('submodule '):
continue
if 'path' not in section:
continue
gitmodule_paths.add(section['path'])
mismatch_entries = []
deps_msg = ""
@ -2094,7 +2103,9 @@ def CheckForCommitObjects(input_api, output_api):
'Make sure DEPS paths match those in .gitmodules \n'
f'and a gitlink exists at {dep_path}.')
]
if f'path = {submodule_path}' not in gitmodules_content:
try:
gitmodule_paths.remove(submodule_path)
except KeyError:
return [
output_api.PresubmitError(
f'No submodule with path {submodule_path} in '
@ -2123,6 +2134,18 @@ def CheckForCommitObjects(input_api, output_api):
'The following entries diverged: ' + deps_msg)
]
if len(gitmodule_paths) > 0:
return [
output_api.PresubmitError(
'.gitmodules file contains submodules that no longer exist\n'
'in DEPS or Git (gitlink).\n'
'Remove the following entries from .gitmodules:\n'
'\n\t' + '\n\t'.join(gitmodule_paths) +
'\n\nor run the following command:\n'
' gclient gitmodules\n')
]
return []

Loading…
Cancel
Save