Skip to content

Conversation

@dylan-hurd-oai
Copy link
Collaborator

@dylan-hurd-oai dylan-hurd-oai commented Dec 3, 2025

Summary

This PR is heavily based on #4017, which contains the core logic for the fix. To reduce the risk, we are first introducing it only on windows. We can then expand to wsl / other environments as needed, and then tackle net new files.

Testing

  • added unit tests in apply-patch
  • add integration tests to apply_patch_cli.rs

cnaples79 and others added 5 commits September 21, 2025 17:47
… files (Fixes #4003)

- Detect CRLF in original file, strip trailing \r for matching, and re-emit using original EOL style
- Add test to ensure updated files retain CRLF endings and avoid mixed EOLs
…d unintended newline conversion\n\n- Count total vs CRLF pairs and treat as CRLF only if every newline is CRLF\n- Prevents converting LF-formatted files that contain embedded in literals
@dylan-hurd-oai dylan-hurd-oai marked this pull request as ready for review December 3, 2025 03:39
@dylan-hurd-oai dylan-hurd-oai marked this pull request as draft December 3, 2025 06:28
@dylan-hurd-oai dylan-hurd-oai removed the request for review from bolinfest December 3, 2025 06:29
@dylan-hurd-oai dylan-hurd-oai marked this pull request as ready for review December 3, 2025 07:29
@dylan-hurd-oai dylan-hurd-oai changed the title [wip] fix(apply-patch): preserve CRLF line endings on Windows fix(apply-patch): preserve CRLF line endings on Windows Dec 4, 2025
}

/// Detects whether the source file uses Windows CRLF line endings consistently.
/// We only consider a file CRLF-formatted if every newline is part of a
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems strict, though admittedly, I'm not sure if there's a better way...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we could potentially relax this constraint, but for now I'd prefer to keep this strict.


// TODO(dylan-hurd-oai): I think we can migrate to just use `contents.lines()`
// across all platforms.
fn build_lines_from_contents(contents: &str) -> Vec<String> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's not a huge deal, but it would be nice to do the work in contents_uses_crlf() as part of this so that we do the splitting and \r\n check in one forward pass of the file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Single forward pass would be ideal, agreed

@dylan-hurd-oai dylan-hurd-oai merged commit 6c9c563 into main Dec 6, 2025
26 checks passed
@dylan-hurd-oai dylan-hurd-oai deleted the dh--apply-patch-crlf branch December 6, 2025 00:43
@github-actions github-actions bot locked and limited conversation to collaborators Dec 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants