Skip to content

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

Closed
@DavisVaughan

Description

@DavisVaughan

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 😢

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions