Skip to content

Commit 094ef50

Browse files
committed
fix(package): Skip registry check if its not needed
I believe this brings makes it so `cargo package -Zpackage-workspace` no longer has a behavior change compared to `cargo package`.
1 parent 778f351 commit 094ef50

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/cargo/ops/cargo_package/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,13 @@ fn do_package<'a>(
240240
let just_pkgs: Vec<_> = pkgs.iter().map(|p| p.0).collect();
241241

242242
let mut local_reg = if ws.gctx().cli_unstable().package_workspace {
243-
// The publish registry doesn't matter unless there are local dependencies,
243+
// The publish registry doesn't matter unless there are local dependencies that will be
244+
// resolved,
244245
// so only try to get one if we need it. If they explicitly passed a
245246
// registry on the CLI, we check it no matter what.
246-
let sid = if deps.has_dependencies() || opts.reg_or_index.is_some() {
247+
let sid = if (deps.has_dependencies() && (opts.include_lockfile || opts.verify))
248+
|| opts.reg_or_index.is_some()
249+
{
247250
let sid = get_registry(ws.gctx(), &just_pkgs, opts.reg_or_index.clone())?;
248251
debug!("packaging for registry {}", sid);
249252
Some(sid)

tests/testsuite/package.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7084,9 +7084,11 @@ fn registry_not_inferred_because_of_conflict_nightly() {
70847084

70857085
p.cargo("package --exclude-lockfile --no-verify -Zpackage-workspace")
70867086
.masquerade_as_nightly_cargo(&["package-workspace"])
7087-
.with_status(101)
70887087
.with_stderr_data(str![[r#"
7089-
[ERROR] conflicts between `package.publish` fields in the selected packages
7088+
[PACKAGING] dep v0.1.0 ([ROOT]/foo/dep)
7089+
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
7090+
[PACKAGING] main v0.0.1 ([ROOT]/foo/main)
7091+
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
70907092
70917093
"#]])
70927094
.run();
@@ -7401,9 +7403,11 @@ fn registry_not_inferred_because_of_multiple_options_nightly() {
74017403

74027404
p.cargo("package --exclude-lockfile --no-verify -Zpackage-workspace")
74037405
.masquerade_as_nightly_cargo(&["package-workspace"])
7404-
.with_status(101)
74057406
.with_stderr_data(str![[r#"
7406-
[ERROR] --registry is required to disambiguate between "alternative" or "alternative2" registries
7407+
[PACKAGING] dep v0.1.0 ([ROOT]/foo/dep)
7408+
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
7409+
[PACKAGING] main v0.0.1 ([ROOT]/foo/main)
7410+
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
74077411
74087412
"#]])
74097413
.run();
@@ -7631,9 +7635,11 @@ fn registry_not_inferred_because_of_mismatch_nightly() {
76317635

76327636
p.cargo("package --exclude-lockfile --no-verify -Zpackage-workspace")
76337637
.masquerade_as_nightly_cargo(&["package-workspace"])
7634-
.with_status(101)
76357638
.with_stderr_data(str![[r#"
7636-
[ERROR] --registry is required because not all `package.publish` settings agree
7639+
[PACKAGING] dep v0.1.0 ([ROOT]/foo/dep)
7640+
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
7641+
[PACKAGING] main v0.0.1 ([ROOT]/foo/main)
7642+
[PACKAGED] 3 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
76377643
76387644
"#]])
76397645
.run();

0 commit comments

Comments
 (0)