Skip to main content

presented_commit

Function presented_commit 

Source
pub fn presented_commit(
    root: &Path,
    rev: &str,
    given: Option<TreeState>,
) -> Result<Presented, String>
Expand description

The checked-out commit, presented as committed.

rev must name the commit that is checked out: the claims matrix, the tests’ sources and the digests a verdict reads come from the checkout, so a verdict “at” some other commit would mix two trees. The tree is measured, ignoring the evidence ledger’s working copy — the ledger is read from the commit, so its working copy is not part of what is judged — and given can only weaken what was measured.

use majordomus_cli::evidence::freshness::{presented_commit, TreeState};
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"]);
git(&["config", "user.email", "t@example.com"]);
git(&["config", "user.name", "t"]);
git(&["commit", "-q", "--allow-empty", "-m", "one"]);

assert_eq!(presented_commit(dir.path(), "HEAD", None).unwrap().tree(), TreeState::Clean);
// a caller that knows better can weaken it
let told = presented_commit(dir.path(), "HEAD", Some(TreeState::Dirty)).unwrap();
assert_eq!(told.tree(), TreeState::Dirty);
// a revision that names nothing is refused, and the refusal names it
let refused = presented_commit(dir.path(), "no-such-branch", None).unwrap_err();
assert!(refused.contains("no-such-branch"), "{refused}");