Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# git-testkit

[![CI](https://github.com/git-fire/git-testkit/actions/workflows/ci.yml/badge.svg)](https://github.com/git-fire/git-testkit/actions/workflows/ci.yml)
[![Go Reference](https://pkg.go.dev/badge/github.com/git-fire/git-testkit.svg)](https://pkg.go.dev/github.com/git-fire/git-testkit)
[![Go 1.22+](https://img.shields.io/badge/go-1.22+-blue.svg)](https://golang.org/dl/)
[![Latest Release](https://img.shields.io/github/v/release/git-fire/git-testkit)](https://github.com/git-fire/git-testkit/releases/latest)
[![MIT License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)

`git-testkit` provides helpers for writing Go tests that exercise real Git repositories.

## Why use this
Expand Down Expand Up @@ -113,6 +119,10 @@ func TestUsingSnapshot(t *testing.T) {
- Helpers fail tests immediately (`t.Fatalf`) when git commands fail, so errors surface close to setup code.
- When tests build large repo graphs repeatedly, prefer snapshot/restore to reduce total runtime.

## Origin

`git-testkit` was extracted from [git-fire](https://github.com/git-fire/git-fire) before its public launch and published as a standalone Go library. The test helpers had accumulated enough utility to be useful on their own, so they were split out to let other projects automate real Git repositories without depending on git-fire itself.

## Developer docs

- See `DEVELOPER_GUIDE.md` for:
Expand Down
29 changes: 29 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Package testutil provides helpers for writing Go tests that exercise real
// Git repositories. Instead of mocking git command output, tests create actual
// repositories on disk, apply operations through fluent builders, and assert
// against real git state.
//
// The three main entry points are:
//
// - [CreateTestRepo] for quickly spinning up a single repository with files,
// branches, and remotes already configured.
// - [NewScenario] for building multi-repository topologies (local + bare
// remote, diverged clones, worktrees, conflict states).
// - [SnapshotRepo] / [RestoreSnapshot] for capturing expensive fixture state
// once and restoring it cheaply across subtests.
//
// All helpers integrate with Go's testing.T: repositories are created inside
// t.TempDir() and cleaned up automatically, and setup failures call t.Fatalf
// so errors surface close to the fixture code rather than deep in assertions.
//
// # Quickstart
//
// func TestMyFeature(t *testing.T) {
// repoPath := testutil.CreateTestRepo(t, testutil.RepoOptions{Name: "subject"})
// testutil.RunGitCmd(t, repoPath, "checkout", "-b", "feature")
// // exercise your code against repoPath
// if testutil.IsDirty(t, repoPath) {
// t.Fatal("expected clean repo")
// }
// }
package testutil
Loading