Skip to content

fix(core): normalize CRLF before computing diff context snippets - #29559

Open
The-AarushiSingh wants to merge 1 commit into
google-gemini:mainfrom
The-AarushiSingh:fix/crlf-diff-context-snippet
Open

The-AarushiSingh wants to merge 1 commit into
google-gemini:mainfrom
The-AarushiSingh:fix/crlf-diff-context-snippet

Conversation

@The-AarushiSingh

Copy link
Copy Markdown

Fixes #29130

Diff.diffLines compared raw CRLF file content against LF edited content, so every line looked changed and getDiffContextSnippet returned the whole file.

Normalize newlines before diffing. Existing LF tests are unchanged. Added CRLF cases in diff-utils.test.ts.

@The-AarushiSingh
The-AarushiSingh requested a review from a team as a code owner September 29, 2026 19:17
@github-actions github-actions Bot added the size/s A small PR label Sep 29, 2026
@github-actions

Copy link
Copy Markdown

📊 PR Size: size/S

  • Lines changed: 31
  • Additions: +29
  • Deletions: -2
  • Files changed: 2

@github-actions

Copy link
Copy Markdown

🛑 Action Required: Evaluation Approval

Steering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged.

Maintainers:

  1. Go to the Workflow Run Summary.
  2. Click the yellow 'Review deployments' button.
  3. Select the 'eval-gate' environment and click 'Approve'.

Once approved, the evaluation results will be posted here automatically.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where files with CRLF line endings were incorrectly identified as having full-file changes when compared against LF content. By normalizing line endings before computing diff context snippets, the tool now accurately detects and reports only the actual code changes, improving the reliability of diff generation.

Highlights

  • Newline Normalization: Introduced a normalizeNewlines utility function to convert both CRLF and CR line endings to LF before processing diffs.
  • Diff Logic Update: Updated getDiffContextSnippet to use normalized content for diff comparison, preventing full-file diffs when only line endings differ.
  • Regression Testing: Added new test cases in diff-utils.test.ts to verify correct snippet generation for mixed CRLF/LF scenarios and consistent CRLF handling.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces newline normalization to the diff utility function getDiffContextSnippet in packages/core/src/tools/diff-utils.ts. It adds a helper function normalizeNewlines to convert CRLF (\r\n) and CR (\r) line endings to LF (\n) before performing diff calculations and line splitting. This prevents CRLF vs LF differences from being treated as full-file changes. Additionally, corresponding unit tests have been added in diff-utils.test.ts to verify this behavior. There are no review comments, and I have no feedback to provide.

@TrueAlpha-spiral

TrueAlpha-spiral commented Sep 29, 2026 via email

Copy link
Copy Markdown

@gemini-cli gemini-cli Bot added the area/core Issues related to User Interface, OS Support, Core Functionality label Sep 29, 2026
@gemini-cli

gemini-cli Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Hi there! Thank you for your interest in contributing to Gemini CLI.

To ensure we maintain high code quality and focus on our prioritized roadmap, we only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'.

This PR will be closed in 7 days if it remains without that designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding.

This branch is waiting to be deployed

1 waiting deployment
eval-gate — 34977fc5 Waiting Sep 29, 2026 by The-AarushiSingh via Evaluate Steering & Regressions #2112
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality size/s A small PR status/pr-nudge-sent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(core): getDiffContextSnippet produces full-file diff on CRLF line endings due to unnormalized line breaks

2 participants