File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,32 @@ impl MDBook {
100
100
output ! ( "{:?} created" , self . config. get_root( ) ) ;
101
101
}
102
102
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
+
103
129
{
104
130
let dest = self . config . get_dest ( ) ;
105
131
let src = self . config . get_src ( ) ;
Original file line number Diff line number Diff line change 69
69
//!
70
70
//! Make sure to take a look at it.
71
71
72
+ // Used in `MDBook.init()`
73
+ #![ feature( path_relative_from) ]
74
+
72
75
#[ macro_use]
73
76
pub mod macros;
74
77
pub mod book;
You can’t perform that action at this time.
0 commit comments