Skip to main content

GitBackend

Trait GitBackend 

Source
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§

Source

fn name(&self) -> &'static str

Short human-readable name of the backend, e.g. "gix". Used in logs and diagnostics; not parsed programmatically.

Source

fn clone( &self, url: &str, dest: &Path, ref: Option<&str>, ) -> Result<ClonedRepo, GitError>

Clone url into dest.

§Contract
  • If dest exists and is non-empty → GitError::DestinationNotEmpty.
  • If r#ref is Some, check out that ref after the clone finishes.
  • If r#ref is None, 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.

Source

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.

Source

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
Source

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.

Implementors§