pub trait GitBackend: Send + Sync {
// Required methods
fn name(&self) -> &'static str;
fn clone(
&self,
url: &str,
dest: &Path,
ref: Option<&str>,
) -> Result<ClonedRepo, GitError>;
fn fetch(&self, dest: &Path) -> Result<(), GitError>;
fn checkout(&self, dest: &Path, ref: &str) -> Result<(), GitError>;
fn head_sha(&self, dest: &Path) -> Result<String, GitError>;
}Expand description
Stable surface for all git operations grex needs.
Implementors must be Send + Sync so a single instance can be handed to
the scheduler as Arc<dyn GitBackend>. All methods are synchronous — the
slice 3 design deliberately avoids async to keep the trait object-safe and
the default backend runtime-free.
Errors are carried as GitError; the enum is #[non_exhaustive] so
future variants (credentials, submodules, …) won’t break implementors.
Required Methods§
Sourcefn name(&self) -> &'static str
fn name(&self) -> &'static str
Short human-readable name of the backend, e.g. "gix". Used in logs
and diagnostics; not parsed programmatically.
Sourcefn clone(
&self,
url: &str,
dest: &Path,
ref: Option<&str>,
) -> Result<ClonedRepo, GitError>
fn clone( &self, url: &str, dest: &Path, ref: Option<&str>, ) -> Result<ClonedRepo, GitError>
Clone url into dest.
§Contract
- If
destexists and is non-empty →GitError::DestinationNotEmpty. - If
r#refisSome, check out that ref after the clone finishes. - If
r#refisNone, leave the working tree on the remote’s default HEAD.
§Errors
Any clone-, network-, or checkout-layer failure maps to a
GitError variant — see that enum for the taxonomy.
Sourcefn fetch(&self, dest: &Path) -> Result<(), GitError>
fn fetch(&self, dest: &Path) -> Result<(), GitError>
Fetch from the default remote (origin) into an existing repo at
dest. Leaves the working tree untouched.
§Errors
Returns GitError::NotARepository when dest is not a git repo,
or GitError::FetchFailed on any network- or ref-update failure.
Sourcefn checkout(&self, dest: &Path, ref: &str) -> Result<(), GitError>
fn checkout(&self, dest: &Path, ref: &str) -> Result<(), GitError>
Resolve r#ref (branch, tag, or SHA) and update the working tree at
dest to match. Refuses to run if the working tree has uncommitted
changes.
§Errors
GitError::NotARepositorywhendestis not a git repo.GitError::DirtyWorkingTreewhen there are uncommitted changes.GitError::RefNotFoundwhen the ref cannot be resolved.GitError::CheckoutFailedfor any other checkout-layer failure.
Sourcefn head_sha(&self, dest: &Path) -> Result<String, GitError>
fn head_sha(&self, dest: &Path) -> Result<String, GitError>
Return HEAD at dest as a 40-char lowercase hex SHA.
§Errors
GitError::NotARepository when dest is not a git repo;
GitError::Internal wraps any unexpected head-resolution failure.