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
4 changes: 3 additions & 1 deletion src/bin/cargo/commands/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
let spec = PackageIdSpec::parse(package)
.with_context(|| format!("invalid package ID specification: `{package}`"))?;

// Check if --registry or --index was explicitly provided
let explicit_registry = args._contains("registry") || args._contains("index");
let reg_or_index = args.registry_or_index(gctx)?;
info(&spec, gctx, reg_or_index)?;
info(&spec, gctx, reg_or_index, explicit_registry)?;
Ok(())
}
12 changes: 11 additions & 1 deletion src/cargo/ops/registry/info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub fn info(
spec: &PackageIdSpec,
gctx: &GlobalContext,
reg_or_index: Option<RegistryOrIndex>,
explicit_registry: bool,
) -> CargoResult<()> {
let source_config = SourceConfigMap::new(gctx)?;
let mut registry = PackageRegistry::new_with_source_config(gctx, source_config)?;
Expand All @@ -39,8 +40,17 @@ pub fn info(
.and_then(|path| ws.members().find(|p| p.manifest_path() == path))
});
let (mut package_id, is_member) = find_pkgid_in_ws(nearest_package, ws.as_ref(), spec);

// If a local package exists and no explicit registry/index was provided,
// prefer the local package over the default registry
let reg_or_index_to_use = if package_id.is_some() && !explicit_registry {
None
} else {
reg_or_index.as_ref()
};

let (use_package_source_id, source_ids) =
get_source_id_with_package_id(gctx, package_id, reg_or_index.as_ref())?;
get_source_id_with_package_id(gctx, package_id, reg_or_index_to_use)?;
// If we don't use the package's source, we need to query the package ID from the specified registry.
if !use_package_source_id {
package_id = None;
Expand Down
2 changes: 2 additions & 0 deletions tests/testsuite/cargo_info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ mod specify_version_within_ws_and_conflict_with_lockfile;
mod specify_version_within_ws_and_match_with_lockfile;
mod transitive_dependency_within_ws;
mod verbose;
mod with_default_registry_configured;
mod with_default_registry_configured_and_specified;
mod with_frozen_outside_ws;
mod with_frozen_within_ws;
mod with_locked_outside_ws;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[registry]
default = "crates-io"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[workspace]
members = ["crates/*"]

[package]
name = "foo"
version = "0.0.0"

[dependencies]
crate1 = { path = "./crates/crate1" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "crate1"
version = "0.0.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

24 changes: 24 additions & 0 deletions tests/testsuite/cargo_info/with_default_registry_configured/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use crate::prelude::*;
use cargo_test_support::{Project, compare::assert_ui, current_dir, file};

use super::init_registry_without_token;

#[cargo_test]
fn case() {
init_registry_without_token();

let project = Project::from_template(current_dir!().join("in"));
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo_ui()
.arg("info")
.arg_line("--verbose foo")
.current_dir(cwd)
.assert()
.success()
.stdout_eq(file!["stdout.term.svg"])
.stderr_eq("");

assert_ui().subset_matches(current_dir!().join("out"), &project_root);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[registry]
default = "crates-io"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[workspace]
members = ["crates/*"]

[package]
name = "foo"
version = "0.0.0"

[dependencies]
crate1 = { path = "./crates/crate1" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "crate1"
version = "0.0.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[registry]
default = "crates-io"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[workspace]
members = ["crates/*"]

[package]
name = "foo"
version = "0.0.0"

[dependencies]
crate1 = { path = "./crates/crate1" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "crate1"
version = "0.0.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use crate::prelude::*;
use cargo_test_support::{Project, compare::assert_ui, current_dir, file};

use super::init_registry_without_token;

#[cargo_test]
fn case() {
init_registry_without_token();

for ver in ["0.1.1+foo", "0.2.0+foo"] {
cargo_test_support::registry::Package::new("foo", ver).publish();
}

let project = Project::from_template(current_dir!().join("in"));
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo_ui()
.arg("info")
.arg_line("--verbose foo")
.arg("--registry=dummy-registry")
.current_dir(cwd)
.assert()
.success()
.stdout_eq(file!["stdout.term.svg"])
.stderr_eq(file!["stderr.term.svg"]);

assert_ui().subset_matches(current_dir!().join("out"), &project_root);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[registry]
default = "crates-io"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[workspace]
members = ["crates/*"]

[package]
name = "foo"
version = "0.0.0"

[dependencies]
crate1 = { path = "./crates/crate1" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "crate1"
version = "0.0.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.