Skip to content

Bug: diffAcceptRejectHunk throws on FileDiffMetadata from patch #427

@jonatanklosko

Description

@jonatanklosko

Prerequisites

Describe the issue

Hello, thank you for this great library!

Given FileDiffMetadata obtained via parsePatchFiles, using diffAcceptRejectHunk throw with an error:

resolveRegion.ts:230 Uncaught Error: pushCollapsedContextLines: missing collapsed context line
    at pushCollapsedContextLines (resolveRegion.ts:230:13)
    at resolveRegion (resolveRegion.ts:79:5)
    at diffAcceptRejectHunk (diffAcceptRejectHunk.ts:24:10)

Reproduction

In the docs example:

export const ACCEPT_REJECT_EXAMPLE: PreloadFileDiffOptions<AcceptRejectMetadata> =
{
fileDiff: parseDiffFromFile(ACCEPT_REJECT_OLD_FILE, ACCEPT_REJECT_NEW_FILE),
options: {
theme: 'pierre-dark',
diffStyle: 'unified',
},
annotations: ACCEPT_REJECT_ANNOTATIONS,
};

Use a file diff from patch, for example:

  fileDiff: parsePatchFiles(`diff --git a/index.html b/index.html
index 36c553c..711c67c 100644
--- a/index.html
+++ b/index.html
@@ -6,8 +6,9 @@
  </head>
  <body>
  <header>
-  <h1>Welcome</h1>
-  <p>Thanks for visiting</p>
+  <h1>Welcome to Our Site</h1>
+  <p>We're glad you're here</p>
+  <a href="/about" class="btn">Learn More</a>
  </header>
  <footer>
    <p>&copy; Acme Inc.</p>`)[0].files[0],

Then accept or reject the hunk.

What browser(s) are you seeing the problem on?

No response

What version of @pierre/diffs are you using?

Tested on main (1a35f2f)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions