Fix gitignore searching not terminating in some cases; closes #25
This commit is contained in:
parent
c416c6082c
commit
0d85d8275a
30
src/main.rs
30
src/main.rs
|
@ -39,21 +39,27 @@ use notification_filter::NotificationFilter;
|
||||||
use process::{Process, ProcessReaper};
|
use process::{Process, ProcessReaper};
|
||||||
use watcher::{Event, Watcher};
|
use watcher::{Event, Watcher};
|
||||||
|
|
||||||
// Starting at the specified path, search for gitignore files,
|
fn find_gitignore(path: &Path) -> Option<PathBuf> {
|
||||||
// stopping at the first one found.
|
let mut p = path.to_owned();
|
||||||
fn find_gitignore_file(path: &Path) -> Option<PathBuf> {
|
|
||||||
let mut gitignore_path = path.join(".gitignore");
|
|
||||||
if gitignore_path.exists() {
|
|
||||||
return Some(gitignore_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
let p = path.to_owned();
|
loop {
|
||||||
|
let gitignore_path = p.join(".gitignore");
|
||||||
while let Some(p) = p.parent() {
|
|
||||||
gitignore_path = p.join(".gitignore");
|
|
||||||
if gitignore_path.exists() {
|
if gitignore_path.exists() {
|
||||||
return Some(gitignore_path);
|
return Some(gitignore_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop if we see a .git directory
|
||||||
|
if let Ok(metadata) = p.join(".git").metadata() {
|
||||||
|
if metadata.is_dir() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.parent().is_none() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
|
@ -85,7 +91,7 @@ fn main() {
|
||||||
|
|
||||||
let mut gitignore_file = None;
|
let mut gitignore_file = None;
|
||||||
if !args.no_vcs_ignore {
|
if !args.no_vcs_ignore {
|
||||||
if let Some(gitignore_path) = find_gitignore_file(&cwd) {
|
if let Some(gitignore_path) = find_gitignore(&cwd) {
|
||||||
debug!("Found .gitignore file: {:?}", gitignore_path);
|
debug!("Found .gitignore file: {:?}", gitignore_path);
|
||||||
|
|
||||||
gitignore_file = gitignore::parse(&gitignore_path).ok();
|
gitignore_file = gitignore::parse(&gitignore_path).ok();
|
||||||
|
|
Loading…
Reference in New Issue