Skip to content
Merged
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
13 changes: 13 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ impl Config {
Duration::from_secs(5),
)
.await?;
Settings::reload();
Config::load().await
}

Expand Down Expand Up @@ -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:
Expand Down
27 changes: 23 additions & 4 deletions src/config/settings.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -762,9 +763,9 @@ impl Settings {
}

fn all_settings_files() -> Vec<SettingsPartial> {
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) => {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down