Skip to main content

layer_is_untracked

Function layer_is_untracked 

Source
pub fn layer_is_untracked(root: &Path) -> bool
Expand description

Whether git has never been given the layer under root: its manifest is on disk and the index holds no entry for it.

The manifest stands for the layer because nothing reads a layer without it, and a repository that tracks its layer tracks that file first. It is asked of git each time rather than recorded anywhere, so a layer that is committed later is read through the index from that moment and nobody has to change a setting. A repository git cannot describe answers false: the caller’s own handling of an unavailable git stands.

use majordomus_cli::discovery::layer_is_untracked;
use std::process::Command;

let dir = tempfile::tempdir().unwrap();
let git = |args: &[&str]| {
    Command::new("git").arg("-C").arg(dir.path()).args(args).output().unwrap()
};
git(&["init", "-q"]);
std::fs::create_dir(dir.path().join(".ai")).unwrap();
std::fs::write(dir.path().join(".ai/manifest.yaml"), "schema: manifest/v1\n").unwrap();
assert!(layer_is_untracked(dir.path()), "on disk, and git was never given it");

git(&["add", ".ai/manifest.yaml"]);
assert!(!layer_is_untracked(dir.path()), "staged is tracked: the index holds it");

let bare = tempfile::tempdir().unwrap();
assert!(!layer_is_untracked(bare.path()), "no manifest, no layer to call untracked");