pub struct GitRepo { /* private fields */ }Expand description
Git repository wrapper
Implementations§
Source§impl GitRepo
impl GitRepo
Sourcepub fn is_git_repo(path: &Path) -> bool
pub fn is_git_repo(path: &Path) -> bool
Check if path is a git repository
Sourcepub fn current_branch(&self) -> Result<String, GitError>
pub fn current_branch(&self) -> Result<String, GitError>
Get current branch name
Sourcepub fn current_commit(&self) -> Result<String, GitError>
pub fn current_commit(&self) -> Result<String, GitError>
Get current commit hash
Sourcepub fn diff_files(
&self,
from: &str,
to: &str,
) -> Result<Vec<ChangedFile>, GitError>
pub fn diff_files( &self, from: &str, to: &str, ) -> Result<Vec<ChangedFile>, GitError>
Get files changed between two commits
Sourcepub fn status(&self) -> Result<Vec<ChangedFile>, GitError>
pub fn status(&self) -> Result<Vec<ChangedFile>, GitError>
Get files changed in working tree
Returns both staged and unstaged changes. For renames, the old_path
field contains the original filename.
Sourcepub fn file_log(
&self,
path: &str,
count: usize,
) -> Result<Vec<Commit>, GitError>
pub fn file_log( &self, path: &str, count: usize, ) -> Result<Vec<Commit>, GitError>
Get commits that modified a specific file
Sourcepub fn blame(&self, path: &str) -> Result<Vec<BlameLine>, GitError>
pub fn blame(&self, path: &str) -> Result<Vec<BlameLine>, GitError>
Get blame information for a file
Sourcepub fn diff_content(
&self,
from: &str,
to: &str,
path: &str,
) -> Result<String, GitError>
pub fn diff_content( &self, from: &str, to: &str, path: &str, ) -> Result<String, GitError>
Get diff content between two commits for a file
Sourcepub fn uncommitted_diff(&self, path: &str) -> Result<String, GitError>
pub fn uncommitted_diff(&self, path: &str) -> Result<String, GitError>
Get diff content for uncommitted changes (working tree vs HEAD) Includes both staged and unstaged changes.
Sourcepub fn all_uncommitted_diffs(&self) -> Result<String, GitError>
pub fn all_uncommitted_diffs(&self) -> Result<String, GitError>
Get diff content for all uncommitted changes Returns combined diff for all changed files.
Sourcepub fn has_changes(&self, path: &str) -> Result<bool, GitError>
pub fn has_changes(&self, path: &str) -> Result<bool, GitError>
Check if a file has uncommitted changes
Sourcepub fn last_modified_commit(&self, path: &str) -> Result<Commit, GitError>
pub fn last_modified_commit(&self, path: &str) -> Result<Commit, GitError>
Get the commit where a file was last modified
Sourcepub fn file_change_frequency(
&self,
path: &str,
days: u32,
) -> Result<u32, GitError>
pub fn file_change_frequency( &self, path: &str, days: u32, ) -> Result<u32, GitError>
Calculate file importance based on recent changes
Sourcepub fn file_at_ref(&self, path: &str, git_ref: &str) -> Result<String, GitError>
pub fn file_at_ref(&self, path: &str, git_ref: &str) -> Result<String, GitError>
Get file content at a specific git ref (commit, branch, tag)
Uses git show <ref>:<path> to retrieve file content at that revision.
§Arguments
path- File path relative to repository rootgit_ref- Git ref (commit hash, branch name, tag, HEAD~n, etc.)
§Returns
File content as string, or error if file doesn’t exist at that ref
§Example
let repo = GitRepo::open(Path::new("."))?;
let content = repo.file_at_ref("src/main.rs", "HEAD~5")?;Sourcepub fn diff_hunks(
&self,
from_ref: &str,
to_ref: &str,
path: Option<&str>,
) -> Result<Vec<DiffHunk>, GitError>
pub fn diff_hunks( &self, from_ref: &str, to_ref: &str, path: Option<&str>, ) -> Result<Vec<DiffHunk>, GitError>
Parse diff between two refs into structured hunks
Returns detailed hunk information including line numbers for each change.
§Arguments
from_ref- Starting ref (e.g., “main”, “HEAD~5”, commit hash)to_ref- Ending ref (e.g., “HEAD”, “feature-branch”)path- Optional file path to filter to a single file
§Returns
Vec of DiffHunk with structured line-level information
Auto Trait Implementations§
impl Freeze for GitRepo
impl RefUnwindSafe for GitRepo
impl Send for GitRepo
impl Sync for GitRepo
impl Unpin for GitRepo
impl UnwindSafe for GitRepo
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);