Skip to content

Commit 9b8325b

Browse files
committed
getDiffRanges: improve handling for missing patch
1 parent b9a60fa commit 9b8325b

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
@@ -361,6 +361,20 @@ function getDiffRanges(
361361
logger: Logger,
362362
): DiffThunkRange[] | undefined {
363363
if (fileDiff.patch === undefined) {
364+
if (fileDiff.changes === 0) {
365+
// There are situations where a changed file legitimately has no diff.
366+
// For example, the file may be a binary file, or that the file may have
367+
// been renamed with no changes to its contents. In these cases, the
368+
// file would be reported as having 0 changes, and we can return an empty
369+
// array to indicate no diff range in this file.
370+
return [];
371+
}
372+
// If a file is reported to have nonzero changes but no patch, that may be
373+
// due to the file diff being too large. In this case, we should return
374+
// undefined to indicate that we cannot process the diff.
375+
logger.warning(
376+
`No patch found for file ${fileDiff.filename} with ${fileDiff.changes} changes.`,
377+
);
364378
return undefined;
365379
}
366380

0 commit comments

Comments
 (0)