#![allow(dead_code)]
use std::path::Path;
use std::process::Command;
use tempfile::TempDir;
pub fn git(dir: &Path, args: &[&str]) {
let status = Command::new("git")
.arg("-C")
.arg(dir)
.args(args)
.output()
.expect("spawn git");
assert!(
status.status.success(),
"git {args:?} failed: {}",
String::from_utf8_lossy(&status.stderr)
);
}
pub fn init_repo() -> Option<TempDir> {
if !gitmeta::has_git_binary() {
eprintln!("git binary not on PATH; skipping git integration test");
return None;
}
let dir = TempDir::new().expect("tempdir");
let root = dir.path();
git(root, &["init", "-q", "-b", "main"]);
git(root, &["config", "user.email", "test@example.com"]);
git(root, &["config", "user.name", "Test User"]);
git(root, &["config", "commit.gpgsign", "false"]);
Some(dir)
}
pub fn write_and_commit(root: &Path, relpath: &str, content: &str, msg: &str) {
let full = root.join(relpath);
if let Some(parent) = full.parent() {
std::fs::create_dir_all(parent).expect("mkdir");
}
std::fs::write(&full, content).expect("write");
git(root, &["add", relpath]);
git(root, &["commit", "-q", "-m", msg]);
}