Repository navigation
fix(core): preserve line endings in patch tool - #58324
Open
rekram1-node wants to merge 1 commit into
Open
rekram1-node wants to merge 1 commit into
rekram1-node wants to merge 1 commit into
Conversation
Co-authored-by: pengzh1 <[email protected]> Co-authored-by: Parker Fawcett <[email protected]>
Contributor
There was a problem hiding this comment.
Looks good. I reproduced #54605 on the base with the simulated model: after patching a CRLF file, the whole hunk came back LF while the untouched line kept CRLF. With this change every line keeps \r\n, and the TUI diff shows only the line that actually changed. The patch tests in packages/core pass, and tsc is clean for packages/util and packages/cli.
Public API: UpdateFileChunk in @opencode/util/patch gets an optional contextIndices field. This is backwards compatible: chunks built without it behave as before, apart from the line-ending fix. No SDK, HTTP, plugin or config surface changes.
No blocking concerns.
This branch has not been deployed
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.


Closes #45926
Closes #54605
Problem
The patch tool rewrote every line it touched with
\n, so a CRLF file ended up with mixed endings after any update.Change
Uniform files stay uniform, and mixed files stay mixed outside the edited lines.
To keep context lines verbatim, the parser now records which old/new lines are context (
contextIndiceson each chunk). The ACP preview, which reverses chunks, swaps those indices too.Out of scope
\ris still part of the line text, matching how Read shows the file.*** Add Fileare still written with LF.Builds on #45931 and #56128, both authors are credited as co-authors.
Added by the opencode bot (AI-generated).
Public API: adds optional
contextIndicestoUpdateFileChunkin @opencode/util/patch (backwards compatible)