Skip to main content

Module git

Module git 

Source
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 git said 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 descendant contain ancestor?
inspect
Ask git about root. Never fails: a missing git or a directory that is not a work tree becomes GitState::Unavailable with the reason.
is_ancestor
Is ancestor reachable from descendant? None when git cannot answer at all — a missing executable, a commit this clone does not have — which is a third answer and not a false: “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 root matching 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 root matching 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 git invocation against root that only ever reads: the one constructor every read in this crate goes through.
resolves
Does rev name a commit this clone has?
working_tree_excluding
clean, dirty or unknown, as working_tree_ignoring decides it, except that an untracked path equal to one of outputs, or under one of them, is not a change either. An output never hides a tracked change.
working_tree_ignoring
clean, dirty or unknown as inspect decides it, except that a change to one of the given repository-relative paths does not make the tree dirty.