Skip to content
Merged
Changes from 1 commit
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
11 changes: 6 additions & 5 deletions src/config/config_file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,12 @@ pub fn trust_check(path: &Path) -> eyre::Result<()> {
return Ok(());
}
if cmd != "hook-env" && !is_ignored(&config_root) && !is_ignored(path) {
let ans = prompt::confirm_with_all(format!(
"{} config files in {} are not trusted. Trust them?",
style::eyellow("mise"),
style::epath(&config_root)
))?;
let ans = (settings::is_loaded() && Settings::get().yes)
|| prompt::confirm_with_all(format!(
"{} config files in {} are not trusted. Trust them?",
style::eyellow("mise"),
style::epath(&config_root)
))?;
Comment on lines +303 to +308

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This implementation is a bit brittle. It relies on settings being loaded before this function is called. If trust_check is ever called in a context where settings haven't been loaded, settings::is_loaded() will be false, and the user will be prompted even if they passed --yes or MISE_YES=1.

A more robust approach would be to attempt to load the settings here. This ensures the --yes flag is always respected, regardless of the call context.

Using try_get() and mapping the result is a safe way to do this without panicking if settings fail to load, falling back to prompting in that case.

Suggested change
let ans = (settings::is_loaded() && Settings::get().yes)
|| prompt::confirm_with_all(format!(
"{} config files in {} are not trusted. Trust them?",
style::eyellow("mise"),
style::epath(&config_root)
))?;
let ans = settings::Settings::try_get().map(|s| s.yes).unwrap_or(false)
|| prompt::confirm_with_all(format!(
"{} config files in {} are not trusted. Trust them?",
style::eyellow("mise"),
style::epath(&config_root)
))?;

if ans {
trust(&config_root)?;
return Ok(());
Expand Down
Loading