Skip to content

Commit 1e9f0ee

Browse files
committed
fix: update --breaking now understands package@version.
1 parent 38d9a71 commit 1e9f0ee

File tree

2 files changed

+59
-10
lines changed

2 files changed

+59
-10
lines changed

src/cargo/ops/cargo_update.rs

Lines changed: 19 additions & 3 deletions
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>,
@@ -267,7 +272,18 @@ fn upgrade_dependency(
267272
return Ok(dependency);
268273
}
269274

270-
if !to_update.is_empty() && !to_update.contains(&name.to_string()) {
275+
if !to_update.is_empty()
276+
&& !to_update.iter().any(|spec| {
277+
spec.name() == name.as_str()
278+
&& dependency.source_id().is_registry()
279+
&& spec
280+
.url()
281+
.map_or(true, |url| url == dependency.source_id().url())
282+
&& spec
283+
.version()
284+
.map_or(true, |v| dependency.version_req().matches(&v))
285+
})
286+
{
271287
trace!("skipping dependency `{name}` not selected for upgrading");
272288
return Ok(dependency);
273289
}

tests/testsuite/update.rs

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,7 +2296,12 @@ fn update_breaking_spec_version() {
22962296
// Invalid spec
22972297
p.cargo("update -Zunstable-options --breaking incompatible@foo")
22982298
.masquerade_as_nightly_cargo(&["update-breaking"])
2299-
.with_stderr("")
2299+
.with_status(101)
2300+
.with_stderr(
2301+
"\
2302+
[ERROR] expected a version like \"1.32\"
2303+
",
2304+
)
23002305
.run();
23012306

23022307
// Spec version not matching our current dependencies
@@ -2314,20 +2319,38 @@ fn update_breaking_spec_version() {
23142319
// Accepted spec
23152320
p.cargo("update -Zunstable-options --breaking [email protected]")
23162321
.masquerade_as_nightly_cargo(&["update-breaking"])
2317-
.with_stderr("")
2322+
.with_stderr(
2323+
"\
2324+
[UPDATING] `[..]` index
2325+
[UPGRADING] incompatible ^1.0 -> ^2.0
2326+
[LOCKING] 1 package to latest compatible version
2327+
[UPDATING] incompatible v1.0.0 -> v2.0.0
2328+
",
2329+
)
23182330
.run();
23192331

23202332
// Accepted spec, full format
23212333
Package::new("incompatible", "3.0.0").publish();
23222334
p.cargo("update -Zunstable-options --breaking https://github.com/rust-lang/crates.io-index#[email protected]")
23232335
.masquerade_as_nightly_cargo(&["update-breaking"])
2324-
.with_stderr("")
2336+
.with_stderr(
2337+
"\
2338+
[UPDATING] `[..]` index
2339+
[UPGRADING] incompatible ^2.0 -> ^3.0
2340+
[LOCKING] 1 package to latest compatible version
2341+
[UPDATING] incompatible v2.0.0 -> v3.0.0
2342+
",
2343+
)
23252344
.run();
23262345

23272346
// Spec matches a dependency that will not be upgraded
23282347
p.cargo("update -Zunstable-options --breaking [email protected]")
23292348
.masquerade_as_nightly_cargo(&["update-breaking"])
2330-
.with_stderr("")
2349+
.with_stderr(
2350+
"\
2351+
[UPDATING] `[..]` index
2352+
",
2353+
)
23312354
.run();
23322355

23332356
// Non-existing versions
@@ -2387,14 +2410,24 @@ fn update_breaking_spec_version_transitive() {
23872410
// Will upgrade the direct dependency
23882411
p.cargo("update -Zunstable-options --breaking [email protected]")
23892412
.masquerade_as_nightly_cargo(&["update-breaking"])
2390-
// FIXME: Should upgrade a dependency here.
2391-
.with_stderr("")
2413+
.with_stderr(
2414+
"\
2415+
[UPDATING] `[..]` index
2416+
[UPGRADING] dep ^1.0 -> ^2.0
2417+
[LOCKING] 1 package to latest compatible version
2418+
[ADDING] dep v2.0.0
2419+
",
2420+
)
23922421
.run();
23932422

23942423
// But not the transitive one, because bar is not a workspace member
23952424
p.cargo("update -Zunstable-options --breaking [email protected]")
23962425
.masquerade_as_nightly_cargo(&["update-breaking"])
2397-
.with_stderr("")
2426+
.with_stderr(
2427+
"\
2428+
[UPDATING] `[..]` index
2429+
",
2430+
)
23982431
.run();
23992432

24002433
// A non-breaking update is different, as it will update transitive dependencies

0 commit comments

Comments
 (0)