use std::path::Path;
use super::git_helpers;
pub fn assert_on_branch(repo_path: &Path, expected: &str) {
let actual = git_helpers::current_branch(repo_path);
assert_eq!(
actual,
expected,
"Expected repo at {} to be on branch '{}', but was on '{}'",
repo_path.display(),
expected,
actual
);
}
pub fn assert_branch_exists(repo_path: &Path, branch_name: &str) {
assert!(
git_helpers::branch_exists(repo_path, branch_name),
"Expected branch '{}' to exist in {}",
branch_name,
repo_path.display()
);
}
pub fn assert_branch_not_exists(repo_path: &Path, branch_name: &str) {
assert!(
!git_helpers::branch_exists(repo_path, branch_name),
"Expected branch '{}' to NOT exist in {}",
branch_name,
repo_path.display()
);
}
pub fn assert_file_exists(path: &Path) {
assert!(path.exists(), "Expected file to exist: {}", path.display());
}
pub fn assert_repo_clean(repo_path: &Path) {
let output = std::process::Command::new("git")
.args(["status", "--porcelain"])
.current_dir(repo_path)
.output()
.expect("failed to run git status");
let status = String::from_utf8_lossy(&output.stdout);
assert!(
status.trim().is_empty(),
"Expected repo at {} to be clean, but had:\n{}",
repo_path.display(),
status
);
}
pub fn assert_all_on_branch(workspace_root: &Path, repo_names: &[String], branch: &str) {
for name in repo_names {
let repo_path = workspace_root.join(name);
if repo_path.join(".git").exists() {
assert_on_branch(&repo_path, branch);
}
}
}