Skip to content

Commit d3167ed

Browse files
committed
Emit shell warning if running outside of all roots
To help make it clear why Cargo may not load all ancestor configs or find workspace manifests in ancestor directories, Cargo emits a warning: ``` warning: Cargo is running outside of any root directory, limiting loading of ancestor configs and manifest ```
1 parent 92ca3bf commit d3167ed

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/bin/cargo/cli.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::collections::HashMap;
99
use std::ffi::OsStr;
1010
use std::ffi::OsString;
1111
use std::fmt::Write;
12+
use tracing::warn;
1213

1314
use super::commands;
1415
use super::list_commands;
@@ -132,6 +133,10 @@ pub fn main(gctx: &mut GlobalContext) -> CliResult {
132133
// Reload now that we have established the cwd and root
133134
gctx.reload_cwd()?;
134135

136+
if gctx.find_nearest_root(gctx.cwd())?.is_none() {
137+
gctx.shell().warn("Cargo is running outside of any root directory, limiting loading of ancestor configs and manifest")?;
138+
}
139+
135140
let (expanded_args, global_args) = expand_aliases(gctx, args, vec![])?;
136141

137142
let is_verbose = expanded_args.verbose() > 0;

src/cargo/util/context/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ impl GlobalContext {
639639
}
640640
}
641641

642-
fn find_nearest_root<P: AsRef<Path>>(
642+
pub fn find_nearest_root<P: AsRef<Path>>(
643643
&self,
644644
start: P,
645645
) -> CargoResult<Option<(PathBuf, PathBuf)>> {

0 commit comments

Comments
 (0)