Ignore homedir if discovered as origin unless explicitly requested
Fixes #276
This commit is contained in:
parent
98348be8b5
commit
036d9a27e8
|
@ -2623,6 +2623,7 @@ dependencies = [
|
|||
"assert_cmd",
|
||||
"clap",
|
||||
"console-subscriber",
|
||||
"dirs 4.0.0",
|
||||
"dunce",
|
||||
"embed-resource",
|
||||
"futures",
|
||||
|
|
|
@ -22,6 +22,7 @@ path = "src/main.rs"
|
|||
|
||||
[dependencies]
|
||||
console-subscriber = { version = "0.1.0", optional = true }
|
||||
dirs = "4.0.0"
|
||||
dunce = "1.0.2"
|
||||
futures = "0.3.17"
|
||||
miette = { version = "3.2.0", features = ["fancy"] }
|
||||
|
|
|
@ -20,11 +20,23 @@ pub async fn dirs(args: &ArgMatches<'static>) -> Result<(PathBuf, PathBuf)> {
|
|||
.into_diagnostic()?;
|
||||
debug!(?curdir, "current directory");
|
||||
|
||||
let homedir = dirs::home_dir()
|
||||
.map(canonicalize)
|
||||
.transpose()
|
||||
.into_diagnostic()?;
|
||||
debug!(?homedir, "home directory");
|
||||
|
||||
let mut paths = HashSet::new();
|
||||
for path in args.values_of("paths").unwrap_or_default() {
|
||||
paths.insert(canonicalize(path).into_diagnostic()?);
|
||||
}
|
||||
|
||||
let homedir_requested = homedir.as_ref().map_or(false, |home| paths.contains(home));
|
||||
debug!(
|
||||
?homedir_requested,
|
||||
"resolved whether the homedir is explicitly requested"
|
||||
);
|
||||
|
||||
if paths.is_empty() {
|
||||
debug!("no paths, using current directory");
|
||||
paths.insert(curdir.clone());
|
||||
|
@ -37,6 +49,14 @@ pub async fn dirs(args: &ArgMatches<'static>) -> Result<(PathBuf, PathBuf)> {
|
|||
origins.extend(project::origins(&path).await);
|
||||
}
|
||||
|
||||
match (homedir, homedir_requested) {
|
||||
(Some(ref dir), false) if origins.contains(dir) => {
|
||||
debug!("removing homedir from origins");
|
||||
origins.remove(dir);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if origins.is_empty() {
|
||||
debug!("no origins, using current directory");
|
||||
origins.insert(curdir.clone());
|
||||
|
|
Loading…
Reference in New Issue