[codex] Ignore fsmonitor config in Git metadata reads (#22652)

## Summary
- keep Git metadata/status subprocesses independent of repository
`core.fsmonitor` configuration
- preserve existing working-tree state reporting while making the helper
behavior more predictable
- add regression coverage for `get_has_changes` when a repository
defines an fsmonitor command

## Validation
- `cargo fmt --all`
- `cargo test -p codex-core test_get_has_changes_`
- `cargo test -p codex-git-utils`
This commit is contained in:
Chris Bookholt
2026-05-14 10:07:43 -07:00
committed by GitHub
parent 8736e32657
commit 6ec8c4a6ec
2 changed files with 43 additions and 0 deletions

View File

@@ -11,6 +11,8 @@ use core_test_support::PathBufExt;
use core_test_support::PathExt;
use core_test_support::skip_if_sandbox;
use std::fs;
#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;
use std::path::PathBuf;
use tempfile::TempDir;
use tokio::process::Command;
@@ -337,6 +339,46 @@ async fn test_get_has_changes_with_untracked_change_returns_true() {
assert_eq!(get_has_changes(&repo_path).await, Some(true));
}
#[cfg(unix)]
#[tokio::test]
async fn test_get_has_changes_ignores_repo_fsmonitor_config() {
let temp_dir = TempDir::new().expect("Failed to create temp dir");
let repo_path = create_test_git_repo(&temp_dir).await;
let helper_path = repo_path.join("fsmonitor-helper.sh");
let marker_path = repo_path.join("fsmonitor-ran");
fs::write(
&helper_path,
format!(
"#!/bin/sh\nprintf ran > \"{}\"\n",
marker_path.to_string_lossy()
),
)
.expect("write fsmonitor helper");
let mut permissions = fs::metadata(&helper_path)
.expect("read fsmonitor helper metadata")
.permissions();
permissions.set_mode(0o755);
fs::set_permissions(&helper_path, permissions).expect("mark fsmonitor helper executable");
Command::new("git")
.args([
"config",
"core.fsmonitor",
helper_path.to_string_lossy().as_ref(),
])
.current_dir(&repo_path)
.output()
.await
.expect("configure fsmonitor helper");
assert_eq!(get_has_changes(&repo_path).await, Some(true));
assert!(
!marker_path.exists(),
"metadata collection should not invoke repository fsmonitor helpers"
);
}
#[tokio::test]
async fn test_get_git_working_tree_state_clean_repo() {
let temp_dir = TempDir::new().expect("Failed to create temp dir");

View File

@@ -375,6 +375,7 @@ async fn run_git_command_with_timeout(args: &[&str], cwd: &Path) -> Option<std::
let mut command = Command::new("git");
command
.env("GIT_OPTIONAL_LOCKS", "0")
.args(["-c", "core.fsmonitor=false"])
.args(args)
.current_dir(cwd)
.kill_on_drop(true);