diff --git a/e2e/cli/test_use b/e2e/cli/test_use index 99012ea52c..9444b024db 100644 --- a/e2e/cli/test_use +++ b/e2e/cli/test_use @@ -12,30 +12,34 @@ assert_not_contains "mise use --rm dummy" "dummy" assert "mise current dummy" "" assert_contains "mise use --env local dummy@2" "dummy@2." -assert "cat .mise.local.toml" '[tools] +assert "cat mise.local.toml" '[tools] dummy = "2"' assert "mise current dummy" "2.0.0" -rm .mise.local.toml +rm mise.local.toml mise use dummy@1 dummy@2 assert "mise current dummy" "1.0.0 2.0.0" mise use --pin dummy@1 -assert "cat .mise.toml" '[tools] +assert "cat mise.toml" '[tools] dummy = "1.0.0"' MISE_PIN=1 mise use --fuzzy dummy@1 -assert "cat .mise.toml" '[tools] +assert "cat mise.toml" '[tools] dummy = "1"' -MISE_PIN=1 mise use dummy@1 --path .mise.local.toml -assert "cat .mise.local.toml" '[tools] +MISE_PIN=1 mise use dummy@1 --path mise.local.toml +assert "cat mise.local.toml" '[tools] dummy = "1.0.0"' -mise use --rm dummy --path .mise.local.toml -assert "cat .mise.local.toml" "" +mise use --rm dummy --path mise.local.toml +assert "cat mise.local.toml" "" -rm -f .mise.local.toml .mise.toml +mise use dummy@1 +assert "cat mise.local.toml" '[tools] +dummy = "1"' + +rm -f mise.local.toml mise.toml echo "dummy 1.0.0" >.tool-versions mise use dummy@2 assert "cat .tool-versions" "dummy 2" diff --git a/e2e/lockfile/test_lockfile_exec b/e2e/lockfile/test_lockfile_exec index dbc8a02153..c4fd278f6a 100644 --- a/e2e/lockfile/test_lockfile_exec +++ b/e2e/lockfile/test_lockfile_exec @@ -3,7 +3,7 @@ export MISE_LOCKFILE=1 export MISE_EXPERIMENTAL=1 -touch .mise.lock +touch mise.lock mise install tiny@1.0.0 mise use tiny@1 mise install tiny@1.0.1 diff --git a/e2e/lockfile/test_lockfile_install b/e2e/lockfile/test_lockfile_install index e441b0fb60..999bbb1f8a 100644 --- a/e2e/lockfile/test_lockfile_install +++ b/e2e/lockfile/test_lockfile_install @@ -3,9 +3,9 @@ export MISE_LOCKFILE=1 export MISE_EXPERIMENTAL=1 -touch .mise.lock +touch mise.lock mise use tiny@1 -cat <.mise.lock +cat <mise.lock [tools] tiny = "1.0.0" EOF diff --git a/e2e/lockfile/test_lockfile_use b/e2e/lockfile/test_lockfile_use index df06b6e15e..90ace4c9b1 100644 --- a/e2e/lockfile/test_lockfile_use +++ b/e2e/lockfile/test_lockfile_use @@ -3,37 +3,37 @@ export MISE_LOCKFILE=1 export MISE_EXPERIMENTAL=1 -touch .mise.lock +touch mise.lock mise install tiny@1.0.0 mise use tiny@1 mise install tiny@1.0.1 -assert "mise config get -f .mise.toml tools.tiny" "1" +assert "mise config get -f mise.toml tools.tiny" "1" assert "mise where tiny" "$MISE_DATA_DIR/installs/tiny/1.0.0" assert "mise ls tiny --json --current | jq -r '.[0].requested_version'" "1" assert "mise ls tiny --json --current | jq -r '.[0].version'" "1.0.0" -assert "cat .mise.lock" '[tools] +assert "cat mise.lock" '[tools] tiny = "1.0.0"' mise use tiny@1 -assert "cat .mise.lock" '[tools] +assert "cat mise.lock" '[tools] tiny = "1.0.1"' assert "mise ls tiny --json --current | jq -r '.[0].requested_version'" "1" assert "mise ls tiny --json --current | jq -r '.[0].version'" "1.0.1" mise up tiny -assert "cat .mise.lock" '[tools] +assert "cat mise.lock" '[tools] tiny = "1.1.0"' assert "mise ls tiny --json --current | jq -r '.[0].requested_version'" "1" assert "mise ls tiny --json --current | jq -r '.[0].version'" "1.1.0" mise up tiny --bump -assert "cat .mise.lock" '[tools] +assert "cat mise.lock" '[tools] tiny = "3.1.0"' assert "mise ls tiny --json --current | jq -r '.[0].requested_version'" "3" assert "mise ls tiny --json --current | jq -r '.[0].version'" "3.1.0" mise use tiny@1 tiny@2 -assert "cat .mise.lock" '[tools] +assert "cat mise.lock" '[tools] tiny = [ "1.0.0", "2.1.0", diff --git a/src/cli/use.rs b/src/cli/use.rs index 8709d767b4..a7a10ce0ea 100644 --- a/src/cli/use.rs +++ b/src/cli/use.rs @@ -10,7 +10,7 @@ use crate::config::{config_file, is_global_config, Config, LOCAL_CONFIG_FILENAME use crate::env::{ MISE_DEFAULT_CONFIG_FILENAME, MISE_DEFAULT_TOOL_VERSIONS_FILENAME, MISE_GLOBAL_CONFIG_FILE, }; -use crate::file::display_path; +use crate::file::{display_path, FindUp}; use crate::toolset::{InstallOptions, ToolRequest, ToolSource, ToolVersion, ToolsetBuilder}; use crate::ui::multi_progress_report::MultiProgressReport; use crate::{env, file, lockfile}; @@ -146,16 +146,27 @@ impl Use { } fn get_config_file(&self) -> Result> { + let cwd = env::current_dir()?; let path = if let Some(env) = &*env::MISE_ENV { - config_file_from_dir(&env::current_dir()?.join(format!(".mise.{}.toml", env))) + config_file_from_dir(&cwd.join(format!("mise.{env}.toml"))) } else if self.global { MISE_GLOBAL_CONFIG_FILE.clone() } else if let Some(env) = &self.env { - config_file_from_dir(&env::current_dir()?.join(format!(".mise.{}.toml", 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 { - config_file_from_dir(p) + let from_dir = config_file_from_dir(p); + if from_dir.starts_with(&cwd) { + from_dir + } else { + p.clone() + } } else { - config_file_from_dir(&env::current_dir()?) + config_file_from_dir(&cwd) }; config_file::parse_or_init(&path) } @@ -195,25 +206,18 @@ fn config_file_from_dir(p: &Path) -> PathBuf { if !p.is_dir() { return p.to_path_buf(); } - let mise_toml = p.join(&*MISE_DEFAULT_CONFIG_FILENAME); - let tool_versions = p.join(&*MISE_DEFAULT_TOOL_VERSIONS_FILENAME); - if mise_toml.exists() { - return mise_toml; - } else if tool_versions.exists() { - return tool_versions; - } let filenames = LOCAL_CONFIG_FILENAMES .iter() - .rev() - .filter(|f| is_global_config(Path::new(f))) .map(|f| f.to_string()) .collect::>(); - if let Some(p) = file::find_up(p, &filenames) { - return p; + for p in FindUp::new(p, &filenames) { + if !is_global_config(&p) { + return p; + } } match SETTINGS.asdf_compat { - true => tool_versions, - false => mise_toml, + true => p.join(&*MISE_DEFAULT_TOOL_VERSIONS_FILENAME), + false => p.join(&*MISE_DEFAULT_CONFIG_FILENAME), } } diff --git a/src/config/mod.rs b/src/config/mod.rs index ff4d2f4411..a6f7c7aaf6 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -570,7 +570,7 @@ fn load_legacy_files() -> BTreeMap> { } pub static LOCAL_CONFIG_FILENAMES: Lazy> = Lazy::new(|| { - if *env::MISE_DEFAULT_CONFIG_FILENAME == ".mise.toml" { + if *env::MISE_DEFAULT_CONFIG_FILENAME == "mise.toml" { vec![ &*env::MISE_DEFAULT_TOOL_VERSIONS_FILENAME, // .tool-versions ".config/mise/config.toml", @@ -579,8 +579,8 @@ pub static LOCAL_CONFIG_FILENAMES: Lazy> = Lazy::new(|| { "mise/config.toml", ".mise/config.toml", ".rtx.toml", - "mise.toml", - &*env::MISE_DEFAULT_CONFIG_FILENAME, // .mise.toml + &*env::MISE_DEFAULT_CONFIG_FILENAME, // mise.toml + ".mise.toml", ".config/mise/config.local.toml", ".config/mise.local.toml", ".mise/config.local.toml", diff --git a/src/env.rs b/src/env.rs index 1b6fb2c13a..cea846b573 100644 --- a/src/env.rs +++ b/src/env.rs @@ -83,7 +83,7 @@ pub static MISE_DEFAULT_TOOL_VERSIONS_FILENAME: Lazy = Lazy::new(|| { var("MISE_DEFAULT_TOOL_VERSIONS_FILENAME").unwrap_or_else(|_| ".tool-versions".into()) }); pub static MISE_DEFAULT_CONFIG_FILENAME: Lazy = - Lazy::new(|| var("MISE_DEFAULT_CONFIG_FILENAME").unwrap_or_else(|_| ".mise.toml".into())); + Lazy::new(|| var("MISE_DEFAULT_CONFIG_FILENAME").unwrap_or_else(|_| "mise.toml".into())); pub static MISE_ENV: Lazy> = Lazy::new(|| environment(&ARGS.read().unwrap())); pub static MISE_SETTINGS_FILE: Lazy = Lazy::new(|| { var_path("MISE_SETTINGS_FILE").unwrap_or_else(|| MISE_CONFIG_DIR.join("settings.toml"))