pub trait GitBackend: Send + Sync {
// Required methods
fn name(&self) -> &'static str;
fn clone(
&self,
url: &str,
dest: &Path,
ref: Option<&str>,
lock_ctx: BackendLockCtx<'_>,
) -> Result<ClonedRepo, GitError>;
fn fetch(
&self,
dest: &Path,
lock_ctx: BackendLockCtx<'_>,
) -> Result<(), GitError>;
fn checkout(
&self,
dest: &Path,
ref: &str,
lock_ctx: BackendLockCtx<'_>,
) -> 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>,
lock_ctx: BackendLockCtx<'_>,
) -> Result<ClonedRepo, GitError>
fn clone( &self, url: &str, dest: &Path, ref: Option<&str>, lock_ctx: BackendLockCtx<'_>, ) -> 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.
lock_ctx carries (parent_meta, child_path) so the backend can
compute the per-repo lock path under <parent_meta>/.grex/locks/
(v1.3.2 B11). Implementations that do not lock may ignore the
argument.
§Errors
Any clone-, network-, or checkout-layer failure maps to a
GitError variant — see that enum for the taxonomy.
Sourcefn fetch(
&self,
dest: &Path,
lock_ctx: BackendLockCtx<'_>,
) -> Result<(), GitError>
fn fetch( &self, dest: &Path, lock_ctx: BackendLockCtx<'_>, ) -> Result<(), GitError>
Fetch from the default remote (origin) into an existing repo at
dest. Leaves the working tree untouched.
lock_ctx carries the parent-meta + child-path so the per-repo
lock can be computed under <parent_meta>/.grex/locks/ (v1.3.2 B11).
§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,
lock_ctx: BackendLockCtx<'_>,
) -> Result<(), GitError>
fn checkout( &self, dest: &Path, ref: &str, lock_ctx: BackendLockCtx<'_>, ) -> 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.
lock_ctx carries the parent-meta + child-path so the per-repo
lock can be computed under <parent_meta>/.grex/locks/ (v1.3.2 B11).
§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.