cargo-edit icon indicating copy to clipboard operation
cargo-edit copied to clipboard

Add support for managing "[patch.crates-io]"

Open rvolgers opened this issue 6 years ago • 6 comments

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.

rvolgers avatar Feb 17 '19 15:02 rvolgers

@killercup Would a PR be accepted that implements this to an extent?

jhpratt avatar Mar 27 '20 15:03 jhpratt

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.

ordian avatar Mar 27 '20 15:03 ordian

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).

killercup avatar Mar 28 '20 16:03 killercup