Skip to content

Move .gitignore directly under the root folder #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bin/mdbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn init(args: &ArgMatches) -> Result<(), Box<Error>> {

}

// Because of `src/book/mdbook.rs#L37-L39`, the following will always evaluate to `true`
// Because of `src/book/mdbook.rs#L37-L39`, `dest` will always start with `root`
let is_dest_inside_root = book.get_dest().starts_with(book.get_root());

if !args.is_present("force") && is_dest_inside_root {
Expand Down
23 changes: 13 additions & 10 deletions src/book/mdbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,25 @@ impl MDBook {
if !gitignore.exists() {
// Gitignore does not exist, create it

// Because of `src/book/mdbook.rs#L37-L39`, `dest` will always start with `root`. If it
// is not, `strip_prefix` will return an Error.
if !self.get_dest().starts_with(self.get_root()) {
return;
}

let relative = self.get_dest().strip_prefix(self.get_root())
.expect("Destination is not relative to root.");
let relative = relative.to_str()
.expect("Path could not be yielded into a string slice.");

debug!("[*]: {:?} does not exist, trying to create .gitignore", gitignore);

let mut f = File::create(&gitignore)
.expect("Could not create file.");

debug!("[*]: Writing to .gitignore");

writeln!(f, "# Ignore everything within this folder")
.expect("Could not write to file.");
writeln!(f, "*")
.expect("Could not write to file.");
writeln!(f, "")
.expect("Could not write to file.");
writeln!(f, "# Except this file")
.expect("Could not write to file.");
writeln!(f, "!.gitignore")
writeln!(f, "{}", relative)
.expect("Could not write to file.");
}
}
Expand All @@ -206,7 +209,7 @@ impl MDBook {


pub fn get_gitignore(&self) -> PathBuf {
self.config.get_dest().join(".gitignore")
self.config.get_root().join(".gitignore")
}

pub fn copy_theme(&self) -> Result<(), Box<Error>> {
Expand Down