Skip to content

Commit 2de4c24

Browse files
committed
fix: update --breaking now understands package@version.
1 parent 3a45d6e commit 2de4c24

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

src/cargo/ops/cargo_update.rs

Lines changed: 15 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>,
@@ -271,7 +276,14 @@ 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+
&& spec
283+
.version()
284+
.map_or(true, |v| dependency.version_req().matches(&v))
285+
})
286+
{
275287
trace!("skipping dependency `{}` not selected for upgrading", name);
276288
return Ok(dependency);
277289
}

tests/testsuite/update.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,11 +2244,29 @@ fn update_breaking_spec_version() {
22442244

22452245
Package::new("incompatible", "2.0.0").publish();
22462246

2247+
p.cargo("update -Zunstable-options --breaking incompatible@foo")
2248+
.masquerade_as_nightly_cargo(&["update-breaking"])
2249+
.with_status(101)
2250+
.with_stderr(
2251+
"\
2252+
[ERROR] expected a version like \"1.32\"
2253+
",
2254+
)
2255+
.run();
2256+
2257+
p.cargo("update -Zunstable-options --breaking [email protected]")
2258+
.masquerade_as_nightly_cargo(&["update-breaking"])
2259+
.with_stderr("")
2260+
.run();
2261+
22472262
p.cargo("update -Zunstable-options --breaking [email protected]")
22482263
.masquerade_as_nightly_cargo(&["update-breaking"])
22492264
.with_stderr(
2250-
// FIXME: This is wrong.
22512265
"\
2266+
[UPDATING] `[..]` index
2267+
[UPGRADING] incompatible ^1.0 -> ^2.0
2268+
[LOCKING] 1 package to latest compatible version
2269+
[UPDATING] incompatible v1.0.0 -> v2.0.0
22522270
",
22532271
)
22542272
.run();
@@ -2259,7 +2277,6 @@ fn update_breaking_spec_version() {
22592277
[UPDATING] `[..]` index
22602278
[LOCKING] 1 package to latest compatible version
22612279
[UPDATING] compatible v1.0.0 -> v1.0.1
2262-
[NOTE] pass `--verbose` to see 1 unchanged dependencies behind latest
22632280
",
22642281
)
22652282
.run();

0 commit comments

Comments
 (0)