Skip to content

Commit 947e1ff

Browse files
committed
fix(publish): Downgrade version-exists error to warning on dry-run
This will get cherry-picked to beta Fixes #14721
1 parent ae6b279 commit 947e1ff

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
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

+11-2
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,19 @@ fn duplicate_version() {
152152

153153
p.cargo("publish --dry-run")
154154
.replace_crates_io(registry_dupl.index_url())
155-
.with_status(101)
156155
.with_stderr_data(str![[r#"
157156
[UPDATING] crates.io index
158-
[ERROR] crate [email protected] already exists on 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
159168
160169
"#]])
161170
.run();

0 commit comments

Comments
 (0)