Skip to content

fix: prepend line origin chars in diff.print() output#213

Draft
monotykamary wants to merge 1 commit into
toss:mainfrom
monotykamary:fix/diff-print-line-origin
Draft

fix: prepend line origin chars in diff.print() output#213
monotykamary wants to merge 1 commit into
toss:mainfrom
monotykamary:fix/diff-print-line-origin

Conversation

@monotykamary

Copy link
Copy Markdown

Problem

diff.print() (default Patch format) was stripping the +/-/ (space) line origin prefixes from hunk body lines, making the output unparseable for consumers that need to distinguish additions from deletions from context. Closes #212.

Before

@@ -1 +1 @@
A
A modified

After

@@ -1 +1 @@
-A
+A modified

What changed

In src/diff.rs, the print callback now reads line.origin() and prepends it for the three content-line origins ( context, + addition, - deletion). Other origin types are excluded because their content is already fully formatted by libgit2:

Origin Char Treatment
Context Prepended
Addition + Prepended
Deletion - Prepended
ContextEOFNL = Not prepended (content is \ No newline at end of file)
AddEOFNL > Not prepended
DeleteEOFNL < Not prepended
FileHeader F Not prepended (content is diff --git, ---, +++)
HunkHeader H Not prepended (content is @@ ... @@)
Binary B Not prepended (content is Binary files ... differ)

This applies to all DiffFormat variants that go through the print callback, not just Patch.

Test plan

  • Updated tests/diff.spec.ts "print diff with formatting" expectations to include +/- prefixes
  • All 210 existing tests pass (34 test files)
  • PatchHeader, NameOnly, Raw formats unchanged (verified test expectations still match)

The print() callback was using line.content() without the origin
character, producing patch output missing +/-/ space prefixes on
hunk body lines. Context lines got no space prefix, additions got
no +, deletions got no -.

Prepend the origin for context (space), addition (+), and deletion
(-) lines. Other origins (F for file headers, H for hunk headers,
B for binary, = > < for EOFNL markers) are excluded because their
content is already fully formatted by libgit2 and should not have
a prefix.

Closes toss#212
@monotykamary monotykamary requested a review from seokju-na as a code owner June 14, 2026 16:32
@vercel

vercel Bot commented Jun 14, 2026

Copy link
Copy Markdown

@monotykamary is attempting to deploy a commit to the Toss Team on Vercel.

A member of the Team first needs to authorize it.

@monotykamary monotykamary marked this pull request as draft June 18, 2026 13:31
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

Successfully merging this pull request may close these issues.

diff.print({ format: "Patch" }) strips +/-/space line origin markers

1 participant