From 92029f7365e7376b6d94be53ff4fa06043eabbac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 6 Jun 2020 15:16:02 +1200 Subject: [PATCH] Fix faulty .git lookup code --- src/gitignore.rs | 24 +++++++++++------------- src/ignore.rs | 5 ++--- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/gitignore.rs b/src/gitignore.rs index 6bc733cb..5b2f92f1 100644 --- a/src/gitignore.rs +++ b/src/gitignore.rs @@ -1,6 +1,3 @@ -extern crate globset; -extern crate walkdir; - use globset::{GlobBuilder, GlobSet, GlobSetBuilder}; use std::fs; @@ -47,21 +44,22 @@ pub fn load(paths: &[PathBuf]) -> Gitignore { let mut files = vec![]; for path in paths { - let mut p = path.to_owned(); + let mut top_level_git_dir = None; + let mut p = Some(path.clone()); // FIXME: cow + + while let Some(ref current) = p { + debug!("Looking in {:?} for a .git directory", current); - // scan parent directories up to a root .git folder - let top_level_git_dir = loop { // Stop if we see a .git directory - if let Ok(metadata) = p.join(".git").metadata() { + if let Ok(metadata) = current.join(".git").metadata() { if metadata.is_dir() { - break Some(path); + top_level_git_dir = Some(path); + break; } } - if p.parent().is_none() { - break None; - } - }; + p = current.parent().map(|p| p.to_owned()); + } if let Some(root) = top_level_git_dir { // scan in subdirectories @@ -81,7 +79,7 @@ pub fn load(paths: &[PathBuf]) -> Gitignore { } } - p.pop(); + // p.pop(); } Gitignore::new(files) diff --git a/src/ignore.rs b/src/ignore.rs index ea8210e0..7988b025 100644 --- a/src/ignore.rs +++ b/src/ignore.rs @@ -1,6 +1,3 @@ -extern crate globset; -extern crate walkdir; - use globset::{GlobBuilder, GlobSet, GlobSetBuilder}; use std::collections::HashSet; use std::fs; @@ -51,6 +48,8 @@ pub fn load(paths: &[PathBuf]) -> Ignore { let mut p = path.to_owned(); // walk up to root + // FIXME: this makes zero sense and should be removed + // but that would be a breaking change loop { if !checked_dirs.contains(&p) { checked_dirs.insert(p.clone());