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: Gavin Mak <gavinmak@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
changes/01/3485501/2
Josip Sokcevic 3 years ago committed by LUCI CQ
parent 368f980b6d
commit c1ab734908

@ -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]

Loading…
Cancel
Save