Generate simple .gitignore on init

This commit is contained in:
vrinek 2016-02-23 14:03:45 +00:00
parent f24eb59753
commit 596455f28c
2 changed files with 29 additions and 0 deletions

View File

@ -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();

View File

@ -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;