Merge pull request #189 from mwu-tow/git-root-lookup

Fix lookup of the root git directory
This commit is contained in:
Félix Saparelli 2021-04-13 02:10:32 +12:00 committed by GitHub
commit 3c26e3987c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 3 deletions

View File

@ -46,7 +46,7 @@ pub fn load(paths: &[PathBuf]) -> Gitignore {
for path in paths { for path in paths {
let mut top_level_git_dir = None; let mut top_level_git_dir = None;
let mut p = Some(path.clone()); // FIXME: cow let mut p = Some(path.as_path());
while let Some(ref current) = p { while let Some(ref current) = p {
debug!("Looking in {:?} for a .git directory", current); debug!("Looking in {:?} for a .git directory", current);
@ -54,15 +54,16 @@ pub fn load(paths: &[PathBuf]) -> Gitignore {
// Stop if we see a .git directory // Stop if we see a .git directory
if let Ok(metadata) = current.join(".git").metadata() { if let Ok(metadata) = current.join(".git").metadata() {
if metadata.is_dir() { if metadata.is_dir() {
top_level_git_dir = Some(path); top_level_git_dir = Some(*current);
break; break;
} }
} }
p = current.parent().map(ToOwned::to_owned); p = current.parent();
} }
if let Some(root) = top_level_git_dir { if let Some(root) = top_level_git_dir {
debug!("Found the top level git directory: {:?}", root);
// scan in subdirectories // scan in subdirectories
for entry in WalkDir::new(root) for entry in WalkDir::new(root)
.into_iter() .into_iter()