Add git_init() helper to TestContext

Initializes a git repo in temp_dir. Replaces the local init_git_repo()
helper in repo.rs tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bryan Helmkamp 2026-03-30 09:08:22 -04:00
parent 2e913428d5
commit 3dee953cd2
No known key found for this signature in database
2 changed files with 13 additions and 11 deletions

View file

@ -1,13 +1,5 @@
use fabro_test::{fabro_snapshot, test_context};
fn init_git_repo(path: &std::path::Path) {
std::process::Command::new("git")
.args(["init"])
.current_dir(path)
.output()
.expect("git init should succeed");
}
fn init_fabro_project(context: &fabro_test::TestContext) {
context
.write_temp("fabro.toml", "version = 1\n")
@ -47,7 +39,7 @@ fn help() {
#[test]
fn test_repo_deinit_removes_fabro_toml_and_dir() {
let context = test_context!();
init_git_repo(&context.temp_dir);
context.git_init();
init_fabro_project(&context);
assert!(context.temp_dir.join("fabro.toml").exists());
@ -73,7 +65,7 @@ fn test_repo_deinit_removes_fabro_toml_and_dir() {
#[test]
fn test_repo_deinit_fails_when_not_initialized() {
let context = test_context!();
init_git_repo(&context.temp_dir);
context.git_init();
let mut cmd = context.repo();
cmd.arg("deinit");
@ -90,7 +82,7 @@ fn test_repo_deinit_fails_when_not_initialized() {
#[test]
fn test_repo_init_skill_installs_skill_files() {
let context = test_context!();
init_git_repo(&context.temp_dir);
context.git_init();
context
.repo()

View file

@ -223,6 +223,16 @@ impl TestContext {
self
}
/// Initialize a git repository in `temp_dir`.
pub fn git_init(&self) -> &Self {
std::process::Command::new("git")
.args(["init"])
.current_dir(&self.temp_dir)
.output()
.expect("git init should succeed");
self
}
/// Write a file under `home_dir`, creating parent directories as needed.
///
/// `path` is relative to `home_dir`.