Skip to content

Single line change parse issue with "normal" chunk headers #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
DavisVaughan opened this issue Apr 27, 2025 · 0 comments
Open

Single line change parse issue with "normal" chunk headers #36

DavisVaughan opened this issue Apr 27, 2025 · 0 comments

Comments

@DavisVaughan
Copy link

See parkerbxyz/suggest-changes#50 (comment)

The TLDR is that it seems like parse-git-diff can handle @@ -74,2 +74 @@, but for 1 line changes git will omit the ,1 and just report @@ -74 +74 @@ and that causes the regex handling in parse-git-diff to break.

I see the "normal" chunk regex here:

const normalChunkExec =
/^@@\s\-(\d+),?(\d+)?\s\+(\d+),?(\d+)?\s@@\s?(.+)?/.exec(line);

Which gets expanded out here:

const [all, delStart, delLines, addStart, addLines, context] =
normalChunkExec;

I'm no expert here but I think whats happening is that it has an optional capture group for the ,<digit> which should become delLines, but that's missing here so instead the next capture group actually gets put in as delLines, which happens to be addStart, which is 94, so it reports 94 lines in fromFileRange 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant