diff --git a/src/book/mdbook.rs b/src/book/mdbook.rs index 521606d3..a8ffc437 100644 --- a/src/book/mdbook.rs +++ b/src/book/mdbook.rs @@ -100,6 +100,32 @@ impl MDBook { output!("{:?} created", self.config.get_root()); } + { + let root = self.config.get_root(); + let gitignore = root.join(".gitignore"); + + if !gitignore.exists() { + + // Gitignore does not exist, create it + + debug!("[*]: {:?} does not exist, trying to create .gitignore", root.join(".gitignore")); + + let dest = self.config.get_dest(); + // `relative_from` is marked as unstable + // http://doc.rust-lang.org/std/path/struct.PathBuf.html#method.relative_from + let dest = dest.relative_from(root) + .expect("Destination path does not start with root path."); + let dest = dest.to_str() + .expect("No destination path found."); + + let mut f = try!(File::create(&root.join(".gitignore"))); + + debug!("[*]: Writing to .gitignore"); + + try!(writeln!(f, "{}", dest)); + } + } + { let dest = self.config.get_dest(); let src = self.config.get_src(); diff --git a/src/lib.rs b/src/lib.rs index edc2fe9e..eb45041f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,6 +69,9 @@ //! //! Make sure to take a look at it. +// Used in `MDBook.init()` +#![feature(path_relative_from)] + #[macro_use] pub mod macros; pub mod book;