cargo-edit
cargo-edit copied to clipboard
Add support for managing "[patch.crates-io]"
The proposal is to allow cargo-edit to manage this Cargo feature:
https://rust-lang-nursery.github.io/edition-guide/rust-2018/cargo-and-crates-io/replacing-dependencies-with-patch.html
The command cargo add-patch frob --path=~/frob
would add a line to a patch
section in Cargo.toml
:
[patch.crates-io]
frob = { path = "/home/user/frob" }
The cargo rm-patch frob
would remove this line.
Some complexities / open questions:
- The section may have to be created when adding a patch.
- The section should probably be deleted when removing the last line of content.
- The section name contains the repository name (which is usually, but not always,
crates-io
). This could be specified using an extra argument that defaults to the default repository, but the naming of that argument is a bit tricky since you are potentially dealing with two repository names (the original one and the override). We could also in theory try to auto-detect the repository name by searching the dependency graph for the named crate, but (again, in theory) I think it might be possible to find two crates with the same name in the dependency graph from different repositories?
Edit: Made various changes after thinking about it some more.
@killercup Would a PR be accepted that implements this to an extent?
This functionality seems useful, but I'm not convinced about adding new commands for that and not e.g. using --patch-crates-io
flag. A PR would be accepted, but we need to agree on how will it look like first.
Agreed. It's a good feature to have, especially if we can make it work smoothly (e.g. by checking that the path contains the expected crate and other things you'd not get by editing the file by hand).