Make apply_patch preserve line endings unconditionally (#51203)

## Why

Updating a CRLF file with `apply_patch` previously normalized its line endings to LF unless preservation was explicitly enabled. Preserve the file's existing line endings without requiring an opt-in.

## What changed

- Use line-ending-preserving updates for both tool calls and standalone `apply_patch` invocations, removing the legacy normalization mode.
- Mark `apply_patch_preserve_line_endings` as removed.
- Always set `CODEX_APPLY_PATCH_PRESERVE_LINE_ENDINGS=1` in child environments for compatibility with older patch executables, overriding stale values.

## Testing

Update CLI, tool-call, shell-heredoc, and app-server tests to check CRLF preservation by default. Keep coverage for overriding stale compatibility environment values.

GitOrigin-RevId: 96d0b0e5350faa3fc7a45d63627a132657b44523
This commit is contained in:
Charlie Marsh
2026-10-05 23:52:06 +00:00
committed by copyberry
parent 93f8e79fd2
commit 685270a56a
21 changed files with 80 additions and 513 deletions
@@ -67,13 +67,8 @@ pub fn run_main() -> i32 {
};
// TODO(anp): Discover the standalone executable cwd as PathUri directly.
let cwd = codex_utils_path_uri::PathUri::from_abs_path(&cwd);
let update_file_mode = crate::apply_patch_file_update_mode_from_env();
match runtime.block_on(crate::apply_patch_with_options(
match runtime.block_on(crate::apply_patch(
&patch_arg,
crate::ApplyPatchOptions {
update_file_mode,
..Default::default()
},
&cwd,
&mut stdout,
&mut stderr,