Skip to content

Commit b3a1a50

Browse files
committed
fix: update --breaking now understands package@version.
1 parent 696b054 commit b3a1a50

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

src/cargo/ops/cargo_update.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ pub fn upgrade_manifests(
222222
let mut upgrades = HashMap::new();
223223
let mut upgrade_messages = HashSet::new();
224224

225+
let to_update = to_update
226+
.iter()
227+
.map(|s| PackageIdSpec::parse(s))
228+
.collect::<Result<Vec<_>, _>>()?;
229+
225230
// Updates often require a lot of modifications to the registry, so ensure
226231
// that we're synchronized against other Cargos.
227232
let _lock = gctx.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)?;
@@ -239,7 +244,7 @@ pub fn upgrade_manifests(
239244
.try_map_dependencies(|d| {
240245
upgrade_dependency(
241246
&gctx,
242-
to_update,
247+
&to_update,
243248
&mut registry,
244249
&mut upgrades,
245250
&mut upgrade_messages,
@@ -253,7 +258,7 @@ pub fn upgrade_manifests(
253258

254259
fn upgrade_dependency(
255260
gctx: &GlobalContext,
256-
to_update: &Vec<String>,
261+
to_update: &Vec<PackageIdSpec>,
257262
registry: &mut PackageRegistry<'_>,
258263
upgrades: &mut UpgradeMap,
259264
upgrade_messages: &mut HashSet<String>,
@@ -271,7 +276,18 @@ fn upgrade_dependency(
271276
return Ok(dependency);
272277
}
273278

274-
if !to_update.is_empty() && !to_update.contains(&name.to_string()) {
279+
if !to_update.is_empty()
280+
&& !to_update.iter().any(|spec| {
281+
spec.name() == name.as_str()
282+
&& dependency.source_id().is_registry()
283+
&& spec
284+
.url()
285+
.map_or(true, |url| url == dependency.source_id().url())
286+
&& spec
287+
.version()
288+
.map_or(true, |v| dependency.version_req().matches(&v))
289+
})
290+
{
275291
trace!("skipping dependency `{}` not selected for upgrading", name);
276292
return Ok(dependency);
277293
}

tests/testsuite/update.rs

+27-4
Original file line numberDiff line numberDiff line change
@@ -2247,7 +2247,12 @@ fn update_breaking_spec_version() {
22472247
// Invalid spec
22482248
p.cargo("update -Zunstable-options --breaking incompatible@foo")
22492249
.masquerade_as_nightly_cargo(&["update-breaking"])
2250-
.with_stderr("")
2250+
.with_status(101)
2251+
.with_stderr(
2252+
"\
2253+
[ERROR] expected a version like \"1.32\"
2254+
",
2255+
)
22512256
.run();
22522257

22532258
// Spec version not matching our current dependencies
@@ -2265,20 +2270,38 @@ fn update_breaking_spec_version() {
22652270
// Accepted spec
22662271
p.cargo("update -Zunstable-options --breaking [email protected]")
22672272
.masquerade_as_nightly_cargo(&["update-breaking"])
2268-
.with_stderr("")
2273+
.with_stderr(
2274+
"\
2275+
[UPDATING] `[..]` index
2276+
[UPGRADING] incompatible ^1.0 -> ^2.0
2277+
[LOCKING] 1 package to latest compatible version
2278+
[UPDATING] incompatible v1.0.0 -> v2.0.0
2279+
",
2280+
)
22692281
.run();
22702282

22712283
// Accepted spec, full format
22722284
Package::new("incompatible", "3.0.0").publish();
22732285
p.cargo("update -Zunstable-options --breaking https://github.com/rust-lang/crates.io-index#[email protected]")
22742286
.masquerade_as_nightly_cargo(&["update-breaking"])
2275-
.with_stderr("")
2287+
.with_stderr(
2288+
"\
2289+
[UPDATING] `[..]` index
2290+
[UPGRADING] incompatible ^2.0 -> ^3.0
2291+
[LOCKING] 1 package to latest compatible version
2292+
[UPDATING] incompatible v2.0.0 -> v3.0.0
2293+
",
2294+
)
22762295
.run();
22772296

22782297
// Spec matches a dependency that will not be upgraded
22792298
p.cargo("update -Zunstable-options --breaking [email protected]")
22802299
.masquerade_as_nightly_cargo(&["update-breaking"])
2281-
.with_stderr("")
2300+
.with_stderr(
2301+
"\
2302+
[UPDATING] `[..]` index
2303+
",
2304+
)
22822305
.run();
22832306

22842307
// Non-existing versions

0 commit comments

Comments
 (0)