Skip to main content

GitOps

Trait GitOps 

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

Source

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.

Source

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.

Source

fn worktree_prune(&self) -> Result<(), CoreError>

Prunes stale worktree bookkeeping entries.

Equivalent to git worktree prune.

§Errors

Returns CoreError::GitError if the command fails.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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".

Implementors§