|
| 1 | +use crate::utils::ignore::remove_ignored_files; |
1 | 2 | use crate::{get_book_dir, open};
|
2 | 3 | use clap::{arg, App, Arg, ArgMatches};
|
3 | 4 | use mdbook::errors::Result;
|
@@ -69,53 +70,6 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
|
69 | 70 | Ok(())
|
70 | 71 | }
|
71 | 72 |
|
72 |
| -fn remove_ignored_files(book_root: &Path, paths: &[PathBuf]) -> Vec<PathBuf> { |
73 |
| - if paths.is_empty() { |
74 |
| - return vec![]; |
75 |
| - } |
76 |
| - |
77 |
| - match find_gitignore(book_root) { |
78 |
| - Some(gitignore_path) => { |
79 |
| - match gitignore::File::new(gitignore_path.as_path()) { |
80 |
| - Ok(exclusion_checker) => filter_ignored_files(exclusion_checker, paths), |
81 |
| - Err(_) => { |
82 |
| - // We're unable to read the .gitignore file, so we'll silently allow everything. |
83 |
| - // Please see discussion: https://github.com/rust-lang/mdBook/pull/1051 |
84 |
| - paths.iter().map(|path| path.to_path_buf()).collect() |
85 |
| - } |
86 |
| - } |
87 |
| - } |
88 |
| - None => { |
89 |
| - // There is no .gitignore file. |
90 |
| - paths.iter().map(|path| path.to_path_buf()).collect() |
91 |
| - } |
92 |
| - } |
93 |
| -} |
94 |
| - |
95 |
| -fn find_gitignore(book_root: &Path) -> Option<PathBuf> { |
96 |
| - book_root |
97 |
| - .ancestors() |
98 |
| - .map(|p| p.join(".gitignore")) |
99 |
| - .find(|p| p.exists()) |
100 |
| -} |
101 |
| - |
102 |
| -fn filter_ignored_files(exclusion_checker: gitignore::File, paths: &[PathBuf]) -> Vec<PathBuf> { |
103 |
| - paths |
104 |
| - .iter() |
105 |
| - .filter(|path| match exclusion_checker.is_excluded(path) { |
106 |
| - Ok(exclude) => !exclude, |
107 |
| - Err(error) => { |
108 |
| - warn!( |
109 |
| - "Unable to determine if {:?} is excluded: {:?}. Including it.", |
110 |
| - &path, error |
111 |
| - ); |
112 |
| - true |
113 |
| - } |
114 |
| - }) |
115 |
| - .map(|path| path.to_path_buf()) |
116 |
| - .collect() |
117 |
| -} |
118 |
| - |
119 | 73 | /// Calls the closure when a book source file is changed, blocking indefinitely.
|
120 | 74 | pub fn trigger_on_change<F>(book: &MDBook, closure: F)
|
121 | 75 | where
|
|
0 commit comments