Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion crates/forge_config/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -164,6 +168,23 @@ 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();
Expand Down
4 changes: 1 addition & 3 deletions crates/forge_infra/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Loading