Skip to content

Commit cb37d33

Browse files
committed
Code review markups.
1 parent 4a302ac commit cb37d33

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/cargo/ops/registry.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ pub fn publish(ws: &Workspace, opts: &PublishOpts) -> CargoResult<()> {
4343
let pkg = ws.current()?;
4444

4545
if let &Some(ref allowed_registries) = pkg.publish() {
46-
if opts.registry.is_none() || !allowed_registries.contains(&opts.registry.clone().unwrap()) {
46+
if !match opts.registry {
47+
Some(ref registry) => allowed_registries.contains(registry),
48+
None => false,
49+
} {
4750
bail!("some crates cannot be published.\n\
4851
`{}` is marked as unpublishable", pkg.name());
4952
}

tests/alt-registry.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn depend_on_alt_registry() {
7373
}
7474

7575
#[test]
76-
fn depend_on_alt_registry_depends_on_same_registry() {
76+
fn depend_on_alt_registry_depends_on_same_registry_no_index() {
7777
let p = project("foo")
7878
.file("Cargo.toml", r#"
7979
cargo-features = ["alternative-registries"]
@@ -107,6 +107,41 @@ fn depend_on_alt_registry_depends_on_same_registry() {
107107
reg = registry::alt_registry())));
108108
}
109109

110+
#[test]
111+
fn depend_on_alt_registry_depends_on_same_registry() {
112+
let p = project("foo")
113+
.file("Cargo.toml", r#"
114+
cargo-features = ["alternative-registries"]
115+
116+
[project]
117+
name = "foo"
118+
version = "0.0.1"
119+
authors = []
120+
121+
[dependencies.bar]
122+
version = "0.0.1"
123+
registry = "alternative"
124+
"#)
125+
.file("src/main.rs", "fn main() {}")
126+
.build();
127+
128+
Package::new("baz", "0.0.1").alternative(true).publish();
129+
Package::new("bar", "0.0.1").registry_dep("baz", "0.0.1", registry::alt_registry().as_str()).alternative(true).publish();
130+
131+
assert_that(p.cargo("build").masquerade_as_nightly_cargo(),
132+
execs().with_status(0).with_stderr(&format!("\
133+
[UPDATING] registry `{reg}`
134+
[DOWNLOADING] [..] v0.0.1 (registry `file://[..]`)
135+
[DOWNLOADING] [..] v0.0.1 (registry `file://[..]`)
136+
[COMPILING] baz v0.0.1 (registry `file://[..]`)
137+
[COMPILING] bar v0.0.1 (registry `file://[..]`)
138+
[COMPILING] foo v0.0.1 ({dir})
139+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
140+
",
141+
dir = p.url(),
142+
reg = registry::alt_registry())));
143+
}
144+
110145
#[test]
111146
fn depend_on_alt_registry_depends_on_crates_io() {
112147
let p = project("foo")

0 commit comments

Comments
 (0)