Skip to content

Commit b4f41bd

Browse files
committed
getDiffRanges: improve handling for missing patch
1 parent 49aebe6 commit b4f41bd

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/analyze.ts

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

0 commit comments

Comments
 (0)