Skip to content

Commit 92f94a5

Browse files
committed
Auto merge of #14742 - epage:publish, r=ehuss
fix(publish): Downgrade version-exists error to warning on dry-run ### What does this PR try to resolve? Especially for beta, this was the most conservative, minimal change. Fixes #14721 ### How should we test and review this PR? ### Additional information This will get cherry-picked to beta
2 parents f95eeb6 + 947e1ff commit 92f94a5

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

src/cargo/ops/registry/publish.rs

+21-7
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
133133
.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)?;
134134

135135
for (pkg, _) in &pkgs {
136-
verify_unpublished(pkg, &mut source, &source_ids)?;
136+
verify_unpublished(pkg, &mut source, &source_ids, opts.dry_run, opts.gctx)?;
137137
verify_dependencies(pkg, &registry, source_ids.original)?;
138138
}
139139
}
@@ -368,6 +368,8 @@ fn verify_unpublished(
368368
pkg: &Package,
369369
source: &mut RegistrySource<'_>,
370370
source_ids: &RegistrySourceIds,
371+
dry_run: bool,
372+
gctx: &GlobalContext,
371373
) -> CargoResult<()> {
372374
let query = Dependency::parse(
373375
pkg.name(),
@@ -383,12 +385,24 @@ fn verify_unpublished(
383385
}
384386
};
385387
if !duplicate_query.is_empty() {
386-
bail!(
387-
"crate {}@{} already exists on {}",
388-
pkg.name(),
389-
pkg.version(),
390-
source.describe()
391-
);
388+
// Move the registry error earlier in the publish process.
389+
// Since dry-run wouldn't talk to the registry to get the error, we downgrade it to a
390+
// warning.
391+
if dry_run {
392+
gctx.shell().warn(format!(
393+
"crate {}@{} already exists on {}",
394+
pkg.name(),
395+
pkg.version(),
396+
source.describe()
397+
))?;
398+
} else {
399+
bail!(
400+
"crate {}@{} already exists on {}",
401+
pkg.name(),
402+
pkg.version(),
403+
source.describe()
404+
);
405+
}
392406
}
393407

394408
Ok(())

tests/testsuite/publish.rs

+19
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,25 @@ fn duplicate_version() {
150150
.file("src/main.rs", "fn main() {}")
151151
.build();
152152

153+
p.cargo("publish --dry-run")
154+
.replace_crates_io(registry_dupl.index_url())
155+
.with_stderr_data(str![[r#"
156+
[UPDATING] crates.io index
157+
[WARNING] crate [email protected] already exists on crates.io index
158+
[WARNING] manifest has no documentation, homepage or repository.
159+
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
160+
[PACKAGING] foo v0.0.1 ([ROOT]/foo)
161+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
162+
[VERIFYING] foo v0.0.1 ([ROOT]/foo)
163+
[WARNING] no edition set: defaulting to the 2015 edition while the latest is 2021
164+
[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1)
165+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
166+
[UPLOADING] foo v0.0.1 ([ROOT]/foo)
167+
[WARNING] aborting upload due to dry run
168+
169+
"#]])
170+
.run();
171+
153172
p.cargo("publish")
154173
.replace_crates_io(registry_dupl.index_url())
155174
.with_status(101)

0 commit comments

Comments
 (0)