Generate simple .gitignore on init
This commit is contained in:
parent
f24eb59753
commit
596455f28c
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue