pub trait GitOps {
Show 35 methods
// Required methods
fn workdir(&self) -> Option<&Path>;
fn current_branch(&self) -> Result<String>;
fn head_detached(&self) -> Result<bool>;
fn is_rebasing(&self) -> bool;
fn branch_exists(&self, name: &str) -> bool;
fn create_branch(&self, name: &str) -> Result<Oid>;
fn checkout(&self, branch: &str) -> Result<()>;
fn delete_branch(&self, name: &str) -> Result<()>;
fn list_branches(&self) -> Result<Vec<String>>;
fn branch_commit(&self, branch: &str) -> Result<Oid>;
fn remote_branch_commit(&self, branch: &str) -> Result<Oid>;
fn branch_commit_message(&self, branch: &str) -> Result<String>;
fn merge_base(&self, one: Oid, two: Oid) -> Result<Oid>;
fn commits_between(&self, from: Oid, to: Oid) -> Result<Vec<Oid>>;
fn count_commits_between(&self, from: Oid, to: Oid) -> Result<usize>;
fn is_clean(&self) -> Result<bool>;
fn require_clean(&self) -> Result<()>;
fn stage_all(&self) -> Result<()>;
fn has_staged_changes(&self) -> Result<bool>;
fn create_commit(&self, message: &str) -> Result<Oid>;
fn amend_commit(&self, new_message: Option<&str>) -> Result<Oid>;
fn rebase_onto(&self, target: Oid) -> Result<()>;
fn rebase_onto_from(&self, onto: Oid, from: Oid) -> Result<()>;
fn conflicting_files(&self) -> Result<Vec<String>>;
fn predict_rebase_conflicts(
&self,
branch: &str,
onto: Oid,
) -> Result<Vec<ConflictPrediction>>;
fn rebase_abort(&self) -> Result<()>;
fn rebase_continue(&self) -> Result<()>;
fn origin_url(&self) -> Result<String>;
fn remote_divergence(&self, branch: &str) -> Result<RemoteDivergence>;
fn detect_default_branch(&self) -> Option<String>;
fn push(&self, branch: &str, force: bool) -> Result<()>;
fn fetch_all(&self) -> Result<()>;
fn fetch(&self, branch: &str) -> Result<()>;
fn pull_ff(&self) -> Result<()>;
fn reset_branch(&self, branch: &str, commit: Oid) -> Result<()>;
}Expand description
Trait for git repository operations.
This trait abstracts git operations, allowing for:
- Dependency injection in commands/services
- Mock implementations for testing
- Alternative implementations (e.g., dry-run mode)
Note: Unlike GitHubApi, git operations are synchronous since
git2 is a synchronous library.
Required Methods§
Sourcefn current_branch(&self) -> Result<String>
fn current_branch(&self) -> Result<String>
Get the current branch name.
Returns an error if HEAD is detached or not on a branch.
Sourcefn head_detached(&self) -> Result<bool>
fn head_detached(&self) -> Result<bool>
Check if HEAD is detached.
Sourcefn is_rebasing(&self) -> bool
fn is_rebasing(&self) -> bool
Check if a rebase is in progress.
Sourcefn branch_exists(&self, name: &str) -> bool
fn branch_exists(&self, name: &str) -> bool
Check if a branch exists.
Sourcefn create_branch(&self, name: &str) -> Result<Oid>
fn create_branch(&self, name: &str) -> Result<Oid>
Create a new branch at the current HEAD.
Returns the OID of the new branch’s tip commit.
Sourcefn delete_branch(&self, name: &str) -> Result<()>
fn delete_branch(&self, name: &str) -> Result<()>
Delete a local branch.
Sourcefn list_branches(&self) -> Result<Vec<String>>
fn list_branches(&self) -> Result<Vec<String>>
List all local branches.
Sourcefn branch_commit(&self, branch: &str) -> Result<Oid>
fn branch_commit(&self, branch: &str) -> Result<Oid>
Get the commit ID for a branch.
Sourcefn remote_branch_commit(&self, branch: &str) -> Result<Oid>
fn remote_branch_commit(&self, branch: &str) -> Result<Oid>
Get the commit ID for a remote branch.
Sourcefn branch_commit_message(&self, branch: &str) -> Result<String>
fn branch_commit_message(&self, branch: &str) -> Result<String>
Get the commit message for a branch’s tip.
Sourcefn commits_between(&self, from: Oid, to: Oid) -> Result<Vec<Oid>>
fn commits_between(&self, from: Oid, to: Oid) -> Result<Vec<Oid>>
Get commits between two OIDs.
Sourcefn count_commits_between(&self, from: Oid, to: Oid) -> Result<usize>
fn count_commits_between(&self, from: Oid, to: Oid) -> Result<usize>
Count commits between two OIDs.
Sourcefn require_clean(&self) -> Result<()>
fn require_clean(&self) -> Result<()>
Require that the working directory is clean.
Sourcefn has_staged_changes(&self) -> Result<bool>
fn has_staged_changes(&self) -> Result<bool>
Check if there are staged changes.
Sourcefn create_commit(&self, message: &str) -> Result<Oid>
fn create_commit(&self, message: &str) -> Result<Oid>
Create a commit with the staged changes.
Sourcefn amend_commit(&self, new_message: Option<&str>) -> Result<Oid>
fn amend_commit(&self, new_message: Option<&str>) -> Result<Oid>
Amend the last commit with staged changes.
Sourcefn rebase_onto(&self, target: Oid) -> Result<()>
fn rebase_onto(&self, target: Oid) -> Result<()>
Rebase the current branch onto a target commit.
Sourcefn rebase_onto_from(&self, onto: Oid, from: Oid) -> Result<()>
fn rebase_onto_from(&self, onto: Oid, from: Oid) -> Result<()>
Rebase using –onto semantics (rebase commits from from onto onto).
Sourcefn conflicting_files(&self) -> Result<Vec<String>>
fn conflicting_files(&self) -> Result<Vec<String>>
Get files with conflicts during a rebase.
Sourcefn predict_rebase_conflicts(
&self,
branch: &str,
onto: Oid,
) -> Result<Vec<ConflictPrediction>>
fn predict_rebase_conflicts( &self, branch: &str, onto: Oid, ) -> Result<Vec<ConflictPrediction>>
Predict conflicts that would occur when rebasing a branch onto a target.
Returns a list of commits that would cause conflicts along with the conflicting files. An empty list means no conflicts are predicted.
Sourcefn rebase_abort(&self) -> Result<()>
fn rebase_abort(&self) -> Result<()>
Abort a rebase in progress.
Sourcefn rebase_continue(&self) -> Result<()>
fn rebase_continue(&self) -> Result<()>
Continue a rebase after resolving conflicts.
Sourcefn origin_url(&self) -> Result<String>
fn origin_url(&self) -> Result<String>
Get the origin URL.
Sourcefn remote_divergence(&self, branch: &str) -> Result<RemoteDivergence>
fn remote_divergence(&self, branch: &str) -> Result<RemoteDivergence>
Check divergence between local and remote branch.
Sourcefn detect_default_branch(&self) -> Option<String>
fn detect_default_branch(&self) -> Option<String>
Detect the default branch (main/master).
Returns None if neither main nor master exists.