From 25990711103817a71d7c570d015ddc40a0a12bd7 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 6 Mar 2020 10:15:14 -0800 Subject: [PATCH] Don't allow both --index and --registry to be specified at the same time. Otherwise --index was being silently ignored. --- src/cargo/ops/registry.rs | 4 ++++ tests/testsuite/alt_registry.rs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index fe9b52577..68d605a43 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -369,6 +369,10 @@ fn registry( force_update: bool, validate_token: bool, ) -> CargoResult<(Registry, SourceId)> { + if index.is_some() && registry.is_some() { + // Otherwise we would silently ignore one or the other. + bail!("both `--index` and `--registry` should not be set at the same time"); + } // Parse all configuration options let RegistryConfig { token: token_config, diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs index cf03ab455..3c76d7d6a 100644 --- a/tests/testsuite/alt_registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -1247,3 +1247,19 @@ Caused by: .with_status(101) .run(); } + +#[cargo_test] +fn both_index_and_registry() { + let p = project().file("src/lib.rs", "").build(); + for cmd in &["publish", "owner", "search", "yank --vers 1.0.0"] { + p.cargo(cmd) + .arg("--registry=foo") + .arg("--index=foo") + .with_status(101) + .with_stderr( + "[ERROR] both `--index` and `--registry` \ + should not be set at the same time", + ) + .run(); + } +}