Skip to main content

GitBackend

Trait GitBackend 

Source
pub trait GitBackend: Send + Sync {
    // Required methods
    fn is_repo(&self, root: &Path) -> Result<bool>;
    fn repo_root(&self, root: &Path) -> Result<PathBuf>;
    fn head(&self, root: &Path) -> Result<Option<String>>;
    fn uncommitted(
        &self,
        root: &Path,
        include_untracked: bool,
    ) -> Result<(ChangeSet, Option<String>)>;
    fn since(
        &self,
        root: &Path,
        baseline: &str,
        rename_similarity: u8,
    ) -> Result<(ChangeSet, Option<String>)>;

    // Provided method
    fn capabilities(&self) -> GitCapabilities { ... }
}
Expand description

Git backend abstraction for change detection

This trait provides a consistent interface for different git backend implementations (subprocess, libgit2, etc.).

Required Methods§

Source

fn is_repo(&self, root: &Path) -> Result<bool>

Check if the path is a git repository

Returns Ok(true) if path is a git repo, Ok(false) otherwise. Returns Err for permission errors or IO failures to surface them instead of silently falling back.

§Errors

Propagates GitError when repository detection fails (for example, when the directory cannot be accessed or git is unavailable).

Source

fn repo_root(&self, root: &Path) -> Result<PathBuf>

Get the repository root path

This handles git worktrees correctly (where .git is a file pointing to the actual git directory).

Returns the canonicalized absolute path to the repository root.

§Errors

Returns GitError when git metadata cannot be inspected or when the path cannot be canonicalized.

Source

fn head(&self, root: &Path) -> Result<Option<String>>

Get the current HEAD commit SHA

Returns Ok(Some(sha)) for repos with commits. Returns Ok(None) for newly initialized repos without commits. Returns Err for permission errors or command failures.

§Errors

Returns GitError when invoking git fails or when the output cannot be parsed.

Source

fn uncommitted( &self, root: &Path, include_untracked: bool, ) -> Result<(ChangeSet, Option<String>)>

Get uncommitted changes (index + working tree)

Returns a tuple of (ChangeSet, current_head) to avoid race conditions between querying changes and querying HEAD separately.

§Arguments
  • root - Repository root path
  • include_untracked - Whether to include untracked files
§Returns
  • ChangeSet - Files changed in index and working tree
  • Option<String> - Current HEAD commit SHA (None if no commits)
§Errors

Returns GitError when git commands fail, time out, or output parsing detects malformed entries.

Source

fn since( &self, root: &Path, baseline: &str, rename_similarity: u8, ) -> Result<(ChangeSet, Option<String>)>

Get changes since a baseline commit

Returns a tuple of (ChangeSet, current_head) to avoid race conditions between diff and HEAD query.

§Arguments
  • root - Repository root path
  • baseline - Baseline commit SHA to compare against
  • rename_similarity - Rename detection threshold (0-100)
§Returns
  • ChangeSet - Files changed between baseline and HEAD
  • Option<String> - Current HEAD commit SHA (None if no commits)
§Errors

Returns Err if baseline commit doesn’t exist (e.g., shallow clone where baseline was pruned). Caller should fall back to hash-based.

Provided Methods§

Source

fn capabilities(&self) -> GitCapabilities

Get backend-specific capabilities

This allows backends to advertise optional features like blame, time-travel indexing, etc. Used for enterprise features.

Implementors§