Skip to content

Commit

Permalink
Fix #13702
Browse files Browse the repository at this point in the history
  • Loading branch information
dohse committed May 2, 2024
1 parent 67f77a5 commit c7890fa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
21 changes: 20 additions & 1 deletion src/cargo/ops/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,26 @@ fn resolve_dependency(
if dependency.source().is_none() {
// Checking for a workspace dependency happens first since a member could be specified
// in the workspace dependencies table as a dependency
if let Some(_dep) = find_workspace_dep(dependency.toml_key(), ws.root_manifest()).ok() {
let mut workspace_dep = find_workspace_dep(dependency.toml_key(), ws.root_manifest()).ok();
if workspace_dep.is_none() && dependency.rename.is_none() {
for name_permutation in [
dependency.name.replace('-', "_"),
dependency.name.replace('_', "-"),
] {
workspace_dep = find_workspace_dep(&name_permutation, ws.root_manifest()).ok();
if let Some(workspace_dep) = &workspace_dep {
if let Some(Source::Registry(_source)) = &workspace_dep.source {
gctx.shell().warn(format!(
"translating `{}` to `{}`",
dependency.name, &name_permutation,
))?;
dependency.name = name_permutation;
break;
}
}
}
}
if let Some(_dep) = workspace_dep {
dependency = dependency.set_source(WorkspaceSource::new());
} else if let Some(package) = ws.members().find(|p| p.name().as_str() == dependency.name) {
// Only special-case workspaces when the user doesn't provide any extra
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.0.0"
edition = "2015"

[dependencies]
fuzzy_dependency = "1.0.0"
fuzzy_dependency.workspace = true
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c7890fa

Please sign in to comment.