gittest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package gittest builds throwaway git repositories for tests. Commits are deterministic: fixed author, committer, and timezone, with timestamps advancing one minute per commit.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Repo

type Repo struct {
	// contains filtered or unexported fields
}

Repo is a scratch repository rooted in a test temp directory.

func New

func New(t *testing.T) *Repo

New creates an empty repository on branch main.

func (*Repo) AnnotatedTag

func (r *Repo) AnnotatedTag(name, msg string)

AnnotatedTag creates an annotated tag at HEAD.

func (*Repo) Bare

func (r *Repo) Bare() string

Bare clones the repository into a new bare directory and returns its path.

func (*Repo) Branch

func (r *Repo) Branch(name string)

Branch creates a branch at HEAD and checks it out.

func (*Repo) Checkout

func (r *Repo) Checkout(name string)

Checkout switches branches.

func (*Repo) Commit

func (r *Repo) Commit(msg string) string

Commit stages everything and commits, returning the commit SHA. The clock advances one minute per commit.

func (*Repo) Git

func (r *Repo) Git(args ...string) string

Git runs a git command in the repository and returns trimmed stdout.

func (*Repo) LFSPointer

func (r *Repo) LFSPointer(path string, size int64)

LFSPointer writes a git-lfs pointer file at path.

func (*Repo) Merge

func (r *Repo) Merge(name string) string

Merge merges the named branch into the current one with a merge commit.

func (*Repo) Path

func (r *Repo) Path() string

Path returns the repository root.

func (*Repo) Remove

func (r *Repo) Remove(path string)

Remove deletes a file from the worktree.

func (*Repo) Rename

func (r *Repo) Rename(from, to string)

Rename moves a file with git mv.

func (*Repo) SetOrigin

func (r *Repo) SetOrigin(url string)

SetOrigin points the origin remote at url without fetching.

func (*Repo) Submodule

func (r *Repo) Submodule(path, sha string)

Submodule stages a gitlink entry at path pinned to sha, with no network and no nested repository. The directory is created empty so Commit's add -A sees an uninitialized submodule and keeps the staged entry.

func (r *Repo) Symlink(target, path string)

Symlink creates a symbolic link at path pointing at target.

func (*Repo) Tag

func (r *Repo) Tag(name string)

Tag creates a lightweight tag at HEAD.

func (*Repo) Write

func (r *Repo) Write(path, content string)

Write creates or replaces a file, creating parent directories.

func (*Repo) WriteBinary

func (r *Repo) WriteBinary(path string, size int)

WriteBinary writes len bytes including NULs so the file sniffs as binary.

Jump to

Keyboard shortcuts

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