fix(core/git_worktree): restore cache mirror toggle

This commit is contained in:
James Peter
2025-10-05 12:02:23 +10:00
parent e293560dd6
commit 627b9cc809
2 changed files with 28 additions and 13 deletions
+25 -11
View File
@@ -59,6 +59,17 @@ pub const LOCAL_DEFAULT_REMOTE: &str = "local-default";
const BRANCH_METADATA_DIR: &str = "_branch-meta";
const DEFAULT_BRANCH_CACHE_DIRS: &[&str] = &["node_modules"];
fn branch_copy_cache_dirs_enabled() -> bool {
const TOGGLES: &[&str] = &["CODE_BRANCH_COPY_CACHES", "CODEX_BRANCH_COPY_CACHES"];
for var in TOGGLES {
if let Ok(value) = std::env::var(var) {
let value = value.to_ascii_lowercase();
return matches!(value.as_str(), "1" | "true" | "yes");
}
}
false
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct BranchMetadata {
#[serde(skip_serializing_if = "Option::is_none")]
@@ -498,22 +509,25 @@ async fn copy_branch_cache_dirs(src_root: &Path, worktree_path: &Path) -> Result
}
fn gather_branch_cache_candidates(src_root: &Path) -> Vec<PathBuf> {
let mut out: Vec<PathBuf> = DEFAULT_BRANCH_CACHE_DIRS
.iter()
.map(PathBuf::from)
.collect();
let mut out: Vec<PathBuf> = Vec::new();
append_cargo_targets(src_root, &mut out);
if branch_copy_cache_dirs_enabled() {
out.extend(DEFAULT_BRANCH_CACHE_DIRS.iter().map(PathBuf::from));
append_cargo_targets(src_root, &mut out);
if let Some(raw) = std::env::var_os("CARGO_TARGET_DIR") {
let path = PathBuf::from(raw);
if let Some(rel) = relative_candidate_path(&path, src_root) {
out.push(rel);
}
}
}
if let Some(raw) = std::env::var_os("CODEX_BRANCH_COPY_DIRS") {
if let Some(raw) = std::env::var_os("CODE_BRANCH_COPY_DIRS") {
out.extend(std::env::split_paths(&raw));
}
if let Some(raw) = std::env::var_os("CARGO_TARGET_DIR") {
let path = PathBuf::from(raw);
if let Some(rel) = relative_candidate_path(&path, src_root) {
out.push(rel);
}
if let Some(raw) = std::env::var_os("CODEX_BRANCH_COPY_DIRS") {
out.extend(std::env::split_paths(&raw));
}
out
+3 -2
View File
@@ -30,8 +30,9 @@ Notes
- `/branch [task]`: create a worktree branch and switch to it. If a
task/description is provided, it is used when naming the branch. Must be run
from the repository root (not inside another branch worktree). Set
`CODEX_BRANCH_COPY_CACHES=1` to mirror `node_modules` and Rust build caches
into the worktree; otherwise no cache directories are copied automatically.
`CODE_BRANCH_COPY_CACHES=1` (legacy: `CODEX_BRANCH_COPY_CACHES=1`) to mirror
`node_modules` and Rust build caches into the worktree; otherwise no cache
directories are copied automatically.
- `/merge`: merge the current worktree branch back into the default branch and
remove the worktree. Run this from inside the worktree created by `/branch`.
- `/review [focus]`: without arguments, opens a review picker so you can audit