From a4dee1b8212c5c438ee7f38cf798f20552c6be94 Mon Sep 17 00:00:00 2001 From: Gavin Mak Date: Wed, 7 Feb 2024 19:56:59 +0000 Subject: [PATCH] Make CheckForCommitObjects check gitlinks and .gitmodules issues.skia.org/issues/324072603: DEPS were renamed but the corresponding gitlinks and gitmodules entry were not updated. Update to check that 1. DEPS entries point to gitlinks (if SYNC) 2. .gitmodules entries match paths of gitlinks Bug: 324118800 Change-Id: I4c97b54c1912712aef309584bebaa4ea3b24d5df Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5273762 Reviewed-by: Josip Sokcevic Commit-Queue: Gavin Mak --- presubmit_canned_checks.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index f3cc6f6ab1..57cbace25a 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -1999,6 +1999,11 @@ def CheckForCommitObjects(input_api, output_api): for commit_tree_entry in commit_tree_entries: git_submodules[commit_tree_entry[2]] = commit_tree_entry[3] + gitmodules_file = input_api.os_path.join(input_api.PresubmitLocalPath(), + '.gitmodules') + with open(gitmodules_file) as f: + gitmodules_content = f.read() + mismatch_entries = [] deps_msg = "" for dep_path, dep in deps['deps'].items(): @@ -2019,7 +2024,23 @@ def CheckForCommitObjects(input_api, output_api): continue if commit_hash in git_submodules: - git_submodules.pop(commit_hash) + submodule_path = git_submodules.pop(commit_hash) + if not dep_path.endswith(submodule_path): + # DEPS entry path doesn't point to a gitlink. + return [ + output_api.PresubmitError( + f'Unexpected DEPS entry {dep_path}.\n' + f'Expected path to end with {submodule_path}.\n' + '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: + return [ + output_api.PresubmitError( + f'No submodule with path {submodule_path} in ' + '.gitmodules.\nMake sure entries in .gitmodules match ' + 'gitlink locations in the tree.') + ] else: mismatch_entries.append(dep_path) deps_msg += f"\n [DEPS] {dep_path} -> {commit_hash}"