Skip to content

Commit 3dd972f

Browse files
committed
getDiffRanges: improve handling for missing patch
1 parent b1ee4ef commit 3dd972f

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

0 commit comments

Comments
 (0)