fix: preserve original line endings when patching files - #1663
Open
officialaritro wants to merge 1 commit into
Open
officialaritro wants to merge 1 commit into
officialaritro wants to merge 1 commit into
Conversation
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.
PR Checklist
PR Type
What is the current behavior?
Issue Number: #1129
ModifyCode'ssave_file_contentsalways 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_filenow detects the file's original newline style (via the existingdetect_newline()utility inpatchwork/common/utils/utils.py) before editing, andsave_file_contentsnow accepts and honors anewlineparameter, writing the patched file back with its original line endings preserved.patchwork/common/tools/code_edit_tools.py), which handle this correctly today —ModifyCodewas the one write path that didn't.ModifyCode/README.mddocuments the new line-ending preservation behavior.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_contentswas the only one missing this handling —code_edit_tools.py's agentic tool-edit path already does this correctly via the samedetect_newline()utility, which this fix now reuses rather than reimplementing.