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 does not operate well under Git Bash on Windows #4048

Merged
merged 1 commit into from
Jan 30, 2025
Merged
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
46 changes: 43 additions & 3 deletions src/shims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ pub fn reshim(ts: &Toolset, force: bool) -> Result<()> {
#[cfg(windows)]
fn add_shim(mise_bin: &Path, symlink_path: &Path, shim: &str) -> Result<()> {
let shim = shim.trim_end_matches(".cmd");
// write a shim file without extension for use in Git Bash/Cygwin
file::write(
symlink_path.with_extension(""),
formatdoc! {r#"
#!/bin/bash

exec mise x -- {shim} "$@"
"#},
)
.wrap_err_with(|| {
eyre!(
"Failed to create symlink from {} to {}",
display_path(mise_bin),
display_path(symlink_path)
)
})?;
file::write(
symlink_path.with_extension("cmd"),
formatdoc! {r#"
Expand Down Expand Up @@ -180,7 +196,7 @@ pub fn get_shim_diffs(
fn get_actual_shims(mise_bin: impl AsRef<Path>) -> Result<HashSet<String>> {
let mise_bin = mise_bin.as_ref();

Ok(list_executables_in_dir(&dirs::SHIMS)?
Ok(list_shims()?
.into_par_iter()
.filter(|bin| {
let path = dirs::SHIMS.join(bin);
Expand Down Expand Up @@ -211,6 +227,27 @@ fn list_executables_in_dir(dir: &Path) -> Result<HashSet<String>> {
.collect())
}

fn list_shims() -> Result<HashSet<String>> {
Ok(dirs::SHIMS
.read_dir()?
.par_bridge()
.map(|bin| {
let bin = bin?;
// files and symlinks which are executable or extensionless files (Git Bash/Cygwin)
if (file::is_executable(&bin.path()) || bin.path().extension().is_none())
&& (bin.file_type()?.is_file() || bin.file_type()?.is_symlink())
{
Ok(Some(bin.file_name().into_string().unwrap()))
} else {
Ok(None)
}
})
.collect::<Result<Vec<_>>>()?
.into_iter()
.flatten()
.collect())
}

fn get_desired_shims(toolset: &Toolset) -> Result<HashSet<String>> {
Ok(toolset
.list_installed_versions()?
Expand All @@ -222,9 +259,12 @@ fn get_desired_shims(toolset: &Toolset) -> Result<HashSet<String>> {
});
if cfg!(windows) {
bins.into_iter()
.map(|b| {
.flat_map(|b| {
let p = PathBuf::from(&b);
p.with_extension("cmd").to_string_lossy().to_string()
vec![
p.with_extension("").to_string_lossy().to_string(),
Copy link
Owner

@jdx jdx Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bet we have a non-zero number of tools with bin names that have "." in them, this will probably break them—though I think that was the case before.

this is fine for now I think, but worth keeping in mind

p.with_extension("cmd").to_string_lossy().to_string(),
]
})
.collect()
} else {
Expand Down