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

Switch from gitignore to ignore #2076

Merged
merged 1 commit into from
Apr 23, 2023
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 .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
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