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§
Sourcefn is_repo(&self, root: &Path) -> Result<bool>
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).
Sourcefn uncommitted(
&self,
root: &Path,
include_untracked: bool,
) -> Result<(ChangeSet, Option<String>)>
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 pathinclude_untracked- Whether to include untracked files
§Returns
ChangeSet- Files changed in index and working treeOption<String>- Current HEAD commit SHA (None if no commits)
§Errors
Returns GitError when git commands fail, time out, or output parsing
detects malformed entries.
Sourcefn since(
&self,
root: &Path,
baseline: &str,
rename_similarity: u8,
) -> Result<(ChangeSet, Option<String>)>
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 pathbaseline- Baseline commit SHA to compare againstrename_similarity- Rename detection threshold (0-100)
§Returns
ChangeSet- Files changed between baseline and HEADOption<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§
Sourcefn capabilities(&self) -> GitCapabilities
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.