mirror of
https://github.com/watchexec/watchexec.git
synced 2024-09-28 22:21:33 +02:00
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 watcher::{Event, Watcher};
|
||||
|
||||
// Starting at the specified path, search for gitignore files,
|
||||
// stopping at the first one found.
|
||||
fn find_gitignore_file(path: &Path) -> Option<PathBuf> {
|
||||
let mut gitignore_path = path.join(".gitignore");
|
||||
if gitignore_path.exists() {
|
||||
return Some(gitignore_path);
|
||||
}
|
||||
fn find_gitignore(path: &Path) -> Option<PathBuf> {
|
||||
let mut p = path.to_owned();
|
||||
|
||||
let p = path.to_owned();
|
||||
|
||||
while let Some(p) = p.parent() {
|
||||
gitignore_path = p.join(".gitignore");
|
||||
loop {
|
||||
let gitignore_path = p.join(".gitignore");
|
||||
if gitignore_path.exists() {
|
||||
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
|
||||
@ -85,7 +91,7 @@ fn main() {
|
||||
|
||||
let mut gitignore_file = None;
|
||||
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);
|
||||
|
||||
gitignore_file = gitignore::parse(&gitignore_path).ok();
|
||||
|
Loading…
Reference in New Issue
Block a user