pub trait GitOps: Send + Sync {
// Required methods
fn worktree_add(
&self,
path: &Path,
branch: &str,
base: &str,
) -> Result<(), CoreError>;
fn worktree_remove(&self, path: &Path, force: bool) -> Result<(), CoreError>;
fn worktree_prune(&self) -> Result<(), CoreError>;
fn branch_delete(&self, branch: &str) -> Result<(), CoreError>;
fn add(&self, cwd: &Path, paths: &[&str]) -> Result<(), CoreError>;
fn has_staged_changes(&self, cwd: &Path) -> bool;
fn commit(&self, cwd: &Path, message: &str) -> Result<(), CoreError>;
fn diff(&self, cwd: &Path, base: &str) -> Result<String, CoreError>;
fn log_oneline(&self, cwd: &Path, range: &str) -> Result<String, CoreError>;
fn push(&self, cwd: &Path, branch: &str) -> Result<(), CoreError>;
fn detect_default_branch(&self) -> String;
}Expand description
Abstraction over git CLI operations.
All path-taking methods expect absolute paths unless noted otherwise.
Implementations must be Send + Sync so they can be shared across async
tasks.
Required Methods§
Sourcefn worktree_add(
&self,
path: &Path,
branch: &str,
base: &str,
) -> Result<(), CoreError>
fn worktree_add( &self, path: &Path, branch: &str, base: &str, ) -> Result<(), CoreError>
Creates a worktree at path on a new branch forked from base.
Equivalent to git worktree add <path> -b <branch> <base>.
§Errors
Returns CoreError::GitError if the command fails.
Sourcefn worktree_remove(&self, path: &Path, force: bool) -> Result<(), CoreError>
fn worktree_remove(&self, path: &Path, force: bool) -> Result<(), CoreError>
Removes a worktree.
Equivalent to git worktree remove <path> [--force].
§Errors
Returns CoreError::GitError if the command fails.
Sourcefn worktree_prune(&self) -> Result<(), CoreError>
fn worktree_prune(&self) -> Result<(), CoreError>
Prunes stale worktree bookkeeping entries.
Equivalent to git worktree prune.
§Errors
Returns CoreError::GitError if the command fails.
Sourcefn branch_delete(&self, branch: &str) -> Result<(), CoreError>
fn branch_delete(&self, branch: &str) -> Result<(), CoreError>
Deletes a local branch.
Equivalent to git branch -D <branch>.
§Errors
Returns CoreError::GitError if the command fails.
Sourcefn add(&self, cwd: &Path, paths: &[&str]) -> Result<(), CoreError>
fn add(&self, cwd: &Path, paths: &[&str]) -> Result<(), CoreError>
Stages files.
Equivalent to git add <paths...> run inside cwd.
§Errors
Returns CoreError::GitError if the command fails.
Sourcefn has_staged_changes(&self, cwd: &Path) -> bool
fn has_staged_changes(&self, cwd: &Path) -> bool
Returns whether the staging area has changes.
Equivalent to git diff --cached --quiet (returns true when dirty).
Sourcefn commit(&self, cwd: &Path, message: &str) -> Result<(), CoreError>
fn commit(&self, cwd: &Path, message: &str) -> Result<(), CoreError>
Creates a commit with the given message.
Equivalent to git commit -m <message> run inside cwd.
§Errors
Returns CoreError::GitError if the command fails.
Sourcefn diff(&self, cwd: &Path, base: &str) -> Result<String, CoreError>
fn diff(&self, cwd: &Path, base: &str) -> Result<String, CoreError>
Returns the diff between base and HEAD.
Equivalent to git diff <base> HEAD run inside cwd.
§Errors
Returns CoreError::GitError if the command fails.
Sourcefn log_oneline(&self, cwd: &Path, range: &str) -> Result<String, CoreError>
fn log_oneline(&self, cwd: &Path, range: &str) -> Result<String, CoreError>
Returns one-line log entries for commits in range.
Equivalent to git log <range> --oneline --no-decorate inside cwd.
§Errors
Returns CoreError::GitError if the command fails.
Sourcefn push(&self, cwd: &Path, branch: &str) -> Result<(), CoreError>
fn push(&self, cwd: &Path, branch: &str) -> Result<(), CoreError>
Pushes the current branch to origin.
Equivalent to git push origin <branch> run inside cwd.
§Errors
Returns CoreError::GitError if the command fails.
Sourcefn detect_default_branch(&self) -> String
fn detect_default_branch(&self) -> String
Detects the repository’s default branch.
Queries git symbolic-ref refs/remotes/origin/HEAD --short and
strips the origin/ prefix. Falls back to "main".