diff --git a/CHANGELOG.md b/CHANGELOG.md index e5cc5e9..1386f12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - New method `Toolchain::remove_component` +### Fixed + +- When passed a global command with the same name as a file in the current directory, + Rustwide will now execute the global command instead of the file. + ## [0.8.0] - 2020-06-05 ### Added diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index ee4f01a..e2e3fff 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -370,19 +370,22 @@ impl<'w, 'pl> Command<'w, 'pl> { ) } else { let (binary, managed_by_rustwide) = match self.binary { + // global paths should never be normalized Binary::Global(path) => (path, false), - Binary::ManagedByRustwide(path) => ( - self.workspace + Binary::ManagedByRustwide(path) => { + let binary = self + .workspace .expect("calling rustwide bins without a workspace is not supported") .cargo_home() .join("bin") - .join(exe_suffix(path.as_os_str())), - true, - ), + .join(exe_suffix(path.as_os_str())); + // `cargo_home()` might a relative path + (crate::utils::normalize_path(&binary), true) + } Binary::__NonExaustive => panic!("do not create __NonExaustive variants manually"), }; - let mut cmd = AsyncCommand::new(crate::utils::normalize_path(&binary)); + let mut cmd = AsyncCommand::new(&binary); cmd.args(&self.args); if managed_by_rustwide { diff --git a/tests/issue_30.rs b/tests/issue_30.rs new file mode 100644 index 0000000..96abbc3 --- /dev/null +++ b/tests/issue_30.rs @@ -0,0 +1,17 @@ +use failure::Error; +use rustwide::cmd::Command; + +mod utils; + +#[test] +fn run_binary_with_same_name_as_file() -> Result<(), Error> { + use std::fs; + + let tmpdir = tempfile::tempdir()?; + std::env::set_current_dir(&tmpdir)?; + fs::write("true", b"foobar")?; + let workspace = crate::utils::init_workspace()?; + Command::new(&workspace, "true").run()?; + + Ok(()) +}