Skip to content
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

Make serve and watch respect .gitignore #1045

Closed
wants to merge 1 commit into from
Closed
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
115 changes: 115 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ clap = "2.24"
env_logger = "0.6"
error-chain = "0.12"
handlebars = { version = "2.0", default-features = false, features = ["no_dir_source"] }
ignore = "0.1.8"
itertools = "0.8"
lazy_static = "1.0"
log = "0.4"
Expand Down
12 changes: 11 additions & 1 deletion src/cmd/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use iron::{status, AfterMiddleware, Chain, Iron, IronError, IronResult, Request,
use mdbook::errors::*;
use mdbook::utils;
use mdbook::MDBook;
use std::path::PathBuf;

struct ErrorRecover;

Expand Down Expand Up @@ -59,6 +60,7 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
.help("Port to use for WebSockets livereload connections"),
)
.arg_from_usage("-o, --open 'Opens the book server in a web browser'")
.arg_from_usage("-i, --gitignore 'Respect .gitignore and skip changes to ignored files'")
}

// Watch command implementation
Expand Down Expand Up @@ -107,8 +109,16 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
open(serving_url);
}

let gitignore_path: Option<PathBuf> = if args.is_present("gitignore") {
let mut path = book_dir.clone();
path.push(".gitignore");
Some(path)
} else {
None
};

#[cfg(feature = "watch")]
watch::trigger_on_change(&book, move |paths, book_dir| {
watch::trigger_on_change(&book, gitignore_path, move |paths, book_dir| {
info!("Files changed: {:?}", paths);
info!("Building book...");

Expand Down
Loading