Skip to content

Commit

Permalink
Merge branch 'rust-lang:master' into patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
expikr authored Apr 23, 2023
2 parents 424dc3c + 41567b0 commit c538432
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- build: msrv
os: ubuntu-20.04
# sync MSRV with docs: guide/src/guide/installation.md and Cargo.toml
rust: 1.60.0
rust: 1.63.0
steps:
- uses: actions/checkout@v3
- name: Install Rust
Expand Down
57 changes: 44 additions & 13 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ license = "MPL-2.0"
readme = "README.md"
repository = "https://github.com/rust-lang/mdBook"
description = "Creates a book from markdown files"
rust-version = "1.60"
rust-version = "1.63"

[dependencies]
anyhow = "1.0.28"
Expand All @@ -39,7 +39,7 @@ topological-sort = "0.2.2"
# Watch feature
notify = { version = "5.0.0", optional = true }
notify-debouncer-mini = { version = "0.2.1", optional = true }
gitignore = { version = "1.0", optional = true }
ignore = { version = "0.4.20", optional = true }

# Serve feature
futures-util = { version = "0.3.4", optional = true }
Expand All @@ -60,9 +60,9 @@ walkdir = "2.0"

[features]
default = ["watch", "serve", "search"]
watch = ["notify", "notify-debouncer-mini", "gitignore"]
serve = ["futures-util", "tokio", "warp"]
search = ["elasticlunr-rs", "ammonia"]
watch = ["dep:notify", "dep:notify-debouncer-mini", "dep:ignore"]
serve = ["dep:futures-util", "dep:tokio", "dep:warp"]
search = ["dep:elasticlunr-rs", "dep:ammonia"]

[[bin]]
doc = false
Expand Down
8 changes: 8 additions & 0 deletions guide/src/cli/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,12 @@ mdbook init --title="my amazing book"
Create a `.gitignore` file configured to ignore the `book` directory created when [building] a book.
If not supplied, an interactive prompt will ask whether it should be created.

```bash
mdbook init --ignore=none
```

```bash
mdbook init --ignore=git
```

[building]: build.md
2 changes: 1 addition & 1 deletion guide/src/guide/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ To make it easier to run, put the path to the binary into your `PATH`.

To build the `mdbook` executable from source, you will first need to install Rust and Cargo.
Follow the instructions on the [Rust installation page].
mdBook currently requires at least Rust version 1.60.
mdBook currently requires at least Rust version 1.63.

Once you have installed Rust, the following command can be used to build and install mdBook:

Expand Down
30 changes: 13 additions & 17 deletions src/cmd/watch.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::command_prelude::*;
use crate::{get_book_dir, open};
use ignore::gitignore::Gitignore;
use mdbook::errors::Result;
use mdbook::utils;
use mdbook::MDBook;
Expand Down Expand Up @@ -62,14 +63,14 @@ fn remove_ignored_files(book_root: &Path, paths: &[PathBuf]) -> Vec<PathBuf> {

match find_gitignore(book_root) {
Some(gitignore_path) => {
match gitignore::File::new(gitignore_path.as_path()) {
Ok(exclusion_checker) => filter_ignored_files(exclusion_checker, paths),
Err(_) => {
// We're unable to read the .gitignore file, so we'll silently allow everything.
// Please see discussion: https://github.com/rust-lang/mdBook/pull/1051
paths.iter().map(|path| path.to_path_buf()).collect()
}
let (ignore, err) = Gitignore::new(&gitignore_path);
if let Some(err) = err {
warn!(
"error reading gitignore `{}`: {err}",
gitignore_path.display()
);
}
filter_ignored_files(ignore, paths)
}
None => {
// There is no .gitignore file.
Expand All @@ -85,18 +86,13 @@ fn find_gitignore(book_root: &Path) -> Option<PathBuf> {
.find(|p| p.exists())
}

fn filter_ignored_files(exclusion_checker: gitignore::File, paths: &[PathBuf]) -> Vec<PathBuf> {
fn filter_ignored_files(ignore: Gitignore, paths: &[PathBuf]) -> Vec<PathBuf> {
paths
.iter()
.filter(|path| match exclusion_checker.is_excluded(path) {
Ok(exclude) => !exclude,
Err(error) => {
warn!(
"Unable to determine if {:?} is excluded: {:?}. Including it.",
&path, error
);
true
}
.filter(|path| {
!ignore
.matched_path_or_any_parents(path, path.is_dir())
.is_ignore()
})
.map(|path| path.to_path_buf())
.collect()
Expand Down

0 comments on commit c538432

Please sign in to comment.