@@ -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]
0 commit comments