mirror of
https://github.com/watchexec/watchexec.git
synced 2024-11-16 09:08:37 +01:00
Fix faulty .git lookup code
This commit is contained in:
parent
80bbea7d21
commit
92029f7365
2 changed files with 13 additions and 16 deletions
|
@ -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)
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue