我依赖于 crate a
和b
,我在ref
foo
上将b
修补为git依赖:
# Cargo.toml of my crate
[dependencies]
a = "1.0.0"
b = "1.0.0"
[patch.crates-io]
b = { git = "https://github.com/user/example", rev = "foo" }
a
还依赖于b
作为git依赖项,但不依赖于特定的ref
:
# Cargo.toml of a
[dependencies]
b = { git = "https://github.com/user/example" }
我想强迫a
和我一样用ref
换b
,我想我可以这样做:
# The ideal Cargo.toml of my crate
[dependencies]
a = "1.0.0"
b = "1.0.0"
# patch local dependency
[patch.crates-io]
b = { git = "https://github.com/user/example", rev = "foo" }
# patch transient dependency
[patch.'https://github.com/user/example']
b = { git = "https://github.com/user/example", rev = "foo" }
但是,这不起作用,因为我正在修补的源仍然指向同一个源,只是在不同的rev
中:
error: failed to resolve patches for `https://github.com/user/example`
Caused by:
patch for `b` in `https://github.com/user/example` points to the same source, but patches must point to different sources
[Finished running. Exit status: 101]
到目前为止,我的解决方法是Forking b
,然后像这样修补:
# Cargo.toml of my crate using a work around
[dependencies]
a = "1.0.0"
b = "1.0.0"
[patch.crates-io]
b = { git = "https://github.com/me/example", rev = "foo" } # Using my fork
[patch.'https://github.com/user/example']
b = { git = "https://github.com/me/example", rev = "foo" } # Using my fork
这是可行的,但fork 基本上是无用的.有更好的方法吗?
我试过this hack,但也不起作用,因为它忽略了rev
.GitHub的整个问题让我觉得我正在try 的功能目前不受支持,但很难说,因为它不是完全相同的功能.