Skip to main content

Module repository

Module repository 

Source
Expand description

Repository discovery: the nearest ancestor of the start directory that carries .ai/manifest.yaml is the root, and the manifest is the only thing read to find it.

.git is not a marker: an arbitrary git repository is not a Majordomus repository. A .majordomus/ directory is not a marker either; it is an optional installation of the tool, or the pre-.ai layout, which is refused by name.

§Why the marker is the manifest

Every other candidate marker is ambiguous. .git says a directory is version controlled, which almost every directory a person runs this in will be; a .ai directory alone says nothing about whether it is this layer. The manifest declares its own schema, so discovery either finds a layer this executable can read or it says which schema it found and which it reads — never a half-open repository.

§Errors

crate::Error::RepositoryNotFound when no ancestor carries the manifest, naming where the search began; crate::Error::LegacyLayout when it finds the pre-.ai layout, naming the migration; and the manifest’s own parse and schema errors, each naming the file. None of them is a diagnostic: without a manifest nothing can be discovered at all.

use majordomus_cli::Repository;

// a directory that is not a repository is an error that says where it looked
let empty = tempfile::tempdir().unwrap();
let err = Repository::discover(empty.path()).unwrap_err();
assert!(matches!(err, majordomus_cli::Error::RepositoryNotFound { .. }));
assert_eq!(err.exit_code(), 12, "the code for something that is not there");

// and a git repository is not one either: the marker is the manifest and nothing else
std::fs::create_dir(empty.path().join(".git")).unwrap();
assert!(Repository::discover(empty.path()).is_err());

Structs§

ContextConventions
The scoped context documents: file names that must carry the context contract (schema: context/v1) wherever they appear under the layer.
GitIdentity
The git repository a checkout belongs to, as distinct from the checkout itself.
LocalHalf
The checkout-local half of the layer, never a source.
Manifest
.ai/manifest.yaml, typed. Unknown keys are refused through share/allow/manifest.txt.
RepoHalf
The tracked half of the layer.
Repository
A located repository with its manifest read.

Constants§

LAYER_SCHEMA
The layer schema this executable reads.
MANIFEST
The file whose presence makes a directory the root of a Majordomus repository.

Functions§

branch_at
The branch the checkout at root has checked out, read from its HEAD file instead of asked of a subprocess. None when HEAD is detached, when the file cannot be read, or when root is not a checkout at all — the same three silences git symbolic-ref -q --short HEAD answers with, at the cost of at most two small reads.
git_identity
Ask git which repository the checkout at root belongs to. One subprocess; None when git is absent or the root is not a work tree.
identity
A repository’s identity over the wire: a digest of its absolute root.