Skip to main content

report

Function report 

Source
pub fn report(root: &Path) -> Result<ConvergenceReport>
Expand description

Measure the repository holding root.

One topology read (the same service the hooks and the Cockpit ask), one git rev-list for the commits no remote reaches, one git stash list. Nothing here writes, and nothing here reaches the network: a remote-tracking ref is what this checkout last fetched, which is exactly the question — whether the work left this disk, not whether the remote still has it.

use std::process::Command;
use majordomus_cli::convergence::{report, Disposition};

let dir = std::env::temp_dir().join(format!("mj-convergence-doc-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
let git = |args: &[&str]| {
    let ok = Command::new("git").current_dir(&dir).args(args).status().unwrap().success();
    assert!(ok, "git {args:?}");
};
git(&["init", "-q", "-b", "master"]);
let commit = |msg: &str| git(&["-c", "user.email=d@example.com", "-c", "user.name=doc",
                               "commit", "-q", "--allow-empty", "-m", msg]);
commit("base");
git(&["checkout", "-q", "-b", "feature/doc"]);
commit("work nobody else has");
git(&["checkout", "-q", "master"]);

// a commit on a branch the trunk does not reach and no remote has seen is on one disk
let verdict = report(&dir).unwrap();
assert!(!verdict.converged);
assert!(verdict.holdings.iter().any(|h| h.disposition == Disposition::LocalOnly));

// and a file never committed is the other half
std::fs::write(dir.join("draft.txt"), "half written").unwrap();
let verdict = report(&dir).unwrap();
assert!(verdict.holdings.iter().any(|h| h.disposition == Disposition::Uncommitted));
std::fs::remove_dir_all(&dir).unwrap();