Skip to main content

weavatrix_scan/ignore/repository/
mod.rs

1use super::git::{gitconfig_excludes_path, resolve_git_directory};
2use super::overrides::OverrideRules;
3use super::repository_source::find_repository_root;
4use super::{
5    IgnoreRules, RepositoryMatch, RuleAction, SourceRank, match_prepared_rules, match_rules,
6    normalized_evidence_location,
7};
8use crate::config::{IgnorePolicy, ScanOptions};
9use crate::error::{Error, Result};
10use crate::hidden::is_hidden_with_hint;
11use crate::path::normalized_relative_path;
12use crate::report::{IgnoreSourceEvidence, IgnoreSourceKind, ScanWarning};
13use crate::walk_types::ErrorPolicy;
14use std::borrow::Cow;
15use std::collections::HashMap;
16use std::io;
17use std::path::{Path, PathBuf};
18
19mod configuration;
20mod matching;
21
22/// A reusable, lazily cached repository ignore matcher.
23///
24/// Paths may be absolute or relative to the configured scan root. Directory
25/// rule files are loaded once and cached, which makes repeated incremental
26/// checks cheap without walking the repository again.
27#[derive(Debug, Clone)]
28pub struct RepositoryMatcher {
29    pub(super) scan_root: PathBuf,
30    pub(super) options: ScanOptions,
31    pub(super) match_root: PathBuf,
32    pub(super) scan_base: String,
33    pub(super) ignore_files: Vec<String>,
34    pub(super) case_insensitive: bool,
35    pub(super) error_policy: ErrorPolicy,
36    pub(super) overrides: OverrideRules,
37    pub(super) skip_hidden: bool,
38    pub(super) base_rules: IgnoreRules,
39    pub(super) directories: HashMap<PathBuf, IgnoreRules>,
40    pub(super) sources: Vec<IgnoreSourceEvidence>,
41    pub(super) warnings: Vec<ScanWarning>,
42    pub(super) portable: bool,
43}
44
45fn source_enabled(name: &str, policy: &IgnorePolicy, git_sources_enabled: bool) -> bool {
46    match name {
47        ".gitignore" => policy.git_ignore && git_sources_enabled,
48        ".ignore" => policy.dot_ignore,
49        _ => policy.custom_ignore,
50    }
51}