Expand description
A minimal, optional, read-only view of git.
Where the work tree is, what HEAD is, and which tracked files match a pathspec — and
nothing else. Everything shells out to the git binary; no library is linked, nothing
is written, and GitHub is not involved at any point.
§Optional means optional
Every function here answers when git is absent, when the directory is not a repository,
and when the repository has no commits. inspect returns a GitState that says
which of those it is rather than an error, because a repository of the layer does not
have to be version controlled — discovery falls back to a filesystem walk with the same
glob semantics, and the index says which mode it used.
use majordomus_cli::git::{inspect, GitState};
// a directory that is not a work tree is a state with a reason, not a failure
let plain = tempfile::tempdir().unwrap();
match inspect(plain.path()) {
GitState::Unavailable { reason } => assert!(!reason.is_empty(), "it says why"),
GitState::Available(_) => panic!("a fresh temporary directory is not a work tree"),
}Structs§
- GitInfo
- What
gitsaid about the repository.
Enums§
- Containment
- Whether one commit contains another: three answers, because “no” and “this clone cannot say” send a reader to different places.
- GitState
- What git says about the repository, or why it could not be asked.
Functions§
- contains
- Does
descendantcontainancestor? - inspect
- Ask git about
root. Never fails: a missinggitor a directory that is not a work tree becomesGitState::Unavailablewith the reason. - is_
ancestor - Is
ancestorreachable fromdescendant?Nonewhen git cannot answer at all — a missing executable, a commit this clone does not have — which is a third answer and not afalse: “not an ancestor” and “unknown ancestry” lead a reader to different actions, and collapsing them is how a record from a rewritten history gets read as current. - ls_
files - Tracked files under
rootmatching one pathspec, repository-relative, in the byte order the index keeps them in. The pathspec is passed to git verbatim. - ls_
files_ all - Every tracked file under
root, repository-relative, in the byte order the index keeps them in: one subprocess per build, matched against each class’s pathspec in process. - ls_
files_ any - Tracked files under
rootmatching any of several pathspecs, repository-relative, in the byte order the index keeps them in — one subprocess, one pass, each file once. - read_
only - A
gitinvocation againstrootthat only ever reads: the one constructor every read in this crate goes through. - resolves
- Does
revname a commit this clone has? - working_
tree_ excluding clean,dirtyorunknown, asworking_tree_ignoringdecides it, except that an untracked path equal to one ofoutputs, or under one of them, is not a change either. An output never hides a tracked change.- working_
tree_ ignoring clean,dirtyorunknownasinspectdecides it, except that a change to one of the given repository-relative paths does not make the tree dirty.