Struct devx_pre_commit::PreCommitContext[][src]

pub struct PreCommitContext { /* fields omitted */ }
Expand description

Represents the API entrypoint of the git pre-commit hook. It carries the list of the staged files and the project root path. Note that staged file paths are all relative to the project root path.

Implementations

impl PreCommitContext[src]

pub fn from_git_diff(project_root: impl Into<PathBuf>) -> Result<Self>[src]

Creates the git pre-commit context acquiring the staged files via running git diff in project_root. The project_root is expected to contain the .git dir (see locate_project_root function for more on that).

The staged files are stored in PreCommitContext as paths relative to project_root.

pub fn staged_files(&self) -> impl Iterator<Item = &Path>[src]

Returns an iterator over all the files staged for the commit.

pub fn retain_staged_files(&mut self, f: impl FnMut(&Path) -> bool)[src]

Accepts a function predicate that accepts a relative path to the staged file and returns false if the given file should be removed from this PreCommitContext

pub fn touched_crates(&self) -> Vec<String>[src]

Returns the names of the crates that contain Self::staged_rust_files().

Warning: this heuristically looks for Cargo.toml files and searches for name = " substring in them to get the crate name (i.e. it doesn’t really parse them properly, but this works 99% of the time and lets us save on a full-fledged toml parser dependency). This heuristic may be relaxed in the future, and it shouldn’t be considered a breaking change.

pub fn staged_rust_files(&self) -> impl Iterator<Item = &Path>[src]

Returns an iterator over all staged files with .rs extension.

pub fn rustfmt(&self) -> Result<()>[src]

Runs cargo fmt against the Self::touched_crates()

pub fn stage_new_changes(&self) -> Result<()>[src]

Pushes the changes introduced to staged files in the working tree to the git index. It is important to call this function once you’ve modified some staged files (e.g. via Self::rustfmt())

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.