gittest

package
v0.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package gittest provides hardened git-command helpers for tests that need to set up real git repositories or worktrees in t.TempDir().

All commands run with system and global git config disabled (GIT_CONFIG_NOSYSTEM=1, GIT_CONFIG_GLOBAL=/dev/null) and with deterministic author/committer identity, so tests behave the same way on every host.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddWorktree

func AddWorktree(t *testing.T, mainDir, worktreeDir, branch string)

AddWorktree creates a linked git worktree at worktreeDir, branching from HEAD of mainDir to a new branch named branch. Registers a t.Cleanup that runs `git worktree remove --force` so t.TempDir() teardown can succeed without lock-file flakes.

func InitRepo

func InitRepo(t *testing.T, dir string)

InitRepo initializes a normal (non-bare) git repository at dir, creating the directory if needed, and makes one empty commit so subsequent `git worktree add` calls have a ref to branch from.

func Run

func Run(t *testing.T, workdir string, args ...string)

Run executes `git <args...>` with cmd.Dir set to workdir and the standard hardened test environment. workdir must already exist; if it doesn't, Run fails the test. Pass "" for workdir to use the current process's CWD.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL