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: mise rm removes/reports wrong version of tool #4272

Merged
merged 3 commits into from
Jan 30, 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: 11 additions & 4 deletions e2e/cli/test_unuse
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,28 @@ assert_empty "mise ls"

assert "mise use [email protected]"
assert_contains "mise ls dummy" "1.0.0"
assert "mise unuse dummy"
assert "mise unuse dummy@1.0.0"
assert_empty "mise ls dummy"

assert "mise use [email protected]"
mkdir subdir
cd subdir || exit 1
assert "mise use -p mise.toml [email protected]"
assert "mise ls dummy" "dummy 1.0.0 ~/workdir/subdir/mise.toml 1.0.0"
assert "mise unuse dummy"
assert "mise unuse dummy@1.0.0"
# version is not pruned because it's in ~/workdir/mise.toml
assert "mise ls dummy" "dummy 1.0.0 ~/workdir/mise.toml 1.0.0"
assert "mise unuse dummy"
assert "mise unuse dummy@1.0.0"
assert_empty "mise ls dummy"
cd - || exit 1

assert "mise use -g [email protected]"
assert "mise ls dummy" "dummy 1.0.0 ~/.config/mise/config.toml 1.0.0"
assert "mise unuse dummy"
assert "mise unuse dummy@1.0.0"
assert_empty "mise ls dummy"

assert "mise use [email protected]"
assert "mise ls dummy" "dummy 2.0.0 ~/workdir/mise.toml 2.0.0"
# tool is not removed because version does not match
assert "mise unuse [email protected]"
assert "mise ls dummy" "dummy 2.0.0 ~/workdir/mise.toml 2.0.0"
17 changes: 13 additions & 4 deletions src/cli/unuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::config;
use crate::config::config_file::ConfigFile;
use crate::config::{config_file, Config};
use crate::file::display_path;
use crate::toolset::ToolRequest;
use eyre::Result;
use itertools::Itertools;

Expand Down Expand Up @@ -31,12 +32,20 @@ impl Unuse {
let config = Config::get();
let mut cf = self.get_config_file(&config)?;
let tools = cf.to_tool_request_set()?.tools;
let mut removed = vec![];
let mut removed: Vec<&ToolArg> = vec![];
for ta in &self.installed_tool {
if tools.contains_key(&ta.ba) {
removed.push(ta);
if let Some(tool_requests) = tools.get(&ta.ba) {
let tools_to_remove: Vec<&ToolRequest> = tool_requests
.iter()
.filter(|tv| {
tv.version() == ta.version.as_ref().map_or("latest", |v| v.as_str())
})
.collect();
for _tool in tools_to_remove {
removed.push(ta);
cf.remove_tool(&ta.ba)?;
}
}
cf.remove_tool(&ta.ba)?;
}
if removed.is_empty() {
debug!("no tools to remove");
Expand Down