mirror of
https://github.com/openai/codex.git
synced 2026-02-01 22:47:52 +00:00
Prefer current cwd if remote downloaded
This commit is contained in:
@@ -1300,6 +1300,7 @@ impl App {
|
||||
&path,
|
||||
CwdPromptAction::Resume,
|
||||
true,
|
||||
false,
|
||||
)
|
||||
.await?
|
||||
{
|
||||
|
||||
@@ -497,6 +497,7 @@ async fn run_ratatui_app(
|
||||
};
|
||||
|
||||
let use_fork = cli.fork_picker || cli.fork_last || cli.fork_session_id.is_some();
|
||||
let mut remote_fork_downloaded = false;
|
||||
let session_selection = if use_fork {
|
||||
if let Some(id_str) = cli.fork_session_id.as_deref() {
|
||||
match find_thread_path_by_id_str(&config.codex_home, id_str).await? {
|
||||
@@ -511,7 +512,10 @@ async fn run_ratatui_app(
|
||||
match download_rollout_if_available(storage_url, session_id, &config.codex_home)
|
||||
.await
|
||||
{
|
||||
Ok(Some(path)) => resume_picker::SessionSelection::Fork(path),
|
||||
Ok(Some(path)) => {
|
||||
remote_fork_downloaded = true;
|
||||
resume_picker::SessionSelection::Fork(path)
|
||||
}
|
||||
Ok(None) => return missing_session_exit(id_str, "fork"),
|
||||
Err(err) => {
|
||||
return fatal_exit(format!(
|
||||
@@ -626,8 +630,16 @@ async fn run_ratatui_app(
|
||||
};
|
||||
let fallback_cwd = match action_and_path_if_resume_or_fork {
|
||||
Some((action, path)) => {
|
||||
resolve_cwd_for_resume_or_fork(&mut tui, ¤t_cwd, path, action, allow_prompt)
|
||||
.await?
|
||||
let prefer_current_cwd = remote_fork_downloaded && action == CwdPromptAction::Fork;
|
||||
resolve_cwd_for_resume_or_fork(
|
||||
&mut tui,
|
||||
¤t_cwd,
|
||||
path,
|
||||
action,
|
||||
allow_prompt,
|
||||
prefer_current_cwd,
|
||||
)
|
||||
.await?
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
@@ -735,7 +747,11 @@ pub(crate) async fn resolve_cwd_for_resume_or_fork(
|
||||
path: &Path,
|
||||
action: CwdPromptAction,
|
||||
allow_prompt: bool,
|
||||
prefer_current_cwd: bool,
|
||||
) -> color_eyre::Result<Option<PathBuf>> {
|
||||
if prefer_current_cwd {
|
||||
return Ok(Some(current_cwd.to_path_buf()));
|
||||
}
|
||||
let Some(history_cwd) = read_session_cwd(path).await else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::env;
|
||||
use std::ffi;
|
||||
use std::ffi::OsString;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
@@ -42,27 +44,13 @@ pub fn cargo_bin(name: &str) -> Result<PathBuf, CargoBinError> {
|
||||
return resolve_bin_from_env(key, value);
|
||||
}
|
||||
}
|
||||
match assert_cmd::Command::cargo_bin(name) {
|
||||
Ok(cmd) => {
|
||||
let mut path = PathBuf::from(cmd.get_program());
|
||||
if !path.is_absolute() {
|
||||
path = std::env::current_dir()
|
||||
.map_err(|source| CargoBinError::CurrentDir { source })?
|
||||
.join(path);
|
||||
}
|
||||
if path.exists() {
|
||||
Ok(path)
|
||||
} else {
|
||||
Err(CargoBinError::ResolvedPathDoesNotExist {
|
||||
key: "assert_cmd::Command::cargo_bin".to_owned(),
|
||||
path,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
match resolve_bin_from_target_dir(name) {
|
||||
Ok(path) => Ok(path),
|
||||
Err(err) => Err(CargoBinError::NotFound {
|
||||
name: name.to_owned(),
|
||||
env_keys,
|
||||
fallback: format!("assert_cmd fallback failed: {err}"),
|
||||
fallback: format!("target dir fallback failed: {err}"),
|
||||
}),
|
||||
}
|
||||
}
|
||||
@@ -105,6 +93,35 @@ fn resolve_bin_from_env(key: &str, value: OsString) -> Result<PathBuf, CargoBinE
|
||||
})
|
||||
}
|
||||
|
||||
fn resolve_bin_from_target_dir(name: &str) -> Result<PathBuf, CargoBinError> {
|
||||
let target_dir = cargo_target_dir()?;
|
||||
let filename = format!("{name}{}", env::consts::EXE_SUFFIX);
|
||||
let candidate = target_dir.join(filename);
|
||||
let abs = absolutize_from_buck_or_cwd(candidate.clone())?;
|
||||
if abs.exists() {
|
||||
Ok(abs)
|
||||
} else {
|
||||
Err(CargoBinError::ResolvedPathDoesNotExist {
|
||||
key: "target_dir".to_owned(),
|
||||
path: candidate,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn cargo_target_dir() -> Result<PathBuf, CargoBinError> {
|
||||
let current_exe = env::current_exe().map_err(|source| CargoBinError::CurrentExe { source })?;
|
||||
let mut path = current_exe.parent().map(PathBuf::from).ok_or_else(|| {
|
||||
CargoBinError::ResolvedPathDoesNotExist {
|
||||
key: "current_exe".to_owned(),
|
||||
path: current_exe.clone(),
|
||||
}
|
||||
})?;
|
||||
if path.ends_with(ffi::OsStr::new("deps")) {
|
||||
path.pop();
|
||||
}
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
/// Macro that derives the path to a test resource at runtime, the value of
|
||||
/// which depends on whether Cargo or Bazel is being used to build and run a
|
||||
/// test. Note the return value may be a relative or absolute path.
|
||||
|
||||
Reference in New Issue
Block a user