Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/cargo/core/source/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,17 @@ impl SourceId {
}
}

/// Returns `true` if this source is a "remote" registry.
///
/// "remote" may also mean a file URL to a git index, so it is not
/// necessarily "remote". This just means it is not `local-registry`.
pub fn is_remote_registry(self) -> bool {
match self.inner.kind {
Kind::Registry => true,
_ => false,
}
}

/// Returns `true` if this source from a Git repository.
pub fn is_git(self) -> bool {
match self.inner.kind {
Expand Down
7 changes: 7 additions & 0 deletions src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,13 @@ fn registry(
} = registry_configuration(config, registry.clone())?;
let token = token.or(token_config);
let sid = get_source_id(config, index_config.or(index), registry)?;
if !sid.is_remote_registry() {
bail!(
"{} does not support API commands.\n\
Check for a source-replacement in .cargo/config.",
sid
);
}
let api_host = {
let _lock = config.acquire_package_cache_lock()?;
let mut src = RegistrySource::remote(sid, &HashSet::new(), config);
Expand Down
48 changes: 48 additions & 0 deletions tests/testsuite/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,3 +1022,51 @@ fn publish_checks_for_token_before_verify() {
.with_stderr_contains("[VERIFYING] foo v0.0.1 ([CWD])")
.run();
}

#[cargo_test]
fn publish_with_bad_source() {
let p = project()
.file(
".cargo/config",
r#"
[source.crates-io]
replace-with = 'local-registry'

[source.local-registry]
local-registry = 'registry'
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("publish")
.with_status(101)
.with_stderr(
"\
[ERROR] registry `[..]/foo/registry` does not support API commands.
Check for a source-replacement in .cargo/config.
",
)
.run();

p.change_file(
".cargo/config",
r#"
[source.crates-io]
replace-with = "vendored-sources"

[source.vendored-sources]
directory = "vendor"
"#,
);

p.cargo("publish")
.with_status(101)
.with_stderr(
"\
[ERROR] dir [..]/foo/vendor does not support API commands.
Check for a source-replacement in .cargo/config.
",
)
.run();
}