Skip to content

Commit 7b6120d

Browse files
authored
fix: improve config path selection logic (#2926)
1 parent 8241bb8 commit 7b6120d

1 file changed

Lines changed: 14 additions & 19 deletions

File tree

crates/forge_config/src/reader.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,34 +51,29 @@ impl ConfigReader {
5151

5252
/// Returns the base directory for all Forge config files.
5353
///
54-
/// If the `FORGE_CONFIG` environment variable is set, its value is used
55-
/// directly as the base path. Otherwise defaults to `~/.forge`.
56-
/// Falls back to the legacy `~/forge` path if it exists, even if `~/.forge`
57-
/// also exists. This prevents tools that eagerly create `~/.forge` (such as
58-
/// the shell plugin's config-edit action) from silently switching the
59-
/// active base path while the user's credentials and config still live
60-
/// in `~/forge`. Once the user runs `forge config migrate` the
61-
/// `~/forge` directory is removed, so this fallback naturally stops
62-
/// applying.
54+
/// Resolution order:
55+
/// 1. `FORGE_CONFIG` environment variable, if set.
56+
/// 2. `~/.forge`, if that directory exists.
57+
/// 3. `~/forge` (legacy path) as a fallback, so users who have not yet run
58+
/// `forge config migrate` continue to read from their existing directory
59+
/// without disruption.
6360
pub fn base_path() -> PathBuf {
6461
if let Ok(path) = std::env::var("FORGE_CONFIG") {
6562
return PathBuf::from(path);
6663
}
6764

6865
let home = dirs::home_dir().unwrap_or(PathBuf::from("."));
6966
let path = home.join(".forge");
70-
let legacy_path = home.join("forge");
71-
72-
// Prefer the legacy ~/forge path while it still exists so that an
73-
// empty ~/.forge directory (e.g. created by `mkdir -p` in the shell
74-
// plugin) does not cause the base path to flip before migration.
75-
if legacy_path.exists() {
76-
tracing::info!("Using legacy path");
77-
return legacy_path;
67+
68+
// Prefer ~/.forge when it exists; fall back to ~/forge for users who
69+
// have not yet migrated.
70+
if path.exists() {
71+
tracing::info!("Using new path");
72+
return path;
7873
}
7974

80-
tracing::info!("Using new path");
81-
path
75+
tracing::info!("Using legacy path");
76+
home.join("forge")
8277
}
8378

8479
/// Adds the provided TOML string as a config source without touching the

0 commit comments

Comments
 (0)