fix: Diff view now ignores line endings changes/windows autocrlf#4356
Merged
Conversation
revert some stuff revert some stuff
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes diff view behavior to ignore line ending changes caused by Windows' autocrlf setting. The changes ensure consistent diff generation across platforms by normalizing line endings to LF (\n) before comparison and configuring git to disable automatic line ending conversion.
- Adds
normalizeLineEndingsfunction to convert CRLF to LF before diff generation - Configures git with
core.autocrlf=falsein snapshot operations - Adds background colors to diff syntax highlighting themes
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/opencode/src/tool/edit.ts | Introduces normalizeLineEndings helper and applies it to createTwoFilesPatch calls to ensure consistent diffs |
| packages/opencode/src/snapshot/index.ts | Configures git to disable autocrlf both persistently and per-command using -c core.autocrlf=false |
| packages/opencode/src/cli/cmd/tui/context/theme.tsx | Adds background color properties to diff syntax highlighting for better visual distinction |
Comments suppressed due to low confidence (2)
packages/opencode/src/tool/edit.ts:69
- Inconsistent line ending normalization. This call to
createTwoFilesPatchshould also usenormalizeLineEndingson bothcontentOldandcontentNewto ensure consistent diff generation. At this point in the code,contentOldis empty string andcontentNewisparams.newString, but ifparams.newStringcontains CRLF line endings, the diff will show spurious changes. Apply the same normalization pattern used at lines 99 and 121.
diff = trimDiff(createTwoFilesPatch(filePath, filePath, contentOld, contentNew))
packages/opencode/src/tool/edit.ts:148
- The
diffLinesfunction should also receive normalized line endings to ensure accurate addition/deletion counts. IfcontentOldandcontentNewhave different line endings (CRLF vs LF), the diff will incorrectly report line changes. UsenormalizeLineEndings(contentOld)andnormalizeLineEndings(contentNew)as arguments to match the normalization applied in the patch generation.
for (const change of diffLines(contentOld, contentNew)) {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
xywsxp
pushed a commit
to xywsxp/opencode
that referenced
this pull request
Apr 24, 2026
Rwanbt
pushed a commit
to Rwanbt/opencode
that referenced
this pull request
May 5, 2026
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.
Its not highlighting the lines correctly but I will fix that in a separate PR