Skip to content

Commit

Permalink
fix: path option should take precedence over global configuration (#4249
Browse files Browse the repository at this point in the history
)
  • Loading branch information
roele authored Jan 29, 2025
1 parent 64f4698 commit f342d0a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
15 changes: 15 additions & 0 deletions e2e/cli/test_use
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ dummy = "2"'
assert "mise current dummy" "2.0.0"
rm mise.local.toml

assert_contains "mise use --env local dummy@1" "dummy@1."
assert "cat mise.local.toml" '[tools]
dummy = "1"'
mv mise.local.toml .mise.local.toml
assert_contains "mise use --env local dummy@2" "dummy@2."
assert_fail "test -f mise.local.toml"
assert "cat .mise.local.toml" '[tools]
dummy = "2"'
rm .mise.local.toml

mise use dummy@1 dummy@2
assert "mise current dummy" "1.0.0 2.0.0"

Expand Down Expand Up @@ -75,3 +85,8 @@ assert_contains "mise ls dummy" "dummy path:~/workdir/mydummy ~/workdir/mise.t

cd "$HOME" || exit 1
assert_contains "mise use dummy@system" "mise ~/.config/mise/config.toml tools: dummy@system"

assert_contains "mise use --path mise.path.toml dummy@1" "dummy@1."
assert "cat mise.path.toml" '[tools]
dummy = "1"'
rm mise.path.toml
24 changes: 12 additions & 12 deletions src/cli/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,25 +195,25 @@ impl Use {

fn get_config_file(&self) -> Result<Box<dyn ConfigFile>> {
let cwd = env::current_dir()?;
let path = 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() {
MISE_GLOBAL_CONFIG_FILE.clone()
let path = 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
} else {
p.clone()
}
} else if let Some(env) = &self.env {
let p = cwd.join(format!(".mise.{env}.toml"));
if p.exists() {
p
} else {
cwd.join(format!("mise.{env}.toml"))
}
} 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
} else {
p.clone()
}
} 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() {
MISE_GLOBAL_CONFIG_FILE.clone()
} else {
config_file_from_dir(&cwd)
};
Expand Down

0 comments on commit f342d0a

Please sign in to comment.