Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bug when using mise use -g when MISE_ENV is filled #4494

Merged
merged 2 commits into from
Feb 22, 2025
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
7 changes: 7 additions & 0 deletions e2e/cli/test_use
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ assert "cat ~/.config/mise/config.toml" '[tools]
gh = "2"'
rm -f ~/.config/mise/config.toml

export MISE_ENV=test
mise use -g dummy@1
assert "cat ~/.config/mise/config.toml" '[tools]
dummy = "1"'
rm -f ~/.config/mise/config.toml
unset MISE_ENV

mise uninstall dummy --all
mise use dummy@system
assert "mise ls dummy" "dummy system ~/workdir/mise.toml system"
Expand Down
6 changes: 4 additions & 2 deletions src/cli/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ impl Use {

fn get_config_file(&self) -> Result<Box<dyn ConfigFile>> {
let cwd = env::current_dir()?;
let path = if let Some(p) = &self.path {
let path = if self.global {
MISE_GLOBAL_CONFIG_FILE.clone()
} else if let Some(p) = &self.path {
let from_dir = config_file_from_dir(p).absolutize()?.to_path_buf();
if from_dir.starts_with(&cwd) {
from_dir
Expand All @@ -212,7 +214,7 @@ impl Use {
} else if !env::MISE_ENV.is_empty() {
let env = env::MISE_ENV.last().unwrap();
config_file_from_dir(&cwd.join(format!("mise.{env}.toml")))
} else if self.global || env::in_home_dir() {
} else if env::in_home_dir() {
MISE_GLOBAL_CONFIG_FILE.clone()
} else {
config_file_from_dir(&cwd)
Expand Down