Git operations for skill management — clone, fetch, checkout, and compute directory checksums.
clone_or_fetch
pub fn clone_or_fetch(url: &str, target: &Path) -> Result<()>
Clone a git repository to a target directory. If it already exists, fetch updates.
checkout
pub fn checkout(repo_path: &Path, rev: &str) -> Result<()>
Checkout a specific ref (branch, tag, or commit SHA).
head_commit
pub fn head_commit(repo_path: &Path) -> Result<String>
Get the current HEAD commit SHA.
resolve_commit
pub fn resolve_commit(repo: &Path, revision: Option<&str>) -> Result<String>
Resolve a fetched revision without changing the cache’s HEAD or working tree. Branch pins use the fetched remote branch rather than a stale local branch.
snapshot
pub fn snapshot(repo: &Path, commit: &str, revisions: &Path) -> Result<PathBuf>
Materialize a commit once, then reuse its independent detached checkout. Local clones hardlink object files where possible, but do not use alternates: pruning the mutable fetch cache cannot invalidate an installed revision. Publish by rename only after checkout succeeds, so interrupted installs never leave a partially populated deployment that another install can reuse.
checksum_dir
pub fn checksum_dir(dir: &Path) -> Result<String>
Compute a SHA-256 checksum of a directory’s contents (all files, sorted).
default_branch
pub fn default_branch(repo_path: &Path) -> Result<String>
Get the default branch name for a repo by checking origin/HEAD or falling back
to symbolic-ref HEAD.
reset_to_remote_head
pub fn reset_to_remote_head(repo_path: &Path) -> Result<()>
Reset the working tree to the remote’s default branch HEAD.
Call this after clone_or_fetch() to advance to the latest commit.