mod loss;
mod refs;
use super::super::*;
use std::fs;
use std::time::Duration;
use tempfile::tempdir;
const DETECT: Duration = Duration::from_secs(5);
const POLL: Duration = Duration::from_millis(25);
fn wait_for(watcher: &Watcher, pred: impl Fn(&Change) -> bool) -> Vec<Change> {
let probe = || {
let changes = watcher.tick();
changes.iter().any(&pred).then_some(changes)
};
super::poll_until(probe, DETECT, POLL).unwrap_or_default()
}
fn git(dir: &Path, args: &[&str]) -> String {
let out = crate::git_env::output(
crate::git_env::git()
.args(args)
.current_dir(dir)
.env("GIT_CONFIG_GLOBAL", "/dev/null")
.env("GIT_CONFIG_SYSTEM", "/dev/null")
.env("GIT_AUTHOR_NAME", "Tester")
.env("GIT_AUTHOR_EMAIL", "t@t.local")
.env("GIT_COMMITTER_NAME", "Tester")
.env("GIT_COMMITTER_EMAIL", "t@t.local"),
)
.expect("git runs");
assert!(out.status.success(), "git {args:?}: {out:?}");
String::from_utf8_lossy(&out.stdout).trim().to_string()
}
fn workspace_with_refs() -> (tempfile::TempDir, PathBuf) {
let dir = tempdir().unwrap();
let root = dir.path().canonicalize().unwrap();
let repo = root.join("repo.git");
fs::create_dir_all(&repo).unwrap();
git(&repo, &["init", "-q", "--bare", "."]);
let tree = git(&repo, &["hash-object", "-w", "-t", "tree", "/dev/null"]);
let commit = git(&repo, &["commit-tree", &tree, "-m", "x"]);
git(&repo, &["update-ref", "refs/heads/agents/aa-bb", &commit]);
git(&repo, &["update-ref", "refs/heads/agents/cc-dd", &commit]);
(dir, root)
}