cargo: Patching dependencies does not work if it's for the same location but a different branch

E.g.

[patch.'https://github.com/sdroege/gobject-subclass']
gobject-subclass = { git = 'https://github.com/sdroege/gobject-subclass', branch = 'refactoring' }

This gives

error: failed to resolve patches for `https://github.com/sdroege/gobject-subclass`

Caused by:
  patch for `gobject-subclass` in `https://github.com/sdroege/gobject-subclass` points to the same source, but patches must point to different sources

About this issue

  • Original URL
  • State: open
  • Created 9 years ago
  • Reactions: 84
  • Comments: 25 (8 by maintainers)

Commits related to this issue

Most upvoted comments

For GitHub repositories, one can work around this by [patch]ing https://github.com/user/repo to https://github.com/user/repo.git (or the other way around).

Nice workaround hack! Further ways to change the URL string include adding / to the url like https://github.com////user///repo . This method scales to unlimited amounts of different urls for the same repo.

For GitHub repositories, one can work around this by [patch]ing https://github.com/user/repo to https://github.com/user/repo.git (or the other way around).

Nice workaround hack! Further ways to change the URL string include adding / to the url like https://github.com////user///repo . This method scales to unlimited amounts of different urls for the same repo.

These workarounds no longer do it for me (using cargo 1.52.0)–perhaps Cargo is now normalizing repo names?

If anyone is having trouble with overriding SSH URLs, and can’t use HTTPS for whatever reason (eg. private git repo) I found another workaround is to add the port number to the URL, like ssh://git@github.com:22/<org>/<repo>.git

For GitHub repositories, one can work around this by [patch]ing https://github.com/user/repo to https://github.com/user/repo.git (or the other way around).

If you want to patch a crate from crates.io with crates.io itself (which often comes up when you just want to change the version), you can do it like this:

# Cargo.toml
[patch.crates-io]
zip = { version = "=2.5.0", registry = "crates-io-2" }
# .cargo/config.toml
[registries]
crates-io-2 = { index = "sparse+https://index.crates.io/" }

This can lead to the same sub-dependency being downloaded from both crates-io and crates-io-2. It’s not a major issue to download the same dependency twice, but just be aware of it.

Have you tried this:

ethers-rs = { git = "https://github.com/gakonst////ethers-rs.git", branch = "test" }

The canonicalization code only strips trailing / and .git. For extra / inside the URL, it doesn’t do anything.

This worked for me (www and .git) :

[patch.'https://github.com/foo/bar']
baz = { git = "https://www.github.com/foo/bar.git", branch = "test" }

this bug has been open for a long time. is there hope? we’re stuck with a suboptimal setup due to this.

For GitHub repositories, one can work around this by [patch]ing https://github.com/user/repo to https://github.com/user/repo.git (or the other way around).

this has been mentioned already but cargo normalization defeats this feature now it seems. did anyone have a new workaround? @jplatte