use std::path::PathBuf;
use tempfile::{TempDir, tempdir};
use super::super::Obligation;
use crate::git_tree::tests::git::{git_out, run_git};
use crate::opslog::Origin;
use crate::start::Prepared;
use balls::layout::Xdg;
pub(super) const MAIN: &str = "main";
pub(super) const BALL: &str = "bl-1f2a";
pub(super) struct World {
pub(super) dir: TempDir,
pub(super) project: PathBuf,
pub(super) xdg: Xdg,
}
impl World {
pub(super) fn new() -> World {
let dir = tempdir().unwrap();
let project = dir.path().join("proj");
std::fs::create_dir_all(&project).unwrap();
run_git(&project, &["init", "-q", "-b", MAIN]);
run_git(&project, &["config", "user.email", "t@t.local"]);
run_git(&project, &["config", "user.name", "Tester"]);
run_git(&project, &["config", "commit.gpgsign", "false"]);
std::fs::write(project.join("README.md"), "the project\n").unwrap();
run_git(&project, &["add", "README.md"]);
run_git(&project, &["commit", "-q", "-m", "found"]);
let xdg = Xdg::with(
&dir.path().join("home"),
None,
Some(&dir.path().join("state").to_string_lossy()),
);
World { dir, project, xdg }
}
pub(super) fn obligation(ball: Option<&str>) -> Obligation {
Obligation {
project: "proj".to_owned(),
ball: ball.map(str::to_owned),
}
}
pub(super) fn tip(&self, refname: &str) -> String {
git_out(&self.project, &["rev-parse", refname])
}
pub(super) fn branch_exists(&self, refname: &str) -> bool {
crate::git_env::output(crate::git_env::git().arg("-C").arg(&self.project).args([
"rev-parse",
"--verify",
"-q",
refname,
]))
.unwrap()
.status
.success()
}
}
pub(super) fn prepared(dir: &TempDir) -> Prepared {
Prepared {
workspace: "cobalt-gecko".to_owned(),
binding: Some(dir.path().join("claim")),
goal: "Ball bl-1f2a: do the thing".to_owned(),
origin: Origin::Balls,
lineage: None,
}
}