Skip to main content

IgnoreMatcher

Struct IgnoreMatcher 

Source
pub struct IgnoreMatcher {
    pub warnings: Vec<String>,
    /* private fields */
}
Expand description

Engine used to evaluate ignore patterns against repository-relative paths.

Fields§

§warnings: Vec<String>

Warnings emitted while loading in-tree .gitignore (e.g. symlink paths).

Implementations§

Source§

impl IgnoreMatcher

Source

pub fn from_repository(repo: &Repository) -> Result<Self>

Build a matcher from repository exclude sources.

§Parameters
  • repo - open repository.
§Errors

Returns Error::Io if configured pattern files cannot be read.

Examples found in repository?
examples/ignore_match.rs (line 16)
9fn main() -> grit_lib::error::Result<()> {
10    let root = tempfile::tempdir()?;
11    let repo = init_repository(root.path(), false, "main", None, "files")?;
12
13    let wt = repo.work_tree.as_ref().expect("non-bare");
14    fs::write(wt.join(".gitignore"), "*.log\n")?;
15
16    let mut matcher = IgnoreMatcher::from_repository(&repo)?;
17    let (ignored_log, m_log) = matcher.check_path(&repo, None, "build.log", false)?;
18    let (ignored_txt, m_txt) = matcher.check_path(&repo, None, "readme.txt", false)?;
19
20    println!("build.log ignored={ignored_log} ({m_log:?})");
21    println!("readme.txt ignored={ignored_txt} ({m_txt:?})");
22
23    Ok(())
24}
Source

pub fn add_exclude_from_files( &mut self, paths: &[PathBuf], cwd: &Path, ) -> Result<()>

Append patterns from ls-files --exclude-from / -X files (relative paths resolve from cwd).

Matches Git’s EXC_FILE lists loaded after core.excludesfile and .git/info/exclude.

Source

pub fn add_cli_excludes(&mut self, patterns: &[String])

Append patterns from ls-files --exclude / -x (Git command-line exclude list).

Source

pub fn take_warnings(&mut self) -> Vec<String>

Take any warnings accumulated while loading ignore files (caller prints to stderr).

Source

pub fn check_path( &mut self, repo: &Repository, index: Option<&Index>, repo_rel_path: &str, is_dir: bool, ) -> Result<(bool, Option<IgnoreMatch>)>

Check whether a repository-relative path is ignored.

§Parameters
  • repo - repository handle.
  • index - optional index; when present, tracked entries are not ignored.
  • repo_rel_path - normalized repository-relative path with / separators.
  • is_dir - whether the queried path is a directory.
§Returns

Tuple (ignored, match_info) where match_info is the last matching pattern (including negated matches).

§Errors

Returns Error::Io when a relevant .gitignore cannot be read.

Examples found in repository?
examples/ignore_match.rs (line 17)
9fn main() -> grit_lib::error::Result<()> {
10    let root = tempfile::tempdir()?;
11    let repo = init_repository(root.path(), false, "main", None, "files")?;
12
13    let wt = repo.work_tree.as_ref().expect("non-bare");
14    fs::write(wt.join(".gitignore"), "*.log\n")?;
15
16    let mut matcher = IgnoreMatcher::from_repository(&repo)?;
17    let (ignored_log, m_log) = matcher.check_path(&repo, None, "build.log", false)?;
18    let (ignored_txt, m_txt) = matcher.check_path(&repo, None, "readme.txt", false)?;
19
20    println!("build.log ignored={ignored_log} ({m_log:?})");
21    println!("readme.txt ignored={ignored_txt} ({m_txt:?})");
22
23    Ok(())
24}

Trait Implementations§

Source§

impl Debug for IgnoreMatcher

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for IgnoreMatcher

Source§

fn default() -> IgnoreMatcher

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.