Skip to content

Commit

Permalink
fix: use mise.toml instead of .mise.toml by default in mise use
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Nov 6, 2024
1 parent 48a6f7b commit 63de228
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 41 deletions.
22 changes: 13 additions & 9 deletions e2e/cli/test_use
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion e2e/lockfile/test_lockfile_exec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export MISE_LOCKFILE=1
export MISE_EXPERIMENTAL=1

touch .mise.lock
touch mise.lock
mise install [email protected]
mise use tiny@1
mise install [email protected]
Expand Down
4 changes: 2 additions & 2 deletions e2e/lockfile/test_lockfile_install
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
export MISE_LOCKFILE=1
export MISE_EXPERIMENTAL=1

touch .mise.lock
touch mise.lock
mise use tiny@1
cat <<EOF >.mise.lock
cat <<EOF >mise.lock
[tools]
tiny = "1.0.0"
EOF
Expand Down
14 changes: 7 additions & 7 deletions e2e/lockfile/test_lockfile_use
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@
export MISE_LOCKFILE=1
export MISE_EXPERIMENTAL=1

touch .mise.lock
touch mise.lock
mise install [email protected]
mise use tiny@1
mise install [email protected]
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",
Expand Down
40 changes: 22 additions & 18 deletions src/cli/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -146,16 +146,27 @@ impl Use {
}

fn get_config_file(&self) -> Result<Box<dyn ConfigFile>> {
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)
}
Expand Down Expand Up @@ -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::<Vec<_>>();
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),
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ fn load_legacy_files() -> BTreeMap<String, Vec<String>> {
}

pub static LOCAL_CONFIG_FILENAMES: Lazy<Vec<&'static str>> = 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",
Expand All @@ -579,8 +579,8 @@ pub static LOCAL_CONFIG_FILENAMES: Lazy<Vec<&'static str>> = 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",
Expand Down
2 changes: 1 addition & 1 deletion src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub static MISE_DEFAULT_TOOL_VERSIONS_FILENAME: Lazy<String> = Lazy::new(|| {
var("MISE_DEFAULT_TOOL_VERSIONS_FILENAME").unwrap_or_else(|_| ".tool-versions".into())
});
pub static MISE_DEFAULT_CONFIG_FILENAME: Lazy<String> =
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<Option<String>> = Lazy::new(|| environment(&ARGS.read().unwrap()));
pub static MISE_SETTINGS_FILE: Lazy<PathBuf> = Lazy::new(|| {
var_path("MISE_SETTINGS_FILE").unwrap_or_else(|| MISE_CONFIG_DIR.join("settings.toml"))
Expand Down

0 comments on commit 63de228

Please sign in to comment.