Skip to main content

GitOps

Trait GitOps 

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

Source

fn workdir(&self) -> Option<&Path>

Get the working directory path.

Source

fn current_branch(&self) -> Result<String>

Get the current branch name.

Returns an error if HEAD is detached or not on a branch.

Source

fn head_detached(&self) -> Result<bool>

Check if HEAD is detached.

Source

fn is_rebasing(&self) -> bool

Check if a rebase is in progress.

Source

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

Check if a branch exists.

Source

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.

Source

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

Checkout a branch.

Source

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

Delete a local branch.

Source

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

List all local branches.

Source

fn branch_commit(&self, branch: &str) -> Result<Oid>

Get the commit ID for a branch.

Source

fn remote_branch_commit(&self, branch: &str) -> Result<Oid>

Get the commit ID for a remote branch.

Source

fn branch_commit_message(&self, branch: &str) -> Result<String>

Get the commit message for a branch’s tip.

Source

fn merge_base(&self, one: Oid, two: Oid) -> Result<Oid>

Find the merge base of two commits.

Source

fn commits_between(&self, from: Oid, to: Oid) -> Result<Vec<Oid>>

Get commits between two OIDs.

Source

fn count_commits_between(&self, from: Oid, to: Oid) -> Result<usize>

Count commits between two OIDs.

Source

fn is_clean(&self) -> Result<bool>

Check if the working directory is clean.

Source

fn require_clean(&self) -> Result<()>

Require that the working directory is clean.

Source

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

Stage all changes.

Source

fn has_staged_changes(&self) -> Result<bool>

Check if there are staged changes.

Source

fn create_commit(&self, message: &str) -> Result<Oid>

Create a commit with the staged changes.

Source

fn amend_commit(&self, new_message: Option<&str>) -> Result<Oid>

Amend the last commit with staged changes.

Source

fn rebase_onto(&self, target: Oid) -> Result<()>

Rebase the current branch onto a target commit.

Source

fn rebase_onto_from(&self, onto: Oid, from: Oid) -> Result<()>

Rebase using –onto semantics (rebase commits from from onto onto).

Source

fn conflicting_files(&self) -> Result<Vec<String>>

Get files with conflicts during a rebase.

Source

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.

Source

fn rebase_abort(&self) -> Result<()>

Abort a rebase in progress.

Source

fn rebase_continue(&self) -> Result<()>

Continue a rebase after resolving conflicts.

Source

fn origin_url(&self) -> Result<String>

Get the origin URL.

Source

fn remote_divergence(&self, branch: &str) -> Result<RemoteDivergence>

Check divergence between local and remote branch.

Source

fn detect_default_branch(&self) -> Option<String>

Detect the default branch (main/master).

Returns None if neither main nor master exists.

Source

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

Push a branch to the remote.

Source

fn fetch_all(&self) -> Result<()>

Fetch all remotes.

Source

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

Fetch a specific branch.

Source

fn pull_ff(&self) -> Result<()>

Pull with fast-forward only.

Source

fn reset_branch(&self, branch: &str, commit: Oid) -> Result<()>

Reset a branch to a specific commit.

Implementors§