mdBook icon indicating copy to clipboard operation
mdBook copied to clipboard

gitignore in parent hierarchy of book

Open quackenbush opened this issue 3 years ago • 0 comments

I ran into a hang issue when running 'mdbook serve', where after touching any .md source file, the mdbook process will spin 100% CPU.

I think I have diagnosed it to a blank .gitignore file located a few parent directories above the book source tree (and no .gitignore file within the book tree).

The mdbook docs say this:

Note: Only the .gitignore from the book root directory is used. 
Global $HOME/.gitignore or .gitignore files in parent directories are not used.

However, I believe this code in watch.rs checks all parent hierarchies of the book for a .gitignore file (ie the ancestors() call)

fn find_gitignore(book_root: &Path) -> Option<PathBuf> {
    book_root
        .ancestors()
        .map(|p| p.join(".gitignore"))
        .find(|p| p.exists())
}

I'm not a rustacean, but is something like this a correct fix?

fn find_gitignore(book_root: &Path) -> Option<PathBuf> {
   let gitignore = book_root.join(".gitignore");
   gitignore.exists().then_some(gitignore)
}

quackenbush avatar Dec 31 '22 01:12 quackenbush