pub fn ledger_at(root: &Path, commit: &str) -> Result<Ledger, Error>Expand description
The ledger as commit holds it: git show <commit>:.ai/repo/evidence/ledger.json.
A commit that holds no ledger has an empty one, as a repository with no ledger file does. A commit this clone does not have is an error, not an empty ledger: “nothing recorded” and “nothing to read” are different answers.
use majordomus_cli::evidence::freshness::ledger_at;
use majordomus_cli::evidence::Ledger;
use std::process::Command;
let dir = tempfile::tempdir().unwrap();
let git = |args: &[&str]| {
let out = Command::new("git").arg("-C").arg(dir.path()).args(args).output().unwrap();
String::from_utf8_lossy(&out.stdout).trim().to_string()
};
git(&["init", "-q"]);
git(&["config", "user.email", "t@example.com"]);
git(&["config", "user.name", "t"]);
git(&["commit", "-q", "--allow-empty", "-m", "nothing recorded yet"]);
let head = git(&["rev-parse", "HEAD"]);
assert_eq!(ledger_at(dir.path(), &head).unwrap(), Ledger::empty());
assert!(ledger_at(dir.path(), &"0".repeat(40)).is_err());