Skip to content

Commit 26badba

Browse files
refactor(config): change default home directory from ~/forge to ~/.forge (#2902)
Co-authored-by: Tushar Mathur <tusharmath@gmail.com>
1 parent b73fb81 commit 26badba

3 files changed

Lines changed: 21 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ System-level environment variables (usually set automatically):
863863

864864
```bash
865865
# .env
866-
FORGE_CONFIG=/custom/config/dir # Base directory for all Forge config files (default: ~/forge)
866+
FORGE_CONFIG=/custom/config/dir # Base directory for all Forge config files (default: ~/.forge)
867867
FORGE_MAX_SEARCH_RESULT_BYTES=10240 # Maximum bytes for search results (default: 10240 - 10 KB)
868868
FORGE_HISTORY_FILE=/path/to/history # Custom path for Forge history file (default: uses system default location)
869869
FORGE_BANNER="Your custom banner text" # Custom banner text to display on startup (default: Forge ASCII art)

crates/forge_config/src/reader.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,26 @@ impl ConfigReader {
5252
/// Returns the base directory for all Forge config files.
5353
///
5454
/// If the `FORGE_CONFIG` environment variable is set, its value is used
55-
/// directly as the base path. Otherwise defaults to `~/forge`.
55+
/// directly as the base path. Otherwise defaults to `~/.forge`.
56+
/// Falls back to the legacy `~/forge` path if it exists and `~/.forge`
57+
/// does not.
5658
pub fn base_path() -> PathBuf {
5759
if let Ok(path) = std::env::var("FORGE_CONFIG") {
5860
return PathBuf::from(path);
5961
}
60-
dirs::home_dir().unwrap_or(PathBuf::from(".")).join("forge")
62+
63+
let home = dirs::home_dir().unwrap_or(PathBuf::from("."));
64+
let path = home.join(".forge");
65+
let legacy_path = home.join("forge");
66+
67+
// Prefer the new dotfile path, but fall back to legacy if only it exists
68+
if !path.exists() && legacy_path.exists() {
69+
tracing::info!("Using legacy path");
70+
return legacy_path;
71+
}
72+
73+
tracing::info!("Using new path");
74+
path
6175
}
6276

6377
/// Adds the provided TOML string as a config source without touching the
@@ -181,8 +195,8 @@ mod tests {
181195
#[test]
182196
fn test_base_path_falls_back_to_home_dir_when_env_var_absent() {
183197
let actual = ConfigReader::base_path();
184-
// Without FORGE_CONFIG set the path must end with "forge"
185-
assert_eq!(actual.file_name().unwrap(), "forge");
198+
// Without FORGE_CONFIG set the path must end with ".forge"
199+
assert_eq!(actual.file_name().unwrap(), ".forge");
186200
}
187201

188202
#[test]

crates/forge_infra/src/env.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ mod tests {
213213
#[test]
214214
fn test_to_environment_falls_back_to_home_dir_when_env_var_absent() {
215215
let actual = to_environment(PathBuf::from("/any/cwd"));
216-
// Without FORGE_CONFIG the base_path must end with "forge"
217-
assert_eq!(actual.base_path.file_name().unwrap(), "forge");
216+
// Without FORGE_CONFIG the base_path must end with ".forge"
217+
assert_eq!(actual.base_path.file_name().unwrap(), ".forge");
218218
}
219219

220220
#[test]

0 commit comments

Comments
 (0)