Skip to content

Commit 4d9ed99

Browse files
committed
fix: update --breaking now understands package@version.
1 parent 7728905 commit 4d9ed99

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
@@ -2264,7 +2264,12 @@ fn update_breaking_spec_version() {
22642264
// Invalid spec
22652265
p.cargo("update -Zunstable-options --breaking incompatible@foo")
22662266
.masquerade_as_nightly_cargo(&["update-breaking"])
2267-
.with_stderr("")
2267+
.with_status(101)
2268+
.with_stderr(
2269+
"\
2270+
[ERROR] expected a version like \"1.32\"
2271+
",
2272+
)
22682273
.run();
22692274

22702275
// Spec version not matching our current dependencies
@@ -2282,20 +2287,38 @@ fn update_breaking_spec_version() {
22822287
// Accepted spec
22832288
p.cargo("update -Zunstable-options --breaking [email protected]")
22842289
.masquerade_as_nightly_cargo(&["update-breaking"])
2285-
.with_stderr("")
2290+
.with_stderr(
2291+
"\
2292+
[UPDATING] `[..]` index
2293+
[UPGRADING] incompatible ^1.0 -> ^2.0
2294+
[LOCKING] 1 package to latest compatible version
2295+
[UPDATING] incompatible v1.0.0 -> v2.0.0
2296+
",
2297+
)
22862298
.run();
22872299

22882300
// Accepted spec, full format
22892301
Package::new("incompatible", "3.0.0").publish();
22902302
p.cargo("update -Zunstable-options --breaking https://github.com/rust-lang/crates.io-index#[email protected]")
22912303
.masquerade_as_nightly_cargo(&["update-breaking"])
2292-
.with_stderr("")
2304+
.with_stderr(
2305+
"\
2306+
[UPDATING] `[..]` index
2307+
[UPGRADING] incompatible ^2.0 -> ^3.0
2308+
[LOCKING] 1 package to latest compatible version
2309+
[UPDATING] incompatible v2.0.0 -> v3.0.0
2310+
",
2311+
)
22932312
.run();
22942313

22952314
// Spec matches a dependency that will not be upgraded
22962315
p.cargo("update -Zunstable-options --breaking [email protected]")
22972316
.masquerade_as_nightly_cargo(&["update-breaking"])
2298-
.with_stderr("")
2317+
.with_stderr(
2318+
"\
2319+
[UPDATING] `[..]` index
2320+
",
2321+
)
22992322
.run();
23002323

23012324
// Non-existing versions
@@ -2355,14 +2378,24 @@ fn update_breaking_spec_version_transitive() {
23552378
// Will upgrade the direct dependency
23562379
p.cargo("update -Zunstable-options --breaking [email protected]")
23572380
.masquerade_as_nightly_cargo(&["update-breaking"])
2358-
// FIXME: Should upgrade a dependency here.
2359-
.with_stderr("")
2381+
.with_stderr(
2382+
"\
2383+
[UPDATING] `[..]` index
2384+
[UPGRADING] dep ^1.0 -> ^2.0
2385+
[LOCKING] 1 package to latest compatible version
2386+
[ADDING] dep v2.0.0
2387+
",
2388+
)
23602389
.run();
23612390

23622391
// But not the transitive one, because bar is not a workspace member
23632392
p.cargo("update -Zunstable-options --breaking [email protected]")
23642393
.masquerade_as_nightly_cargo(&["update-breaking"])
2365-
.with_stderr("")
2394+
.with_stderr(
2395+
"\
2396+
[UPDATING] `[..]` index
2397+
",
2398+
)
23662399
.run();
23672400

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

0 commit comments

Comments
 (0)