GitRepo

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 fn get_ref_diff_full(&self, from: &str, to: &str) -> Result<String>

Get diff between two refs as a full unified diff string with headers

Returns a complete diff suitable for parsing, including:

  • diff –git headers
  • — and +++ file headers
  • @@ hunk headers
  • +/- content lines
Source

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

Get staged diff as a full unified diff string with headers

Returns a complete diff suitable for parsing, including:

  • diff –git headers
  • — and +++ file headers
  • @@ hunk headers
  • +/- content lines
Source

pub 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 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_git_info_for_branch_diff( &self, _config: &Config, base_branch: &str, target_branch: &str, ) -> Result<CommitContext>

Get Git information for comparing two branches

§Arguments
  • config - The configuration object
  • base_branch - The base branch (e.g., “main”)
  • target_branch - The target branch (e.g., “feature-branch”)
§Returns

A Result containing the CommitContext for the branch comparison or an error.

Source

pub fn get_git_info_for_commit_range( &self, _config: &Config, from: &str, to: &str, ) -> Result<CommitContext>

Get Git information for a commit range (for PR descriptions)

§Arguments
  • config - The configuration object
  • from - The starting Git reference (exclusive)
  • to - The ending Git reference (inclusive)
§Returns

A Result containing the CommitContext for the commit range or an error.

Source

pub fn get_commits_for_pr(&self, from: &str, to: &str) -> Result<Vec<String>>

Get commits for PR description between two references

Source

pub fn get_commit_range_files( &self, from: &str, to: &str, ) -> Result<Vec<StagedFile>>

Get files changed in a commit range

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 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 amend_commit(&self, message: &str) -> Result<CommitResult>

Amend the previous commit with staged changes and a new message

Source

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

Get the message of the HEAD commit

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

Source

pub fn stage_file(&self, path: &Path) -> Result<()>

Stage a file (add to index)

Source

pub fn unstage_file(&self, path: &Path) -> Result<()>

Unstage a file (remove from index, keep working tree changes)

Source

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

Stage all modified/new/deleted files

Source

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

Unstage all files (reset index to HEAD)

Source

pub fn get_untracked_files(&self) -> Result<Vec<String>>

Get list of untracked files (new files not in the index)

Source

pub fn get_all_tracked_files(&self) -> Result<Vec<String>>

Get all tracked files in the repository (from HEAD + index)

Source

pub fn get_ahead_behind(&self) -> (usize, usize)

Get ahead/behind counts relative to upstream tracking branch

Returns (ahead, behind) tuple, or (0, 0) if no upstream is configured

Trait Implementations§

Source§

impl Debug for GitRepo

Source§

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

Formats the value using the given formatter. Read more
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> 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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> 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> WasmCompatSend for T
where T: Send,

Source§

impl<T> WasmCompatSync for T
where T: Sync,