diff --git a/src/config/mod.rs b/src/config/mod.rs index 805099f6955..e30e1a856f1 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -126,6 +126,7 @@ impl Config { Duration::from_secs(5), ) .await?; + Settings::reload(); Config::load().await } @@ -3248,6 +3249,18 @@ mod tests { assert_debug_snapshot!(config); } + #[tokio::test] + async fn test_reset_reloads_settings() { + Settings::reset(None); + let before = Settings::get(); + + Config::reset().await.unwrap(); + let after = Settings::get(); + + assert!(!Arc::ptr_eq(&before, &after)); + Settings::reset(None); + } + #[test] fn test_config_set_contains_matches_symlinked_prefix() { // Regression for https://github.com/jdx/mise/discussions/10483: diff --git a/src/config/settings.rs b/src/config/settings.rs index d80d83b58f9..241208ad86e 100644 --- a/src/config/settings.rs +++ b/src/config/settings.rs @@ -1,5 +1,4 @@ use crate::cli::Cli; -use crate::config::ALL_TOML_CONFIG_FILES; use crate::duration; use crate::file::FindUp; use crate::platform::Platform; @@ -24,6 +23,8 @@ use std::{ collections::{BTreeSet, HashSet}, sync::atomic::{AtomicBool, Ordering}, }; + +use super::{TOML_CONFIG_FILENAMES, load_config_paths}; use url::Url; // settings are generated from settings.toml in the project root @@ -762,9 +763,9 @@ impl Settings { } fn all_settings_files() -> Vec { - ALL_TOML_CONFIG_FILES - .iter() - .map(|p| Self::parse_settings_file(p)) + load_config_paths(&TOML_CONFIG_FILENAMES, false) + .into_iter() + .map(|p| Self::parse_settings_file(&p)) .filter_map(|cfg| match cfg { Ok(cfg) => Some(cfg), Err(e) => { @@ -798,6 +799,12 @@ impl Settings { crate::config::config_file::config_root::reset(); } + /// Invalidate settings loaded from config files without discarding CLI overrides. + pub fn reload() { + *BASE_SETTINGS.write().unwrap() = None; + crate::config::config_file::config_root::reset(); + } + /// Merge an override into the CLI-level settings partial. /// /// `reset` replaces CLI_SETTINGS wholesale, which would clobber overrides @@ -1614,6 +1621,18 @@ mod tests { Settings::reset(None); } + #[test] + fn test_reload_preserves_cli_settings() { + let mut partial = SettingsPartial::empty(); + partial.offline = Some(true); + Settings::reset(Some(partial)); + assert!(Settings::get().offline()); + + Settings::reload(); + assert!(Settings::get().offline()); + Settings::reset(None); + } + #[test] fn test_offline_implies_prefer_offline() { let mut partial = SettingsPartial::empty();