Struct GitRepository

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

Wrapper around git2::Repository with safe operations

For thread safety, use the async variants (e.g., fetch_async, pull_async) which automatically handle threading using tokio::spawn_blocking. The async methods create new repository instances in background threads.

Implementations§

Source§

impl GitRepository

Source

pub fn open(path: &Path) -> Result<Self>

Open a Git repository at the given path Automatically loads SSL configuration from cascade config if available

Source

pub fn get_info(&self) -> Result<RepositoryInfo>

Get repository information

Source

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

Get the current branch name

Source

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

Get the HEAD commit hash

Source

pub fn is_dirty(&self) -> Result<bool>

Check if the working directory is dirty (has uncommitted changes)

Source

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

Get list of untracked files

Source

pub fn create_branch(&self, name: &str, target: Option<&str>) -> Result<()>

Create a new branch

Source

pub fn checkout_branch(&self, name: &str) -> Result<()>

Switch to a branch with safety checks

Source

pub fn checkout_branch_unsafe(&self, name: &str) -> Result<()>

Switch to a branch with force option to bypass safety checks

Source

pub fn checkout_commit(&self, commit_hash: &str) -> Result<()>

Checkout a specific commit (detached HEAD) with safety checks

Source

pub fn checkout_commit_unsafe(&self, commit_hash: &str) -> Result<()>

Checkout a specific commit with force option to bypass safety checks

Source

pub fn branch_exists(&self, name: &str) -> bool

Check if a branch exists

Source

pub fn branch_exists_or_fetch(&self, name: &str) -> Result<bool>

Check if a branch exists locally, and if not, attempt to fetch it from remote

Source

pub fn get_branch_commit_hash(&self, branch_name: &str) -> Result<String>

Get the commit hash for a specific branch without switching branches

Source

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

List all local branches

Source

pub fn get_upstream_branch(&self, branch_name: &str) -> Result<Option<String>>

Get the upstream branch for a local branch

Source

pub fn get_ahead_behind_counts( &self, local_branch: &str, upstream_branch: &str, ) -> Result<(usize, usize)>

Get ahead/behind counts compared to upstream

Source

pub fn set_upstream( &self, branch_name: &str, remote: &str, remote_branch: &str, ) -> Result<()>

Set upstream tracking for a branch

Source

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

Create a commit with all staged changes

Source

pub fn commit_staged_changes( &self, default_message: &str, ) -> Result<Option<String>>

Commit any staged changes with a default message

Source

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

Stage all changes

Source

pub fn stage_files(&self, file_paths: &[&str]) -> Result<()>

Stage only specific files (safer than stage_all during rebase)

Source

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

Stage only files that had conflicts (safer for rebase operations)

Source

pub fn path(&self) -> &Path

Get repository path

Source

pub fn commit_exists(&self, commit_hash: &str) -> Result<bool>

Check if a commit exists

Source

pub fn get_head_commit(&self) -> Result<Commit<'_>>

Get the HEAD commit object

Source

pub fn get_commit(&self, commit_hash: &str) -> Result<Commit<'_>>

Get a commit object by hash

Source

pub fn get_branch_head(&self, branch_name: &str) -> Result<String>

Get the commit hash at the head of a branch

Source

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

Validate git user configuration is properly set

Source

pub fn get_status(&self) -> Result<Statuses<'_>>

Get repository status

Source

pub fn get_status_summary(&self) -> Result<GitStatusSummary>

Get a summary of repository status

Source

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

Get the current commit hash (alias for get_head_commit_hash)

Source

pub fn get_commit_count_between( &self, from_commit: &str, to_commit: &str, ) -> Result<usize>

Get the count of commits between two commits

Source

pub fn get_remote_url(&self, name: &str) -> Result<String>

Get remote URL for a given remote name

Source

pub fn cherry_pick(&self, commit_hash: &str) -> Result<String>

Cherry-pick a specific commit to the current branch

Source

pub fn has_conflicts(&self) -> Result<bool>

Check for merge conflicts in the index

Source

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

Get list of conflicted files

Source

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

Fetch from remote origin

Source

pub fn pull(&self, branch: &str) -> Result<()>

Pull changes from remote (fetch + merge)

Source

pub fn push(&self, branch: &str) -> Result<()>

Push current branch to remote

Source

pub fn delete_branch(&self, name: &str) -> Result<()>

Delete a local branch

Source

pub fn delete_branch_unsafe(&self, name: &str) -> Result<()>

Delete a local branch with force option to bypass safety checks

Source

pub fn get_commits_between( &self, from: &str, to: &str, ) -> Result<Vec<Commit<'_>>>

Get commits between two references

Source

pub fn force_push_branch( &self, target_branch: &str, source_branch: &str, ) -> Result<()>

Force push one branch’s content to another branch name This is used to preserve PR history while updating branch contents after rebase

Source

pub fn force_push_branch_unsafe( &self, target_branch: &str, source_branch: &str, ) -> Result<()>

Force push with explicit force flag to bypass safety checks

Source

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

Detect the main branch name (main, master, develop)

Source

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

Get staged files in index

Source

pub fn resolve_reference(&self, reference: &str) -> Result<Commit<'_>>

Resolve a reference (branch name, tag, or commit hash) to a commit

Source

pub fn reset_soft(&self, target_ref: &str) -> Result<()>

Reset HEAD to a specific reference (soft reset)

Source

pub fn find_branch_containing_commit(&self, commit_hash: &str) -> Result<String>

Find which branch contains a specific commit

Source

pub async fn fetch_async(&self) -> Result<()>

Fetch from remote origin (async)

Source

pub async fn pull_async(&self, branch: &str) -> Result<()>

Pull changes from remote (async)

Source

pub async fn push_branch_async(&self, branch_name: &str) -> Result<()>

Push branch to remote (async)

Source

pub async fn cherry_pick_commit_async( &self, commit_hash: &str, ) -> Result<String>

Cherry-pick commit (async)

Source

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

Get commit hashes between two refs (async)

Source

pub fn reset_branch_to_commit( &self, branch_name: &str, commit_hash: &str, ) -> Result<()>

Reset a branch to point to a specific commit

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> Same for T

Source§

type Output = T

Should always be Self
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<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,