presubmit: update CheckPatchFormatted to pass --input_diff_file

Once devs update depot_tools, this will take effect in both
terminal and CiderG

TESTED: http://go/scrcast/NjM1MzE5NDc4NjQ4ODMyMHxmMzc3NGVlZi03Yg
Bug: 386840832
Change-Id: Ibb8f74bffd662eb330f61b9e82bcd75c09bbc232
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6937365
Commit-Queue: Scott Lee <ddoman@chromium.org>
Reviewed-by: Gavin Mak <gavinmak@google.com>
This commit is contained in:
Scott Lee
2025-09-11 10:40:14 -07:00
committed by LUCI CQ
parent 363e910475
commit 4689d66abf

View File

@@ -1838,6 +1838,10 @@ def CheckPatchFormatted(input_api,
result_factory=None):
result_factory = result_factory or output_api.PresubmitPromptWarning
import git_cl
affected_files = input_api.AffectedFiles(include_deletes=False)
with input_api.CreateTemporaryFile() as diff_file:
for f in affected_files:
diff_file.write(f.GenerateScmDiff().encode('utf-8'))
display_args = []
if not check_clang_format:
@@ -1857,8 +1861,13 @@ def CheckPatchFormatted(input_api,
cmd = [
'-C',
input_api.change.RepositoryRoot(), 'cl', 'format', '--dry-run',
'--presubmit'
input_api.change.RepositoryRoot(),
'cl',
'format',
'--dry-run',
'--presubmit',
'--input_diff_file',
diff_file.name,
] + display_args
# Make sure the passed --upstream branch is applied to a dry run.
@@ -1885,11 +1894,13 @@ def CheckPatchFormatted(input_api,
else:
short_path = input_api.basename(input_api.change.RepositoryRoot())
display_args.append(presubmit_subdir)
return [
result_factory('The %s directory requires source formatting. '
'Please run: git cl format %s' %
(short_path, ' '.join(display_args)))
]
msg = (
'The %s directory requires source formatting. '
'Please run: git cl format %s. Or, if you are in CiderG, '
'please use the "Format Modified Lines in All Files '
'(git cl format)" functionality in the command palette.' % (
short_path, ' '.join(display_args)))
return [result_factory(msg)]
return []