Skip to content

Commit 090dcfe

Browse files
committed
fix(publish): better message when nothing to publish
This doesn't need to be an hard error because missing publish for the entire worspace should be a fairly visible. However, this is open for future to configure via Cargo lint system.
1 parent 4f7494c commit 090dcfe

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/cargo/ops/registry/publish.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,22 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
117117
);
118118
}
119119

120+
if pkgs.is_empty() {
121+
if allow_unpublishable {
122+
let n = unpublishable.len();
123+
let plural = if n == 1 { "" } else { "s" };
124+
ws.gctx().shell().warn(format_args!(
125+
"nothing to publish, but found {n} unpublishable package{plural}"
126+
))?;
127+
ws.gctx().shell().note(format_args!(
128+
"to publish packages, set `package.publish` to `true` or a non-empty list"
129+
))?;
130+
return Ok(());
131+
} else {
132+
unreachable!("must have at least one publishable package");
133+
}
134+
}
135+
120136
let just_pkgs: Vec<_> = pkgs.iter().map(|p| p.0).collect();
121137
let reg_or_index = match opts.reg_or_index.clone() {
122138
Some(r) => {

tests/testsuite/publish.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4353,7 +4353,8 @@ fn all_unpublishable_packages() {
43534353
.masquerade_as_nightly_cargo(&["package-workspace"])
43544354
.replace_crates_io(registry.index_url())
43554355
.with_stderr_data(str![[r#"
4356-
[UPDATING] crates.io index
4356+
[WARNING] nothing to publish, but found 2 unpublishable packages
4357+
[NOTE] to publish packages, set `package.publish` to `true` or a non-empty list
43574358
43584359
"#]])
43594360
.run();

0 commit comments

Comments
 (0)