From c1ab734908f09df3d4c6672acd66c0cfcd584114 Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Thu, 24 Feb 2022 19:02:44 +0000 Subject: [PATCH] Handle no changed content in presubmit support git cl presubmit has --all option which marks all files as modified. However, that doesn't work well with SCM diff. That is, git diff may not contain affected file. Instead of throwing an exception in such case, just return no diff. R=gavinmak@google.com Fixed: 808346 Change-Id: Ie1d534b8eebc84bc5206eba7db8057829390fbec Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3485501 Auto-Submit: Josip Sokcevic Reviewed-by: Gavin Mak Commit-Queue: Gavin Mak --- presubmit_support.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/presubmit_support.py b/presubmit_support.py index 84d5711fc..0b4999284 100755 --- a/presubmit_support.py +++ b/presubmit_support.py @@ -925,8 +925,12 @@ class _GitDiffCache(_DiffCache): (normpath(path), ''.join(diff)) for path, diff in diffs.items()) if path not in self._diffs_by_file: - raise PresubmitFailure( - 'Unified diff did not contain entry for file %s' % path) + # SCM didn't have any diff on this file. It could be that the file was not + # modified at all (e.g. user used --all flag in git cl presubmit). + # Intead of failing, return empty string. + # See: https://crbug.com/808346. + logging.warning('No diff found for %s' % path) + return '' return self._diffs_by_file[path]