Skip to content

Commit

Permalink
Auto merge of #10685 - Muscraft:cargo-add-workspace-source, r=epage
Browse files Browse the repository at this point in the history
fix bugs with `workspace` key and `update_toml`

### Motivations and Context

When working on an external subcommand to help with the switch to workspace inheritance, I found issues with the output `Cargo.toml` it was creating. When a `cargo_add::Dependency` would change its source to a `WorkspsaceSource`, `workspace = true` would not show up. This lead me to discover that the `default-features` key was not being removed when the `workspace` key was set.

This fixes those issues but brought up questions about how to deal with removing keys and clearing conflicting fields in a `Dependency`. After talking with `@epage,` it was decided that this was the minimal set of changes to make while the changes to fix the other issues is workshopped.

### Changes
- add `default-features` to the list of keys to remove when the source is a `WorkspaceSource`
- insert a `workspace` key when the source is a `WorkspaceSource`
  • Loading branch information
bors committed May 20, 2022
2 parents 7524ccd + ffc1053 commit 83a7983
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cargo/ops/cargo_add/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,9 @@ impl Dependency {
}
}
Some(Source::Workspace(_)) => {
table.insert("workspace", toml_edit::value(true));
table.set_dotted(true);
key.fmt();
for key in [
"version",
"registry",
Expand All @@ -550,6 +552,7 @@ impl Dependency {
"tag",
"rev",
"package",
"default-features",
] {
table.remove(key);
}
Expand Down

0 comments on commit 83a7983

Please sign in to comment.