Skip to main content

write_env_worktree

Function write_env_worktree 

Source
pub fn write_env_worktree(
    worktree_path: &Path,
    repo_name: &str,
    worktree_name: &str,
    slot_id: u32,
    effective_ports: &BTreeMap<String, u16>,
    environment: Option<&EnvironmentConfig>,
) -> Result<()>
Expand description

Generates .env.worktree inside the worktree directory.

Injects slot ID, worktree name and path, Docker Compose project name, calculated dynamic ports, optional Python runtime environment (PYENV_VERSION), and virtualenv variables (VIRTUAL_ENV, PATH) when .venv is present.

ยงExamples

use git_claw::infra::env_file::write_env_worktree;
use git_claw::core::config::EnvironmentConfig;
use std::collections::BTreeMap;
use tempfile::tempdir;
use std::fs;

let dir = tempdir().unwrap();
let wt = dir.path().join("wt-1");
fs::create_dir_all(&wt).unwrap();

let env = EnvironmentConfig {
    name: Some("3.12.0".to_string()),
    ..Default::default()
};
write_env_worktree(&wt, "repo", "wt-1", 1, &BTreeMap::new(), Some(&env)).unwrap();
let content = fs::read_to_string(wt.join(".env.worktree")).unwrap();
assert!(content.contains("PYENV_VERSION=3.12.0"));