Skip to content

Commit c538432

Browse files
authored
Merge branch 'rust-lang:master' into patch-2
2 parents 424dc3c + 41567b0 commit c538432

File tree

6 files changed

+72
-37
lines changed

6 files changed

+72
-37
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
- build: msrv
3333
os: ubuntu-20.04
3434
# sync MSRV with docs: guide/src/guide/installation.md and Cargo.toml
35-
rust: 1.60.0
35+
rust: 1.63.0
3636
steps:
3737
- uses: actions/checkout@v3
3838
- name: Install Rust

Cargo.lock

+44-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ license = "MPL-2.0"
1414
readme = "README.md"
1515
repository = "https://github.com/rust-lang/mdBook"
1616
description = "Creates a book from markdown files"
17-
rust-version = "1.60"
17+
rust-version = "1.63"
1818

1919
[dependencies]
2020
anyhow = "1.0.28"
@@ -39,7 +39,7 @@ topological-sort = "0.2.2"
3939
# Watch feature
4040
notify = { version = "5.0.0", optional = true }
4141
notify-debouncer-mini = { version = "0.2.1", optional = true }
42-
gitignore = { version = "1.0", optional = true }
42+
ignore = { version = "0.4.20", optional = true }
4343

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

6161
[features]
6262
default = ["watch", "serve", "search"]
63-
watch = ["notify", "notify-debouncer-mini", "gitignore"]
64-
serve = ["futures-util", "tokio", "warp"]
65-
search = ["elasticlunr-rs", "ammonia"]
63+
watch = ["dep:notify", "dep:notify-debouncer-mini", "dep:ignore"]
64+
serve = ["dep:futures-util", "dep:tokio", "dep:warp"]
65+
search = ["dep:elasticlunr-rs", "dep:ammonia"]
6666

6767
[[bin]]
6868
doc = false

guide/src/cli/init.md

+8
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,12 @@ mdbook init --title="my amazing book"
6767
Create a `.gitignore` file configured to ignore the `book` directory created when [building] a book.
6868
If not supplied, an interactive prompt will ask whether it should be created.
6969

70+
```bash
71+
mdbook init --ignore=none
72+
```
73+
74+
```bash
75+
mdbook init --ignore=git
76+
```
77+
7078
[building]: build.md

guide/src/guide/installation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ To make it easier to run, put the path to the binary into your `PATH`.
2020

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

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

src/cmd/watch.rs

+13-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::command_prelude::*;
22
use crate::{get_book_dir, open};
3+
use ignore::gitignore::Gitignore;
34
use mdbook::errors::Result;
45
use mdbook::utils;
56
use mdbook::MDBook;
@@ -62,14 +63,14 @@ fn remove_ignored_files(book_root: &Path, paths: &[PathBuf]) -> Vec<PathBuf> {
6263

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

88-
fn filter_ignored_files(exclusion_checker: gitignore::File, paths: &[PathBuf]) -> Vec<PathBuf> {
89+
fn filter_ignored_files(ignore: Gitignore, paths: &[PathBuf]) -> Vec<PathBuf> {
8990
paths
9091
.iter()
91-
.filter(|path| match exclusion_checker.is_excluded(path) {
92-
Ok(exclude) => !exclude,
93-
Err(error) => {
94-
warn!(
95-
"Unable to determine if {:?} is excluded: {:?}. Including it.",
96-
&path, error
97-
);
98-
true
99-
}
92+
.filter(|path| {
93+
!ignore
94+
.matched_path_or_any_parents(path, path.is_dir())
95+
.is_ignore()
10096
})
10197
.map(|path| path.to_path_buf())
10298
.collect()

0 commit comments

Comments
 (0)