Skip to content

fix: Diff view now ignores line endings changes/windows autocrlf#4356

Merged
rekram1-node merged 1 commit into
anomalyco:devfrom
Hona:fix/diff-on-windows
Nov 16, 2025
Merged

fix: Diff view now ignores line endings changes/windows autocrlf#4356
rekram1-node merged 1 commit into
anomalyco:devfrom
Hona:fix/diff-on-windows

Conversation

@Hona
Copy link
Copy Markdown
Member

@Hona Hona commented Nov 15, 2025

Its not highlighting the lines correctly but I will fix that in a separate PR

image

revert some stuff

revert some stuff
Copilot AI review requested due to automatic review settings November 15, 2025 23:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 normalizeLineEndings function to convert CRLF to LF before diff generation
  • Configures git with core.autocrlf=false in 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 createTwoFilesPatch should also use normalizeLineEndings on both contentOld and contentNew to ensure consistent diff generation. At this point in the code, contentOld is empty string and contentNew is params.newString, but if params.newString contains 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 diffLines function should also receive normalized line endings to ensure accurate addition/deletion counts. If contentOld and contentNew have different line endings (CRLF vs LF), the diff will incorrectly report line changes. Use normalizeLineEndings(contentOld) and normalizeLineEndings(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.

@rekram1-node rekram1-node merged commit 35fbb01 into anomalyco:dev Nov 16, 2025
9 checks passed
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
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.

3 participants