mirror of
https://github.com/openai/codex.git
synced 2026-10-29 19:08:43 +00:00
fixes
This commit is contained in:
@@ -44,6 +44,9 @@ use crate::invocation::ExtractHeredocError;
|
||||
/// surface.
|
||||
pub const CODEX_CORE_APPLY_PATCH_ARG1: &str = "--codex-run-as-apply-patch";
|
||||
|
||||
/// Enables CRLF preservation for the standalone `apply_patch` command.
|
||||
pub const APPLY_PATCH_PRESERVE_CRLF_ARG: &str = "--preserve-crlf";
|
||||
|
||||
/// Controls optional behavior when parsing or applying a patch.
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||
pub struct ApplyPatchOptions {
|
||||
|
||||
@@ -442,8 +442,8 @@ fn parse_update_file_chunk(
|
||||
match line_contents.chars().next() {
|
||||
None => {
|
||||
// Interpret this as an empty line.
|
||||
chunk.old_lines.push(String::new());
|
||||
chunk.new_lines.push(String::new());
|
||||
chunk.old_lines.push(line.to_string());
|
||||
chunk.new_lines.push(line.to_string());
|
||||
}
|
||||
Some(' ') => {
|
||||
chunk.old_lines.push(line[1..].to_string());
|
||||
@@ -587,6 +587,34 @@ fn test_update_file_chunk() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_update_file_chunk_preserves_crlf_for_bare_empty_context_line() {
|
||||
assert_eq!(
|
||||
parse_update_file_chunk(
|
||||
&["@@\r", " before\r", "\r", " after\r", "*** End Patch\r"],
|
||||
/*line_number*/ 123,
|
||||
/*allow_missing_context*/ false,
|
||||
),
|
||||
Ok((
|
||||
UpdateFileChunk {
|
||||
change_context: None,
|
||||
old_lines: vec![
|
||||
"before\r".to_string(),
|
||||
"\r".to_string(),
|
||||
"after\r".to_string(),
|
||||
],
|
||||
new_lines: vec![
|
||||
"before\r".to_string(),
|
||||
"\r".to_string(),
|
||||
"after\r".to_string(),
|
||||
],
|
||||
is_end_of_file: false,
|
||||
},
|
||||
4,
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_patch() {
|
||||
assert_eq!(
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
|
||||
const PRESERVE_CRLF_FLAG: &str = "--preserve-crlf";
|
||||
|
||||
pub fn main() -> ! {
|
||||
let exit_code = run_main();
|
||||
std::process::exit(exit_code);
|
||||
@@ -17,7 +15,7 @@ pub fn run_main() -> i32 {
|
||||
let _argv0 = args.next();
|
||||
let first_arg = args.next();
|
||||
let (options, patch_arg) = match first_arg {
|
||||
Some(arg) if arg.to_str() == Some(PRESERVE_CRLF_FLAG) => {
|
||||
Some(arg) if arg == crate::APPLY_PATCH_PRESERVE_CRLF_ARG => {
|
||||
(crate::ApplyPatchOptions::preserve_crlf(), args.next())
|
||||
}
|
||||
patch_arg => (crate::ApplyPatchOptions::default(), patch_arg),
|
||||
|
||||
Reference in New Issue
Block a user