mirror of https://github.com/rust-lang/cargo
Switch over to use --registry for publish list.
This commit is contained in:
parent
941d78075e
commit
caf7681fe2
|
@ -43,8 +43,7 @@ pub fn publish(ws: &Workspace, opts: &PublishOpts) -> CargoResult<()> {
|
|||
let pkg = ws.current()?;
|
||||
|
||||
if let &Some(ref allowed_registries) = pkg.publish() {
|
||||
let index = opts.index.clone();
|
||||
if index.is_none() || !allowed_registries.contains(&index.unwrap()) {
|
||||
if opts.registry.is_none() || !allowed_registries.contains(&opts.registry.clone().unwrap()) {
|
||||
bail!("some crates cannot be published.\n\
|
||||
`{}` is marked as unpublishable", pkg.name());
|
||||
}
|
||||
|
|
|
@ -10,10 +10,21 @@ use url::Url;
|
|||
pub fn setup() -> Repository {
|
||||
let config = paths::root().join(".cargo/config");
|
||||
t!(fs::create_dir_all(config.parent().unwrap()));
|
||||
t!(t!(File::create(&config)).write_all(br#"
|
||||
t!(t!(File::create(&config)).write_all(format!(r#"
|
||||
[registry]
|
||||
token = "api-token"
|
||||
|
||||
[registries.alternative]
|
||||
index = "{registry}"
|
||||
"#, registry = registry().to_string()).as_bytes()));
|
||||
|
||||
let credentials = paths::root().join("home/.cargo/credentials");
|
||||
t!(fs::create_dir_all(credentials.parent().unwrap()));
|
||||
t!(t!(File::create(&credentials)).write_all(br#"
|
||||
[alternative]
|
||||
token = "api-token"
|
||||
"#));
|
||||
|
||||
t!(fs::create_dir_all(&upload_path().join("api/v1/crates")));
|
||||
|
||||
repo(®istry_path())
|
||||
|
|
|
@ -7,6 +7,7 @@ use std::io::prelude::*;
|
|||
use std::fs::File;
|
||||
use std::io::SeekFrom;
|
||||
|
||||
use cargotest::ChannelChanger;
|
||||
use cargotest::support::git::repo;
|
||||
use cargotest::support::paths;
|
||||
use cargotest::support::{project, execs, publish};
|
||||
|
@ -502,7 +503,7 @@ See [..]
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn index_not_in_publish_list() {
|
||||
fn registry_not_in_publish_list() {
|
||||
publish::setup();
|
||||
|
||||
let p = project("foo")
|
||||
|
@ -517,10 +518,11 @@ fn index_not_in_publish_list() {
|
|||
"test"
|
||||
]
|
||||
"#)
|
||||
.file("src/main.rs", "fn main() {}");
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
assert_that(p.cargo_process("publish")
|
||||
.arg("--index").arg(publish::registry().to_string()),
|
||||
assert_that(p.cargo("publish").masquerade_as_nightly_cargo()
|
||||
.arg("--registry").arg("alternative").arg("-Zunstable-options"),
|
||||
execs().with_status(101).with_stderr("\
|
||||
[ERROR] some crates cannot be published.
|
||||
`foo` is marked as unpublishable
|
||||
|
@ -541,10 +543,11 @@ fn publish_empty_list() {
|
|||
description = "foo"
|
||||
publish = []
|
||||
"#)
|
||||
.file("src/main.rs", "fn main() {}");
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
assert_that(p.cargo_process("publish")
|
||||
.arg("--index").arg(publish::registry().to_string()),
|
||||
assert_that(p.cargo("publish").masquerade_as_nightly_cargo()
|
||||
.arg("--registry").arg("alternative").arg("-Zunstable-options"),
|
||||
execs().with_status(101).with_stderr("\
|
||||
[ERROR] some crates cannot be published.
|
||||
`foo` is marked as unpublishable
|
||||
|
@ -552,14 +555,13 @@ fn publish_empty_list() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn publish_allowed_index() {
|
||||
fn publish_allowed_registry() {
|
||||
publish::setup();
|
||||
|
||||
let p = project("foo");
|
||||
p.build();
|
||||
let p = project("foo").build();
|
||||
|
||||
repo(&paths::root().join("foo"))
|
||||
.file("Cargo.toml", &format!(r#"
|
||||
let _ = repo(&paths::root().join("foo"))
|
||||
.file("Cargo.toml", r#"
|
||||
[project]
|
||||
name = "foo"
|
||||
version = "0.0.1"
|
||||
|
@ -568,12 +570,37 @@ fn publish_allowed_index() {
|
|||
description = "foo"
|
||||
documentation = "foo"
|
||||
homepage = "foo"
|
||||
publish = ["{}"]
|
||||
"#, publish::registry().to_string()))
|
||||
publish = ["alternative"]
|
||||
"#)
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
assert_that(p.cargo("publish")
|
||||
.arg("--index").arg(publish::registry().to_string()),
|
||||
assert_that(p.cargo("publish").masquerade_as_nightly_cargo()
|
||||
.arg("--registry").arg("alternative").arg("-Zunstable-options"),
|
||||
execs().with_status(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block_publish_no_registry() {
|
||||
publish::setup();
|
||||
|
||||
let p = project("foo")
|
||||
.file("Cargo.toml", r#"
|
||||
[project]
|
||||
name = "foo"
|
||||
version = "0.0.1"
|
||||
authors = []
|
||||
license = "MIT"
|
||||
description = "foo"
|
||||
publish = []
|
||||
"#)
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
assert_that(p.cargo("publish").masquerade_as_nightly_cargo()
|
||||
.arg("--index").arg(publish::registry().to_string()),
|
||||
execs().with_status(101).with_stderr("\
|
||||
[ERROR] some crates cannot be published.
|
||||
`foo` is marked as unpublishable
|
||||
"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue