diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs index de93a1cbce9..4201e35d2ce 100644 --- a/src/bin/cargo/commands/install.rs +++ b/src/bin/cargo/commands/install.rs @@ -78,7 +78,11 @@ continuous integration systems.", pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { let registry = args.registry(config)?; - config.reload_rooted_at_cargo_home()?; + if let Some(path) = args.value_of_path("path", config) { + config.reload_rooted_at(path)?; + } else { + config.reload_rooted_at(config.home().clone().into_path_unlocked())?; + } let workspace = args.workspace(config).ok(); let mut compile_opts = args.compile_options(config, CompileMode::Build, workspace.as_ref())?; diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index 3f96618c7ac..0459f0beb79 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -285,9 +285,8 @@ impl Config { } } - pub fn reload_rooted_at_cargo_home(&mut self) -> CargoResult<()> { - let home = self.home_path.clone().into_path_unlocked(); - let values = self.load_values_from(&home)?; + pub fn reload_rooted_at>(&mut self, path: P) -> CargoResult<()> { + let values = self.load_values_from(path.as_ref())?; self.values.replace(values); Ok(()) } diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index 05a33a0732f..d870cc185cd 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -1358,3 +1358,21 @@ fn install_global_cargo_config() { .with_stderr_contains("[..]--target nonexistent[..]") .run(); } + +#[test] +fn install_path_config() { + project() + .file( + ".cargo/config", + r#" + [build] + target = 'nonexistent' + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + cargo_process("install --path foo") + .with_status(101) + .with_stderr_contains("[..]--target nonexistent[..]") + .run(); +}