@@ -53,33 +53,48 @@ fn remove_ignored_files(book_root: &PathBuf, paths: &[PathBuf]) -> Vec<PathBuf>
53
53
return vec ! [ ] ;
54
54
}
55
55
56
- let gitignore_path = book_root. with_file_name ( ".gitignore" ) ;
57
-
58
- match gitignore:: File :: new ( gitignore_path. as_path ( ) ) {
59
- Ok ( exclusion_checker) => paths
60
- . iter ( )
61
- . filter ( |path| match exclusion_checker. is_excluded ( path) {
62
- Ok ( exclude) => !exclude,
63
- Err ( error) => {
64
- warn ! (
65
- "Unable to determine if {:?} is excluded: {:?}. Including it." ,
66
- & path, error
67
- ) ;
68
- true
56
+ match find_gitignore ( book_root) {
57
+ Some ( gitignore_path) => {
58
+ match gitignore:: File :: new ( gitignore_path. as_path ( ) ) {
59
+ Ok ( exclusion_checker) => filter_ignored_files ( exclusion_checker, paths) ,
60
+ Err ( _) => {
61
+ // We're unable to read the .gitignore file, so we'll silently allow everything.
62
+ // Please see discussion: https://github.com/rust-lang-nursery/mdBook/pull/1051
63
+ paths. iter ( ) . map ( |path| path. to_path_buf ( ) ) . collect ( )
69
64
}
70
- } )
71
- . map ( |path| path. to_path_buf ( ) )
72
- . collect ( ) ,
73
- Err ( error) => {
74
- warn ! (
75
- "Unable to read gitignore file at {:?} file: {:?}. All files will be allowed." ,
76
- gitignore_path, error
77
- ) ;
65
+ }
66
+ }
67
+ None => {
68
+ // There is no .gitignore file.
78
69
paths. iter ( ) . map ( |path| path. to_path_buf ( ) ) . collect ( )
79
70
}
80
71
}
81
72
}
82
73
74
+ fn find_gitignore ( book_root : & PathBuf ) -> Option < PathBuf > {
75
+ book_root
76
+ . ancestors ( )
77
+ . map ( |p| p. join ( ".gitignore" ) )
78
+ . find ( |p| p. exists ( ) )
79
+ }
80
+
81
+ fn filter_ignored_files ( exclusion_checker : gitignore:: File , paths : & [ PathBuf ] ) -> Vec < PathBuf > {
82
+ paths
83
+ . iter ( )
84
+ . filter ( |path| match exclusion_checker. is_excluded ( path) {
85
+ Ok ( exclude) => !exclude,
86
+ Err ( error) => {
87
+ warn ! (
88
+ "Unable to determine if {:?} is excluded: {:?}. Including it." ,
89
+ & path, error
90
+ ) ;
91
+ true
92
+ }
93
+ } )
94
+ . map ( |path| path. to_path_buf ( ) )
95
+ . collect ( )
96
+ }
97
+
83
98
/// Calls the closure when a book source file is changed, blocking indefinitely.
84
99
pub fn trigger_on_change < F > ( book : & MDBook , closure : F )
85
100
where
0 commit comments