Skip to main content

GitOperations

Trait GitOperations 

Source
pub trait GitOperations: Send + Sync {
    // Required methods
    fn clone_repo(
        &self,
        url: &str,
        target: &Path,
        options: &CloneOptions,
    ) -> Result<(), GitError>;
    fn fetch(&self, repo_path: &Path) -> Result<FetchResult, GitError>;
    fn pull(&self, repo_path: &Path) -> Result<PullResult, GitError>;
    fn status(&self, repo_path: &Path) -> Result<RepoStatus, GitError>;
    fn is_repo(&self, path: &Path) -> bool;
    fn current_branch(&self, repo_path: &Path) -> Result<String, GitError>;
    fn remote_url(
        &self,
        repo_path: &Path,
        remote: &str,
    ) -> Result<String, GitError>;
    fn recent_commits(
        &self,
        repo_path: &Path,
        limit: usize,
    ) -> Result<Vec<String>, GitError>;
}
Expand description

Trait for git operations.

This trait abstracts git commands to allow for testing with mocks.

Required Methods§

Source

fn clone_repo( &self, url: &str, target: &Path, options: &CloneOptions, ) -> Result<(), GitError>

Clones a repository to the target path.

§Arguments
  • url - The clone URL (SSH or HTTPS)
  • target - Target directory path
  • options - Clone options (depth, branch, submodules)
Source

fn fetch(&self, repo_path: &Path) -> Result<FetchResult, GitError>

Fetches updates from the remote.

§Arguments
  • repo_path - Path to the local repository
Source

fn pull(&self, repo_path: &Path) -> Result<PullResult, GitError>

Pulls updates from the remote.

§Arguments
  • repo_path - Path to the local repository
Source

fn status(&self, repo_path: &Path) -> Result<RepoStatus, GitError>

Gets the status of a local repository.

§Arguments
  • repo_path - Path to the local repository
Source

fn is_repo(&self, path: &Path) -> bool

Checks if a directory is a git repository.

§Arguments
  • path - Path to check
Source

fn current_branch(&self, repo_path: &Path) -> Result<String, GitError>

Gets the current branch name.

§Arguments
  • repo_path - Path to the local repository
Source

fn remote_url(&self, repo_path: &Path, remote: &str) -> Result<String, GitError>

Gets the remote URL for a repository.

§Arguments
  • repo_path - Path to the local repository
  • remote - Remote name (default: “origin”)
Source

fn recent_commits( &self, repo_path: &Path, limit: usize, ) -> Result<Vec<String>, GitError>

Gets recent commits as one-line summaries.

§Arguments
  • repo_path - Path to the local repository
  • limit - Maximum number of commits to return

Implementors§