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
impl GitRepository
Sourcepub fn open(path: &Path) -> Result<Self>
pub fn open(path: &Path) -> Result<Self>
Open a Git repository at the given path Automatically loads SSL configuration from cascade config if available
Sourcepub fn get_info(&self) -> Result<RepositoryInfo>
pub fn get_info(&self) -> Result<RepositoryInfo>
Get repository information
Sourcepub fn get_current_branch(&self) -> Result<String>
pub fn get_current_branch(&self) -> Result<String>
Get the current branch name
Sourcepub fn get_head_commit_hash(&self) -> Result<String>
pub fn get_head_commit_hash(&self) -> Result<String>
Get the HEAD commit hash
Sourcepub fn is_dirty(&self) -> Result<bool>
pub fn is_dirty(&self) -> Result<bool>
Check if the working directory is dirty (has uncommitted changes)
Sourcepub fn get_untracked_files(&self) -> Result<Vec<String>>
pub fn get_untracked_files(&self) -> Result<Vec<String>>
Get list of untracked files
Sourcepub fn create_branch(&self, name: &str, target: Option<&str>) -> Result<()>
pub fn create_branch(&self, name: &str, target: Option<&str>) -> Result<()>
Create a new branch
Sourcepub fn checkout_branch(&self, name: &str) -> Result<()>
pub fn checkout_branch(&self, name: &str) -> Result<()>
Switch to a branch with safety checks
Sourcepub fn checkout_branch_unsafe(&self, name: &str) -> Result<()>
pub fn checkout_branch_unsafe(&self, name: &str) -> Result<()>
Switch to a branch with force option to bypass safety checks
Sourcepub fn checkout_commit(&self, commit_hash: &str) -> Result<()>
pub fn checkout_commit(&self, commit_hash: &str) -> Result<()>
Checkout a specific commit (detached HEAD) with safety checks
Sourcepub fn checkout_commit_unsafe(&self, commit_hash: &str) -> Result<()>
pub fn checkout_commit_unsafe(&self, commit_hash: &str) -> Result<()>
Checkout a specific commit with force option to bypass safety checks
Sourcepub fn branch_exists(&self, name: &str) -> bool
pub fn branch_exists(&self, name: &str) -> bool
Check if a branch exists
Sourcepub fn branch_exists_or_fetch(&self, name: &str) -> Result<bool>
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
Sourcepub fn get_branch_commit_hash(&self, branch_name: &str) -> Result<String>
pub fn get_branch_commit_hash(&self, branch_name: &str) -> Result<String>
Get the commit hash for a specific branch without switching branches
Sourcepub fn list_branches(&self) -> Result<Vec<String>>
pub fn list_branches(&self) -> Result<Vec<String>>
List all local branches
Sourcepub fn get_upstream_branch(&self, branch_name: &str) -> Result<Option<String>>
pub fn get_upstream_branch(&self, branch_name: &str) -> Result<Option<String>>
Get the upstream branch for a local branch
Sourcepub fn get_ahead_behind_counts(
&self,
local_branch: &str,
upstream_branch: &str,
) -> Result<(usize, usize)>
pub fn get_ahead_behind_counts( &self, local_branch: &str, upstream_branch: &str, ) -> Result<(usize, usize)>
Get ahead/behind counts compared to upstream
Sourcepub fn set_upstream(
&self,
branch_name: &str,
remote: &str,
remote_branch: &str,
) -> Result<()>
pub fn set_upstream( &self, branch_name: &str, remote: &str, remote_branch: &str, ) -> Result<()>
Set upstream tracking for a branch
Sourcepub fn commit_staged_changes(
&self,
default_message: &str,
) -> Result<Option<String>>
pub fn commit_staged_changes( &self, default_message: &str, ) -> Result<Option<String>>
Commit any staged changes with a default message
Sourcepub fn stage_files(&self, file_paths: &[&str]) -> Result<()>
pub fn stage_files(&self, file_paths: &[&str]) -> Result<()>
Stage only specific files (safer than stage_all during rebase)
Sourcepub fn stage_conflict_resolved_files(&self) -> Result<()>
pub fn stage_conflict_resolved_files(&self) -> Result<()>
Stage only files that had conflicts (safer for rebase operations)
Sourcepub fn commit_exists(&self, commit_hash: &str) -> Result<bool>
pub fn commit_exists(&self, commit_hash: &str) -> Result<bool>
Check if a commit exists
Sourcepub fn get_head_commit(&self) -> Result<Commit<'_>>
pub fn get_head_commit(&self) -> Result<Commit<'_>>
Get the HEAD commit object
Sourcepub fn get_commit(&self, commit_hash: &str) -> Result<Commit<'_>>
pub fn get_commit(&self, commit_hash: &str) -> Result<Commit<'_>>
Get a commit object by hash
Sourcepub fn get_branch_head(&self, branch_name: &str) -> Result<String>
pub fn get_branch_head(&self, branch_name: &str) -> Result<String>
Get the commit hash at the head of a branch
Sourcepub fn validate_git_user_config(&self) -> Result<()>
pub fn validate_git_user_config(&self) -> Result<()>
Validate git user configuration is properly set
Sourcepub fn get_status(&self) -> Result<Statuses<'_>>
pub fn get_status(&self) -> Result<Statuses<'_>>
Get repository status
Sourcepub fn get_status_summary(&self) -> Result<GitStatusSummary>
pub fn get_status_summary(&self) -> Result<GitStatusSummary>
Get a summary of repository status
Sourcepub fn get_current_commit_hash(&self) -> Result<String>
pub fn get_current_commit_hash(&self) -> Result<String>
Get the current commit hash (alias for get_head_commit_hash)
Sourcepub fn get_commit_count_between(
&self,
from_commit: &str,
to_commit: &str,
) -> Result<usize>
pub fn get_commit_count_between( &self, from_commit: &str, to_commit: &str, ) -> Result<usize>
Get the count of commits between two commits
Sourcepub fn get_remote_url(&self, name: &str) -> Result<String>
pub fn get_remote_url(&self, name: &str) -> Result<String>
Get remote URL for a given remote name
Sourcepub fn cherry_pick(&self, commit_hash: &str) -> Result<String>
pub fn cherry_pick(&self, commit_hash: &str) -> Result<String>
Cherry-pick a specific commit to the current branch
Sourcepub fn has_conflicts(&self) -> Result<bool>
pub fn has_conflicts(&self) -> Result<bool>
Check for merge conflicts in the index
Sourcepub fn get_conflicted_files(&self) -> Result<Vec<String>>
pub fn get_conflicted_files(&self) -> Result<Vec<String>>
Get list of conflicted files
Sourcepub fn delete_branch(&self, name: &str) -> Result<()>
pub fn delete_branch(&self, name: &str) -> Result<()>
Delete a local branch
Sourcepub fn delete_branch_unsafe(&self, name: &str) -> Result<()>
pub fn delete_branch_unsafe(&self, name: &str) -> Result<()>
Delete a local branch with force option to bypass safety checks
Sourcepub fn get_commits_between(
&self,
from: &str,
to: &str,
) -> Result<Vec<Commit<'_>>>
pub fn get_commits_between( &self, from: &str, to: &str, ) -> Result<Vec<Commit<'_>>>
Get commits between two references
Sourcepub fn force_push_branch(
&self,
target_branch: &str,
source_branch: &str,
) -> Result<()>
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
Sourcepub fn force_push_branch_unsafe(
&self,
target_branch: &str,
source_branch: &str,
) -> Result<()>
pub fn force_push_branch_unsafe( &self, target_branch: &str, source_branch: &str, ) -> Result<()>
Force push with explicit force flag to bypass safety checks
Sourcepub fn detect_main_branch(&self) -> Result<String>
pub fn detect_main_branch(&self) -> Result<String>
Detect the main branch name (main, master, develop)
Sourcepub fn get_staged_files(&self) -> Result<Vec<String>>
pub fn get_staged_files(&self) -> Result<Vec<String>>
Get staged files in index
Sourcepub fn resolve_reference(&self, reference: &str) -> Result<Commit<'_>>
pub fn resolve_reference(&self, reference: &str) -> Result<Commit<'_>>
Resolve a reference (branch name, tag, or commit hash) to a commit
Sourcepub fn reset_soft(&self, target_ref: &str) -> Result<()>
pub fn reset_soft(&self, target_ref: &str) -> Result<()>
Reset HEAD to a specific reference (soft reset)
Sourcepub fn find_branch_containing_commit(&self, commit_hash: &str) -> Result<String>
pub fn find_branch_containing_commit(&self, commit_hash: &str) -> Result<String>
Find which branch contains a specific commit
Sourcepub async fn fetch_async(&self) -> Result<()>
pub async fn fetch_async(&self) -> Result<()>
Fetch from remote origin (async)
Sourcepub async fn pull_async(&self, branch: &str) -> Result<()>
pub async fn pull_async(&self, branch: &str) -> Result<()>
Pull changes from remote (async)
Sourcepub async fn push_branch_async(&self, branch_name: &str) -> Result<()>
pub async fn push_branch_async(&self, branch_name: &str) -> Result<()>
Push branch to remote (async)
Sourcepub async fn cherry_pick_commit_async(
&self,
commit_hash: &str,
) -> Result<String>
pub async fn cherry_pick_commit_async( &self, commit_hash: &str, ) -> Result<String>
Cherry-pick commit (async)
Auto Trait Implementations§
impl Freeze for GitRepository
impl RefUnwindSafe for GitRepository
impl Send for GitRepository
impl !Sync for GitRepository
impl Unpin for GitRepository
impl UnwindSafe for GitRepository
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 more