Skip to content

Commit 596455f

Browse files
committed
Generate simple .gitignore on init
1 parent f24eb59 commit 596455f

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/book/mdbook.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,32 @@ impl MDBook {
100100
output!("{:?} created", self.config.get_root());
101101
}
102102

103+
{
104+
let root = self.config.get_root();
105+
let gitignore = root.join(".gitignore");
106+
107+
if !gitignore.exists() {
108+
109+
// Gitignore does not exist, create it
110+
111+
debug!("[*]: {:?} does not exist, trying to create .gitignore", root.join(".gitignore"));
112+
113+
let dest = self.config.get_dest();
114+
// `relative_from` is marked as unstable
115+
// http://doc.rust-lang.org/std/path/struct.PathBuf.html#method.relative_from
116+
let dest = dest.relative_from(root)
117+
.expect("Destination path does not start with root path.");
118+
let dest = dest.to_str()
119+
.expect("No destination path found.");
120+
121+
let mut f = try!(File::create(&root.join(".gitignore")));
122+
123+
debug!("[*]: Writing to .gitignore");
124+
125+
try!(writeln!(f, "{}", dest));
126+
}
127+
}
128+
103129
{
104130
let dest = self.config.get_dest();
105131
let src = self.config.get_src();

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
//!
7070
//! Make sure to take a look at it.
7171
72+
// Used in `MDBook.init()`
73+
#![feature(path_relative_from)]
74+
7275
#[macro_use]
7376
pub mod macros;
7477
pub mod book;

0 commit comments

Comments
 (0)