From 3cb702f05ea4ff98e8deb6a229d3e33de0a48856 Mon Sep 17 00:00:00 2001 From: majiayu000 <1835304752@qq.com> Date: Sat, 28 Mar 2026 20:11:20 +0800 Subject: [PATCH 1/2] feat: support FORGE_FOLDER_PATH env var to override base path Check FORGE_FOLDER_PATH env var in ConfigReader::base_path() before falling back to ~/forge. Deduplicate the base_path logic in env.rs by reusing ConfigReader::base_path(). Closes #2662 Signed-off-by: majiayu000 <1835304752@qq.com> --- crates/forge_config/src/reader.rs | 20 +++++++++++++++++++- crates/forge_infra/src/env.rs | 4 +--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/crates/forge_config/src/reader.rs b/crates/forge_config/src/reader.rs index 2f2ed94821..d0a6c45b08 100644 --- a/crates/forge_config/src/reader.rs +++ b/crates/forge_config/src/reader.rs @@ -49,8 +49,12 @@ impl ConfigReader { Self::base_path().join(".forge.toml") } - /// Returns the base directory for all Forge config files (`~/forge`). + /// Returns the base directory for all Forge config files. + /// Checks `FORGE_FOLDER_PATH` env var first, falls back to `~/forge`. pub fn base_path() -> PathBuf { + if let Ok(path) = std::env::var("FORGE_FOLDER_PATH") { + return PathBuf::from(path); + } dirs::home_dir().unwrap_or(PathBuf::from(".")).join("forge") } @@ -164,6 +168,20 @@ mod tests { } } + #[test] + fn test_base_path_respects_env_var() { + let _guard = EnvGuard::set(&[("FORGE_FOLDER_PATH", "/custom/forge/path")]); + assert_eq!(ConfigReader::base_path(), PathBuf::from("/custom/forge/path")); + } + + #[test] + fn test_base_path_defaults_to_home_forge() { + let _guard = EnvGuard::set(&[]); + let path = ConfigReader::base_path(); + let expected = dirs::home_dir().unwrap_or(PathBuf::from(".")).join("forge"); + assert_eq!(path, expected); + } + #[test] fn test_read_parses_without_error() { let actual = ConfigReader::default().read_defaults().build(); diff --git a/crates/forge_infra/src/env.rs b/crates/forge_infra/src/env.rs index 04b17274ba..873e6efed3 100644 --- a/crates/forge_infra/src/env.rs +++ b/crates/forge_infra/src/env.rs @@ -129,9 +129,7 @@ fn to_environment(fc: ForgeConfig, cwd: PathBuf) -> Environment { } else { std::env::var("SHELL").unwrap_or_else(|_| "/bin/sh".to_string()) }, - base_path: dirs::home_dir() - .map(|h| h.join("forge")) - .unwrap_or_else(|| PathBuf::from(".").join("forge")), + base_path: ConfigReader::base_path(), // --- ForgeConfig-mapped fields --- retry_config: fc.retry.map(to_retry_config).unwrap_or_default(), From a4523be6943d3c05f6e9a56fd3458f8b4fdc6e6e Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sat, 28 Mar 2026 12:18:14 +0000 Subject: [PATCH 2/2] [autofix.ci] apply automated fixes --- crates/forge_config/src/reader.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/forge_config/src/reader.rs b/crates/forge_config/src/reader.rs index d0a6c45b08..eccfece730 100644 --- a/crates/forge_config/src/reader.rs +++ b/crates/forge_config/src/reader.rs @@ -171,7 +171,10 @@ mod tests { #[test] fn test_base_path_respects_env_var() { let _guard = EnvGuard::set(&[("FORGE_FOLDER_PATH", "/custom/forge/path")]); - assert_eq!(ConfigReader::base_path(), PathBuf::from("/custom/forge/path")); + assert_eq!( + ConfigReader::base_path(), + PathBuf::from("/custom/forge/path") + ); } #[test]