Struct GitRepo

Source
pub struct GitRepo { /* private fields */ }
Expand description

Represents a Git repository and provides methods for interacting with it.

Implementations§

Source§

impl GitRepo

Source

pub fn new(repo_path: &Path) -> Result<Self>

Creates a new GitRepo instance from a local path.

§Arguments
  • repo_path - The path to the Git repository.
§Returns

A Result containing the GitRepo instance or an error.

Source

pub fn new_from_url(repository_url: Option<String>) -> Result<Self>

Creates a new GitRepo instance, handling both local and remote repositories.

§Arguments
  • repository_url - Optional URL for a remote repository.
§Returns

A Result containing the GitRepo instance or an error.

Source

pub fn clone_remote_repository(url: &str) -> Result<Self>

Clones a remote repository and creates a GitRepo instance for it.

§Arguments
  • url - The URL of the remote repository to clone.
§Returns

A Result containing the GitRepo instance or an error.

Source

pub fn open_repo(&self) -> Result<Repository, Error>

Open the repository at the stored path

Source

pub fn is_remote(&self) -> bool

Returns whether this GitRepo instance is working with a remote repository

Source

pub fn get_remote_url(&self) -> Option<&str>

Returns the original remote URL if this is a cloned repository

Source

pub fn repo_path(&self) -> &PathBuf

Returns the repository path

Source

pub fn update_remote(&self) -> Result<()>

Updates the remote repository by fetching the latest changes

Source

pub fn get_current_branch(&self) -> Result<String>

Retrieves the current branch name.

§Returns

A Result containing the branch name as a String or an error.

Source

pub fn execute_hook(&self, hook_name: &str) -> Result<()>

Executes a Git hook.

§Arguments
  • hook_name - The name of the hook to execute.
§Returns

A Result indicating success or an error.

Source

pub fn get_repo_root() -> Result<PathBuf>

Get the root directory of the current git repository

Source

pub fn get_readme_at_commit(&self, commit_ish: &str) -> Result<Option<String>>

Retrieves the README content at a specific commit.

§Arguments
  • commit_ish - A string that resolves to a commit.
§Returns

A Result containing an Option with the README content or an error.

Source

pub fn extract_files_info( &self, include_unstaged: bool, ) -> Result<RepoFilesInfo>

Extract files info without crossing async boundaries

Source

pub fn get_unstaged_files(&self) -> Result<Vec<StagedFile>>

Gets unstaged file changes from the repository

Source

pub async fn get_project_metadata( &self, changed_files: &[String], ) -> Result<ProjectMetadata>

Retrieves project metadata for changed files.

§Arguments
  • changed_files - A slice of Strings representing the changed file paths.
§Returns

A Result containing the ProjectMetadata or an error.

Source

pub async fn get_git_info(&self, _config: &Config) -> Result<CommitContext>

Retrieves Git information for the repository.

§Arguments
  • config - The configuration object.
§Returns

A Result containing the CommitContext or an error.

Source

pub async fn get_git_info_with_unstaged( &self, _config: &Config, include_unstaged: bool, ) -> Result<CommitContext>

Get Git information including unstaged changes

§Arguments
  • config - The configuration object
  • include_unstaged - Whether to include unstaged changes
§Returns

A Result containing the CommitContext or an error.

Source

pub fn get_recent_commits(&self, count: usize) -> Result<Vec<RecentCommit>>

Retrieves recent commits.

§Arguments
  • count - The number of recent commits to retrieve.
§Returns

A Result containing a Vec of RecentCommit objects or an error.

Source

pub fn commit_and_verify(&self, message: &str) -> Result<CommitResult>

Commits changes and verifies the commit.

§Arguments
  • message - The commit message.
§Returns

A Result containing the CommitResult or an error.

Source

pub async fn get_git_info_for_commit( &self, _config: &Config, commit_id: &str, ) -> Result<CommitContext>

Get Git information for a specific commit

§Arguments
  • config - The configuration object
  • commit_id - The ID of the commit to analyze
§Returns

A Result containing the CommitContext or an error.

Source

pub fn get_commit_date(&self, commit_ish: &str) -> Result<String>

Get the commit date for a reference

Source

pub fn get_commits_between_with_callback<T, F>( &self, from: &str, to: &str, callback: F, ) -> Result<Vec<T>>
where F: FnMut(&RecentCommit) -> Result<T>,

Get commits between two references with a callback

Source

pub fn commit(&self, message: &str) -> Result<CommitResult>

Commit changes to the repository

Source

pub fn is_inside_work_tree() -> Result<bool>

Check if inside a working tree

Source

pub fn get_commit_files(&self, commit_id: &str) -> Result<Vec<StagedFile>>

Get the files changed in a specific commit

Source

pub fn get_file_paths_for_commit(&self, commit_id: &str) -> Result<Vec<String>>

Get just the file paths for a specific commit

Trait Implementations§

Source§

impl Drop for GitRepo

Source§

fn drop(&mut self)

Executes the destructor for this 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,