From 4b6c6ce98f71a65ec43a20f77fbbbf05389a4655 Mon Sep 17 00:00:00 2001 From: Gabriel Peal Date: Tue, 26 Aug 2025 22:53:00 -0700 Subject: [PATCH] Make git_diff_against_sha more robust (#2749) 1. Ignore custom git diff drivers users may have set 2. Allow diffing against filenames that start with a dash --- codex-rs/core/src/git_info.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/codex-rs/core/src/git_info.rs b/codex-rs/core/src/git_info.rs index 91634ab9..0290323c 100644 --- a/codex-rs/core/src/git_info.rs +++ b/codex-rs/core/src/git_info.rs @@ -385,7 +385,9 @@ async fn find_closest_sha(cwd: &Path, branches: &[String], remotes: &[String]) - } async fn diff_against_sha(cwd: &Path, sha: &GitSha) -> Option { - let output = run_git_command_with_timeout(&["diff", &sha.0], cwd).await?; + let output = + run_git_command_with_timeout(&["diff", "--no-textconv", "--no-ext-diff", &sha.0], cwd) + .await?; // 0 is success and no diff. // 1 is success but there is a diff. let exit_ok = output.status.code().is_some_and(|c| c == 0 || c == 1); @@ -406,10 +408,21 @@ async fn diff_against_sha(cwd: &Path, sha: &GitSha) -> Option { .collect(); if !untracked.is_empty() { + // Use platform-appropriate null device and guard paths with `--`. + let null_device: &str = if cfg!(windows) { "NUL" } else { "/dev/null" }; let futures_iter = untracked.into_iter().map(|file| async move { let file_owned = file; - let args_vec: Vec<&str> = - vec!["diff", "--binary", "--no-index", "/dev/null", &file_owned]; + let args_vec: Vec<&str> = vec![ + "diff", + "--no-textconv", + "--no-ext-diff", + "--binary", + "--no-index", + // -- ensures that filenames that start with - are not treated as options. + "--", + null_device, + &file_owned, + ]; run_git_command_with_timeout(&args_vec, cwd).await }); let results = join_all(futures_iter).await;