in focus/operations/src/refs.rs [342:411]
fn test_expire_leaves_repod_master_untouched() -> Result<()> {
let mut fix = Fixture::new()?;
let ident = old_ident();
{
setup_ref_repo(&mut fix, &ident)?;
}
{
// set head to unborn branch
let repo = fix.repo();
repo.set_head("refs/heads/repo.d/master")?;
// cleanup existing files
let workdir = repo.workdir().unwrap().to_owned();
for res in fs::read_dir(workdir)? {
let entry = res?;
if entry.file_name() == ".git" {
continue;
}
let meta = entry.metadata()?;
if meta.is_dir() {
fs::remove_dir_all(entry.path())?;
} else {
fs::remove_file(entry.path())?;
}
}
}
let cutoff = FocusTime::now() - chrono::Duration::days(90);
// create a new commit
let oid = {
let sig = ident.to_signature()?;
fix.write_add_and_commit(
"stuff.sh",
"this is stuff",
"stuff for repo.d",
Some(&sig),
Some(&sig),
)
}?;
{
let repo = fix.repo();
let repod_commit = repo.find_commit(oid)?;
// make sure this commit is older than the cutoff so we know we're actually
// testing the right thing.
assert!(FocusTime::from(repod_commit.author().when()) < cutoff);
// create a ref with the same name that HEAD points to, making it a "born" branch
repo.reference(REFS_HEADS_REPOD_MASTER, oid, true, "")?;
}
// switch head back to main
fix.checkout(REFS_HEADS_MAIN, Some(git2::ResetType::Hard))?;
{
let repo = fix.repo();
super::expire_old_refs(repo, cutoff, false, false, fix.app())?;
assert!(repo.find_reference(OLD_TIP_BRANCH_NAME).is_err());
assert!(repo.find_reference(OLD_MERGE_BASE_BRANCH_NAME).is_ok());
assert!(repo.find_reference(REFS_HEADS_MAIN).is_ok());
assert!(repo.find_reference(REFS_HEADS_REPOD_MASTER).is_ok());
}
Ok(())
}