mirror of
https://github.com/openai/codex.git
synced 2026-10-19 17:28:46 +00:00
Render turn diffs for foreign environment paths (#34654)
## Why Turn diffs need to render paths from remote environments whose path convention may differ from the Codex host. ## What changed - Preserve `PathUri` values through applied patch deltas, display-root discovery, and turn-diff tracking. - Add host-independent relative-path rendering and normalize Windows drive-letter case in `PathUri`. - Render paths relative to each environment's repository root while keeping Git diff headers slash-separated. ## Testing - Cover POSIX, Windows, UNC, encoded-separator, and opaque URI relative paths. - Verify an applied patch in a remote Windows working directory emits a portable unified diff. GitOrigin-RevId: 526f70ae36a40627de5496d375310d12295b69bb
This commit is contained in:
committed by
copyberry
parent
9fce9e13fd
commit
1823c13771
@@ -42,30 +42,6 @@ pub fn get_git_repo_root(base_dir: &Path) -> Option<PathBuf> {
|
||||
find_ancestor_git_entry(base).map(|(repo_root, _)| repo_root)
|
||||
}
|
||||
|
||||
/// Return the repository root for `cwd` using the provided filesystem.
|
||||
///
|
||||
/// This mirrors [`get_git_repo_root`] for local paths, but works when `cwd`
|
||||
/// only exists inside a selected remote environment.
|
||||
pub async fn get_git_repo_root_with_fs(
|
||||
fs: &dyn ExecutorFileSystem,
|
||||
cwd: &AbsolutePathBuf,
|
||||
) -> Option<AbsolutePathBuf> {
|
||||
let cwd_uri = PathUri::from_abs_path(cwd);
|
||||
let base = match fs.get_metadata(&cwd_uri, /*sandbox*/ None).await {
|
||||
Ok(metadata) if metadata.is_directory => cwd.clone(),
|
||||
_ => cwd.parent()?,
|
||||
};
|
||||
find_nearest_native_ancestor_with_markers(
|
||||
fs,
|
||||
&base,
|
||||
vec![".git".to_string()],
|
||||
FindUpErrorPolicy::Ignore,
|
||||
/*sandbox*/ None,
|
||||
)
|
||||
.await
|
||||
.ok()?
|
||||
}
|
||||
|
||||
/// Timeout for git commands to prevent freezing on large repositories
|
||||
const GIT_COMMAND_TIMEOUT: TokioDuration = TokioDuration::from_secs(5);
|
||||
const DISABLED_HOOKS_PATH: &str = if cfg!(windows) { "NUL" } else { "/dev/null" };
|
||||
@@ -817,7 +793,20 @@ pub async fn resolve_root_git_project_for_trust(
|
||||
fs: &dyn ExecutorFileSystem,
|
||||
cwd: &AbsolutePathBuf,
|
||||
) -> Option<AbsolutePathBuf> {
|
||||
let repo_root = get_git_repo_root_with_fs(fs, cwd).await?;
|
||||
let cwd_uri = PathUri::from_abs_path(cwd);
|
||||
let base = match fs.get_metadata(&cwd_uri, /*sandbox*/ None).await {
|
||||
Ok(metadata) if metadata.is_directory => cwd.clone(),
|
||||
_ => cwd.parent()?,
|
||||
};
|
||||
let repo_root = find_nearest_native_ancestor_with_markers(
|
||||
fs,
|
||||
&base,
|
||||
vec![".git".to_string()],
|
||||
FindUpErrorPolicy::Ignore,
|
||||
/*sandbox*/ None,
|
||||
)
|
||||
.await
|
||||
.ok()??;
|
||||
let dot_git = repo_root.join(".git");
|
||||
let dot_git_uri = PathUri::from_abs_path(&dot_git);
|
||||
if fs
|
||||
|
||||
@@ -35,7 +35,6 @@ pub use info::default_branch_name;
|
||||
pub use info::get_git_remote_urls;
|
||||
pub use info::get_git_remote_urls_assume_git_repo;
|
||||
pub use info::get_git_repo_root;
|
||||
pub use info::get_git_repo_root_with_fs;
|
||||
pub use info::get_has_changes;
|
||||
pub use info::get_head_commit_hash;
|
||||
pub use info::git_diff_to_remote;
|
||||
|
||||
Reference in New Issue
Block a user