fix: preserve line endings when updating a file - #48
Merged
Merged
Conversation
Owner
Author
|
Lead in-session review at 6a03692: PASS. |
Updates split the file on LF and joined it back with LF, so a one-line patch rewrote every line of a CRLF or mixed-ending file. The file is now parsed into lines that keep their own ending; a chunk is replaced around its context lines, which keep their exact text and ending; inserted lines take the file's first ending. This is Codex's PreserveLineEndings model (text_file.rs, compute_replacements). Fixes #47
code-yeongyu
force-pushed
the
fix/preserve-line-endings
branch
from
October 3, 2026 12:28
6a03692 to
abf6c13
Compare
This was referenced Oct 3, 2026
Merged
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 #47.
Summary
The bug: an update split the file on LF and joined it back with LF, so a one-line patch rewrote every line of a CRLF or mixed-ending file. That showed up in git, and in the tool's own preview as a whole-file diff.
The model:
src/line-endings.tsparses the file into lines that keep their own ending (\r\n,\n, or a lone\r). A matched chunk is replaced around its context lines, so those keep their exact text and ending. Inserted lines take the file's first ending. Every line still ends with one, as before. This is Codex's PreserveLineEndings model (text_file.rs,file_update.rscompute_replacements).Codex comparison: in Codex this model is behind
apply_patch_preserve_line_endings(under development, default off), and its conformance scenarios run with it on. oh-my-pi restores the detected file ending after edits.Two user-visible changes:
LF-only files produce the same bytes as before.
Verification
bun run check(typecheck + biome)bun run test: 67/67test/line-endings.test.ts: 6 user-facing cases. Four fail onmainand pass here: CRLF update with an insertion, mixed endings, a trimmed-match context line, and a CRLF one-line change counting (+1 -1) in the tool's rendered result. The other two pass on both and guard against regressions: an LF file without a final newline, and a failed hunk on a CRLF file leaving its bytes untouched.npm pack --dry-runincludessrc/line-endings.tsapply_patch impact
[Unreleased]