Skip to content

Commit 2599071

Browse files
committed
Don't allow both --index and --registry to be specified at the same time.
Otherwise --index was being silently ignored.
1 parent 9d00f9f commit 2599071

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/cargo/ops/registry.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ fn registry(
369369
force_update: bool,
370370
validate_token: bool,
371371
) -> CargoResult<(Registry, SourceId)> {
372+
if index.is_some() && registry.is_some() {
373+
// Otherwise we would silently ignore one or the other.
374+
bail!("both `--index` and `--registry` should not be set at the same time");
375+
}
372376
// Parse all configuration options
373377
let RegistryConfig {
374378
token: token_config,

tests/testsuite/alt_registry.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,3 +1247,19 @@ Caused by:
12471247
.with_status(101)
12481248
.run();
12491249
}
1250+
1251+
#[cargo_test]
1252+
fn both_index_and_registry() {
1253+
let p = project().file("src/lib.rs", "").build();
1254+
for cmd in &["publish", "owner", "search", "yank --vers 1.0.0"] {
1255+
p.cargo(cmd)
1256+
.arg("--registry=foo")
1257+
.arg("--index=foo")
1258+
.with_status(101)
1259+
.with_stderr(
1260+
"[ERROR] both `--index` and `--registry` \
1261+
should not be set at the same time",
1262+
)
1263+
.run();
1264+
}
1265+
}

0 commit comments

Comments
 (0)