GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: preserve original line endings when patching files by officialaritro · Pull Request #1663 · patched-codes/patchwork

Conversation

@officialaritro

@officialaritro officialaritro commented Sep 21, 2026

Copy link
Copy Markdown

PR Checklist

  • The commit message follows our guidelines: Code of conduct
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Does this PR introduce a breaking change?
  • Include PR in release notes?

PR Type

  • Bugfix

What is the current behavior?

Issue Number: #1129

ModifyCode's save_file_contents always writes with Python's default newline translation, discarding a file's original line-ending style. When a patchflow modifies one line in a file that uses CRLF (\r\n) endings, the whole file gets rewritten with LF (\n) endings, so the generated diff shows every line in the file as changed instead of just the actual edit — exactly as described in the issue.

What is the new behavior?

  • replace_code_in_file now detects the file's original newline style (via the existing detect_newline() utility in patchwork/common/utils/utils.py) before editing, and save_file_contents now accepts and honors a newline parameter, writing the patched file back with its original line endings preserved.
  • This mirrors the pattern already used by the agentic code-edit tools (patchwork/common/tools/code_edit_tools.py), which handle this correctly today — ModifyCode was the one write path that didn't.
  • ModifyCode/README.md documents the new line-ending preservation behavior.
  • Added a regression test in tests/steps/test_ModifyCode.py, verified to fail without the fix (CRLF flattened to LF) and pass with it.

Other information

Traced every file-write path in the codebase to confirm ModifyCode.save_file_contents was the only one missing this handling — code_edit_tools.py's agentic tool-edit path already does this correctly via the same detect_newline() utility, which this fix now reuses rather than reimplementing.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@officialaritro
fix: preserve original line endings when patching files
2ef5a9b
@officialaritro officialaritro mentioned this pull request Sep 21, 2026
Patchwork always read and write files with \n line ending. #1129
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@officialaritro
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.