Struct ignore::gitignore::Gitignore

source ·
pub struct Gitignore { /* private fields */ }
Expand description

Gitignore is a matcher for the globs in one or more gitignore files in the same directory.

Implementations§

source§

impl Gitignore

source

pub fn new<P: AsRef<Path>>(gitignore_path: P) -> (Gitignore, Option<Error>)

Creates a new gitignore matcher from the gitignore file path given.

If it’s desirable to include multiple gitignore files in a single matcher, or read gitignore globs from a different source, then use GitignoreBuilder.

This always returns a valid matcher, even if it’s empty. In particular, a Gitignore file can be partially valid, e.g., when one glob is invalid but the rest aren’t.

Note that I/O errors are ignored. For more granular control over errors, use GitignoreBuilder.

source

pub fn global() -> (Gitignore, Option<Error>)

Creates a new gitignore matcher from the global ignore file, if one exists.

The global config file path is specified by git’s core.excludesFile config option.

Git’s config file location is $HOME/.gitconfig. If $HOME/.gitconfig does not exist or does not specify core.excludesFile, then $XDG_CONFIG_HOME/git/ignore is read. If $XDG_CONFIG_HOME is not set or is empty, then $HOME/.config/git/ignore is used instead.

source

pub fn empty() -> Gitignore

Creates a new empty gitignore matcher that never matches anything.

Its path is empty.

source

pub fn path(&self) -> &Path

Returns the directory containing this gitignore matcher.

All matches are done relative to this path.

source

pub fn is_empty(&self) -> bool

Returns true if and only if this gitignore has zero globs, and therefore never matches any file path.

source

pub fn len(&self) -> usize

Returns the total number of globs, which should be equivalent to num_ignores + num_whitelists.

source

pub fn num_ignores(&self) -> u64

Returns the total number of ignore globs.

source

pub fn num_whitelists(&self) -> u64

Returns the total number of whitelisted globs.

source

pub fn matched<P: AsRef<Path>>(&self, path: P, is_dir: bool) -> Match<&Glob>

Returns whether the given path (file or directory) matched a pattern in this gitignore matcher.

is_dir should be true if the path refers to a directory and false otherwise.

The given path is matched relative to the path given when building the matcher. Specifically, before matching path, its prefix (as determined by a common suffix of the directory containing this gitignore) is stripped. If there is no common suffix/prefix overlap, then path is assumed to be relative to this matcher.

source

pub fn matched_path_or_any_parents<P: AsRef<Path>>( &self, path: P, is_dir: bool ) -> Match<&Glob>

Returns whether the given path (file or directory, and expected to be under the root) or any of its parent directories (up to the root) matched a pattern in this gitignore matcher.

NOTE: This method is more expensive than walking the directory hierarchy top-to-bottom and matching the entries. But, is easier to use in cases when a list of paths are available without a hierarchy.

is_dir should be true if the path refers to a directory and false otherwise.

The given path is matched relative to the path given when building the matcher. Specifically, before matching path, its prefix (as determined by a common suffix of the directory containing this gitignore) is stripped. If there is no common suffix/prefix overlap, then path is assumed to be relative to this matcher.

Panics

This method panics if the given file path is not under the root path of this matcher.

Trait Implementations§

source§

impl Clone for Gitignore

source§

fn clone(&self) -> Gitignore

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Gitignore

source§

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

Formats the value using the given formatter. 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.