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: path option should take precedence over global configuration #4249

Merged
merged 1 commit into from
Jan 29, 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
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