Load ignore rules from a specific file only. This is useful for testing or when you want to use a custom ignore file. # Arguments `repo_root` - The root directory of the repository `ignore_path` - Path to the ignore file # Returns An `IgnoreRules` instance with patterns from the specified file.
(repo_root: &Path, ignore_path: &Path)
| 167 | /// |
| 168 | /// An `IgnoreRules` instance with patterns from the specified file. |
| 169 | pub fn from_file(repo_root: &Path, ignore_path: &Path) -> IgnoreResult<Self> { |
| 170 | let local = if ignore_path.exists() { |
| 171 | let mut builder = GitignoreBuilder::new(repo_root); |
| 172 | if let Some(err) = builder.add(ignore_path) { |
| 173 | return Err(IgnoreError::ParseError { |
| 174 | path: ignore_path.display().to_string(), |
| 175 | details: err.to_string(), |
| 176 | }); |
| 177 | } |
| 178 | builder.build().ok() |
| 179 | } else { |
| 180 | None |
| 181 | }; |
| 182 | |
| 183 | Ok(Self { |
| 184 | global: None, |
| 185 | local, |
| 186 | repo_root: repo_root.to_path_buf(), |
| 187 | }) |
| 188 | } |
| 189 | |
| 190 | /// Check if a path should be ignored. |
| 191 | /// |