[−][src]Struct devx_pre_commit::PreCommitContext
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 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 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 rustfmt
)
Auto Trait Implementations
impl RefUnwindSafe for PreCommitContext
impl Send for PreCommitContext
impl Sync for PreCommitContext
impl Unpin for PreCommitContext
impl UnwindSafe for PreCommitContext
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,