Skip to content

Commit 94f73a3

Browse files
authored
fix(package): Don't verify registry for --list (#16341)
### What does this PR try to resolve? Since `--list` is doing nothing with registries, imo, it shouldn't error if `CARGO_REGISTRY_DEFAULT` is not in `package.publish`. This also affects `--registry` and `--index` but that should be fine. Fixes crate-ci/cargo-release#921 ### How to test and review this PR?
2 parents 4d0eff0 + 5e2cf5d commit 94f73a3

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

src/cargo/ops/cargo_package/mod.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -268,23 +268,22 @@ fn do_package<'a>(
268268
let deps = local_deps(pkgs.iter().map(|(p, f)| ((*p).clone(), f.clone())));
269269
let just_pkgs: Vec<_> = pkgs.iter().map(|p| p.0).collect();
270270

271-
let mut local_reg = {
272-
// The publish registry doesn't matter unless there are local dependencies that will be
273-
// resolved,
274-
// so only try to get one if we need it. If they explicitly passed a
275-
// registry on the CLI, we check it no matter what.
276-
let sid = if (deps.has_dependencies() && (opts.include_lockfile || opts.verify))
277-
|| opts.reg_or_index.is_some()
278-
{
279-
let sid = get_registry(ws.gctx(), &just_pkgs, opts.reg_or_index.clone())?;
280-
debug!("packaging for registry {}", sid);
281-
Some(sid)
282-
} else {
283-
None
284-
};
271+
// The publish registry doesn't matter unless there are local dependencies that will be
272+
// resolved,
273+
// so only try to get one if we need it.
274+
//
275+
// If they explicitly passed a registry on the CLI, we check it no matter what to verify
276+
// `package.publish`.
277+
let needs_local_reg = deps.has_dependencies() && (opts.include_lockfile || opts.verify);
278+
let verify_registry_allow_list = opts.reg_or_index.is_some();
279+
let mut local_reg = if !opts.list && (needs_local_reg || verify_registry_allow_list) {
280+
let sid = get_registry(ws.gctx(), &just_pkgs, opts.reg_or_index.clone())?;
281+
debug!("packaging for registry {}", sid);
285282
let reg_dir = ws.build_dir().join("package").join("tmp-registry");
286-
sid.map(|sid| TmpRegistry::new(ws.gctx(), reg_dir, sid))
287-
.transpose()?
283+
let local_reg = TmpRegistry::new(ws.gctx(), reg_dir, sid)?;
284+
Some(local_reg)
285+
} else {
286+
None
288287
};
289288

290289
// Packages need to be created in dependency order, because dependencies must

tests/testsuite/package.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6791,6 +6791,16 @@ fn registry_not_in_publish_list() {
67916791
[ERROR] `foo` cannot be packaged.
67926792
The registry `alternative` is not listed in the `package.publish` value in Cargo.toml.
67936793
6794+
"#]])
6795+
.run();
6796+
6797+
p.cargo("package --registry alternative --list")
6798+
.with_stdout_data(str![[r#"
6799+
Cargo.lock
6800+
Cargo.toml
6801+
Cargo.toml.orig
6802+
src/main.rs
6803+
67946804
"#]])
67956805
.run();
67966806
}

0 commit comments

Comments
 (0)