fix: handle consecutive added empty file diff#38
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes handling of consecutive empty-file diffs and refines parsing logic to correctly classify file changes.
- Update comparison-line parsing to streamline
to/fromextraction - Change extended-header handling to skip comparison lines without consuming them
- Add fixtures, tests, and snapshots for empty-file and no-prefix scenarios; update existing snapshots
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/parse-git-diff.ts | Adjust token parsing in parseComparisonInputLine and header flow in parseExtendedHeader |
| src/tests/consecutive-empty-files.test.ts | Add test for parsing consecutive empty-file diffs |
| src/tests/snapshots/consecutive-empty-files.test.ts.snap | New snapshot for empty-file test |
| src/tests/snapshots/31.test.ts.snap | Update snapshot to reflect new file type classification |
| src/tests/31.test.ts | Remove .only from existing test suite |
| src/tests/31-no-prefix.test.ts | Add test for noPrefix option |
| src/fixtures/consecutive-empty-files | Add fixture representing multiple empty-file diffs |
| src/fixtures/31-no-prefix | Add fixture for no-prefix diff scenario |
Comments suppressed due to low confidence (1)
src/parse-git-diff.ts:138
- Destructuring the reversed split tokens can misassign 'to' and 'from' if the diff line contains extra segments. Consider filtering parts by 'b/' and 'a/' prefixes (e.g., using
find) to ensure correct file path extraction.
const [to, from] = line.split(' ').reverse();
| @@ -210,7 +207,7 @@ function parseChunk(context: Context): AnyChunk | undefined { | |||
|
|
|||
| function parseExtendedHeader(ctx: Context) { | |||
| if (isComparisonInputLine(ctx.getCurLine())) { | |||
There was a problem hiding this comment.
Returning null without consuming the comparison line may leave the parser cursor on the same line and disrupt subsequent parsing. Consider calling ctx.nextLine() before returning to advance properly.
Suggested change
| if (isComparisonInputLine(ctx.getCurLine())) { | |
| if (isComparisonInputLine(ctx.getCurLine())) { | |
| ctx.nextLine(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #31