Skip to main content

Module gitio

Module gitio 

Source
Expand description

Pure-Rust git helpers (via gix). The single home for read-side git inspection so the rest of the crate never shells out to the git binary. No std::process::Command, no libgit2/C — matches nornir’s pure-Rust ethos (gix over libgit2, like ureq over curl).

Write/network release operations (commit-on-release, push) live in nornir’s release::publish. The write helpers here — init and commit_all — exist only to build new repositories from scratch (test fixtures and the synthetic-repo generator) without ever shelling out; they use a fixed, deterministic identity so fixtures are reproducible and need no ambient git config.

Structs§

LocalPushReport
Outcome of a push_to_local_remote.
WorktreeFreshness
A working-tree freshness reading: whether the tree is dirty and a stable content digest of the porcelain status (AUT6 / freshness gate).

Constants§

CLEAN_WORKTREE_DIGEST
Sentinel digest for a clean working tree (no tracked modifications, nothing staged, no untracked files). A fixed string so clients can test it without recomputing a hash of the empty set.

Functions§

clone_or_fetch
Ensure dest is an up-to-date clone of url: clone if absent, else fetch. Returns the resulting HEAD SHA. SSH remotes use the deploy key at ssh_key (resolved via nornir_ssh_key_path when None).
commit_all
Snapshot the entire working tree (every file except those under .git/) into a new commit on HEAD, returning the commit SHA.
head_branch
Short branch name for HEAD, or "(detached)" when detached. gix-first, git symbolic-ref fallback (see head_sha).
head_sha
Full 40-char hex SHA of the commit HEAD points at.
head_sha_and_branch
(sha, branch) for HEAD. gix-first, git-fallback for each half (see head_sha).
https_to_ssh
Rewrite an https://host/owner/repo(.git) (or http://) URL to its scp-like SSH form git@host:owner/repo.git. Returns None when url isn’t a plain http(s) URL with both a host and a path we can rewrite. Used to prefer SSH (deploy-key, no credential prompt) over https for private remotes.
init
Initialise a fresh git repository at root (pure-Rust via gix). The directory is created if missing. Used by test fixtures and the synthetic-repo generator so setup code is also free of git subprocesses.
is_ssh_url
true for SSH-style remotes (git@host:… or ssh://…).
nornir_ssh_key_path
Resolve the deploy-key path the server uses for git-over-SSH. Mirrors the CLI’s nornir key resolution: honors NORNIR_SSH_DIR, else the nornir system user’s home (/home/nornir/.ssh), else a per-user dev location that never touches the operator’s own ~/.ssh. Returns the private key path only if it exists.
push_to_local_remote
Fast-forward PUSH to a LOCAL/file git remote, pure-Rust (no send-pack).
set_head_and_checkout
Point an existing clone at branch (→ commit sha) and materialize its worktree from that commit. Pure-gix (no shell-out): updates refs/heads/ <branch> + HEAD, then writes the tree onto disk. branch is the SHORT name (e.g. main); sha its peeled commit. Used by the fat auto-materialize path to honor a member’s pinned branch after a default-HEAD clone.
tag_commit_sha
Commit SHA the tag refs/tags/<tag> resolves to, peeling annotated tags down to their target commit. Ok(None) if the tag is absent.
tag_lightweight
Create a lightweight tag refs/tags/<name> pointing at target_sha. Pure-gix (no shell). Fails if the tag already exists.
tag_points_at_head
True iff refs/tags/<tag> exists and (after peeling) points at the same commit as HEAD.
worktree_freshness
Compute the working-tree freshness of the repo at root, in-process via gix (no shelling out to the git binary).