Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dohse committed May 2, 2024
1 parent ea24eaa commit 67f77a5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
19 changes: 18 additions & 1 deletion src/cargo/ops/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,24 @@ fn resolve_dependency(
};
selected_dep = populate_dependency(selected_dep, arg);

let old_dep = get_existing_dependency(manifest, selected_dep.toml_key(), section)?;
let mut old_dep = get_existing_dependency(manifest, selected_dep.toml_key(), section)?;
if old_dep.is_none() && selected_dep.source().is_none() && selected_dep.rename().is_none() {
for name_permutation in [
selected_dep.name.replace('-', "_"),
selected_dep.name.replace('_', "-"),
] {
old_dep = get_existing_dependency(manifest, &name_permutation, section)?;
if old_dep.is_some() {
gctx.shell().warn(format!(
"translating `{}` to `{}`",
selected_dep.name, &name_permutation,
))?;
selected_dep.name = name_permutation;
break;
}
}
}

let mut dependency = if let Some(mut old_dep) = old_dep.clone() {
if old_dep.name != selected_dep.name {
// Assuming most existing keys are not relevant when the package changes
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/cargo_add/features_fuzzy/out/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ version = "0.0.0"
edition = "2015"

[dependencies]
your_face = { version = "99999.0.0" }
your_face = { version = "99999.0.0", features = ["eyes"] }
8 changes: 4 additions & 4 deletions tests/testsuite/cargo_add/features_fuzzy/stderr.term.svg
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 67f77a5

Please sign in to comment.