compare_changes/lib.rs
1mod convert;
2mod path;
3
4pub fn path_matches(path: &str, files: &[&str]) -> Result<Option<usize>, regex::Error> {
5 if files.is_empty() {
6 return Ok(None);
7 }
8
9 // remove leading '!' since negations are not handled here
10 let pattern = path.strip_prefix('!').unwrap_or(path);
11
12 // Parse the single path
13 let parsed_path = path::parse(pattern);
14
15 // Build regex from the parsed path — propagate compilation errors
16 let re = convert::path_to_regex(&parsed_path)?;
17
18 // Check if any file matches the compiled regex
19 Ok(files.iter().enumerate().find(|(_, file)| re.is_match(file)).map(|(i, _)| i))
20}