Skip to content

Commit d4c56bb

Browse files
committed
getDiffRanges: improve handling for missing patch
1 parent 63d1f4f commit d4c56bb

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/analyze.ts

+14
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,20 @@ function getDiffRanges(
375375
logger: Logger,
376376
): DiffThunkRange[] | undefined {
377377
if (fileDiff.patch === undefined) {
378+
if (fileDiff.changes === 0) {
379+
// There are situations where a changed file legitimately has no diff.
380+
// For example, the file may be a binary file, or that the file may have
381+
// been renamed with no changes to its contents. In these cases, the
382+
// file would be reported as having 0 changes, and we can return an empty
383+
// array to indicate no diff range in this file.
384+
return [];
385+
}
386+
// If a file is reported to have nonzero changes but no patch, that may be
387+
// due to the file diff being too large. In this case, we should return
388+
// undefined to indicate that we cannot process the diff.
389+
logger.warning(
390+
`No patch found for file ${fileDiff.filename} with ${fileDiff.changes} changes.`,
391+
);
378392
return undefined;
379393
}
380394

0 commit comments

Comments
 (0)