@@ -166,22 +166,25 @@ impl MDBook {
166
166
if !gitignore. exists ( ) {
167
167
// Gitignore does not exist, create it
168
168
169
+ // Because of `src/book/mdbook.rs#L37-L39`, `dest` will always start with `root`. If it
170
+ // is not, `strip_prefix` will return an Error.
171
+ if !self . get_dest ( ) . starts_with ( self . get_root ( ) ) {
172
+ return ;
173
+ }
174
+
175
+ let relative = self . get_dest ( ) . strip_prefix ( self . get_root ( ) )
176
+ . expect ( "Destination is not relative to root." ) ;
177
+ let relative = relative. to_str ( )
178
+ . expect ( "Path could not be yielded into a string slice." ) ;
179
+
169
180
debug ! ( "[*]: {:?} does not exist, trying to create .gitignore" , gitignore) ;
170
181
171
182
let mut f = File :: create ( & gitignore)
172
183
. expect ( "Could not create file." ) ;
173
184
174
185
debug ! ( "[*]: Writing to .gitignore" ) ;
175
186
176
- writeln ! ( f, "# Ignore everything within this folder" )
177
- . expect ( "Could not write to file." ) ;
178
- writeln ! ( f, "*" )
179
- . expect ( "Could not write to file." ) ;
180
- writeln ! ( f, "" )
181
- . expect ( "Could not write to file." ) ;
182
- writeln ! ( f, "# Except this file" )
183
- . expect ( "Could not write to file." ) ;
184
- writeln ! ( f, "!.gitignore" )
187
+ writeln ! ( f, "{}" , relative)
185
188
. expect ( "Could not write to file." ) ;
186
189
}
187
190
}
@@ -206,7 +209,7 @@ impl MDBook {
206
209
207
210
208
211
pub fn get_gitignore ( & self ) -> PathBuf {
209
- self . config . get_dest ( ) . join ( ".gitignore" )
212
+ self . config . get_root ( ) . join ( ".gitignore" )
210
213
}
211
214
212
215
pub fn copy_theme ( & self ) -> Result < ( ) , Box < Error > > {
0 commit comments