Commit c1ab7349 authored by Josip Sokcevic's avatar Josip Sokcevic Committed by LUCI CQ

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 <sokcevic@google.com>
Reviewed-by: 's avatarGavin Mak <gavinmak@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
parent 368f980b
......@@ -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]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment