git

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package git wraps the git CLI behind two small interfaces: Runner (executes arbitrary git commands) and Client (high-level operations the rest of the codebase actually needs).

Both interfaces accept context for cancellation. Callers that need to test git interactions should inject a mock Runner rather than shelling out.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	IsRepo(dir string) bool
	Init(ctx context.Context, dir string) error
	Add(ctx context.Context, dir, path string) error
	Commit(ctx context.Context, dir, msg string) (hash string, err error)
	Status(ctx context.Context, dir string) (dirty bool, lines []string, err error)
	HeadHash(ctx context.Context, dir string) (string, error)
	EnsureConfig(ctx context.Context, dir, key, value string) error
	// CloneOrPull clones url@ref into dest if dest is not already a git
	// repository, otherwise runs `git fetch && git checkout ref` in place.
	// Used by `adept init --from <git-url>` to bootstrap a library remote.
	CloneOrPull(ctx context.Context, url, ref, dest string) error
}

Client is the high-level surface used by callers.

func NewClient

func NewClient(r Runner) Client

NewClient returns a Client backed by r. r must not be nil.

type Result

type Result struct {
	ExitCode int
	Stdout   string
	Stderr   string
}

Result is the captured output of a single git invocation.

type Runner

type Runner interface {
	Run(ctx context.Context, dir string, args ...string) (Result, error)
}

Runner executes a git command with the given working directory and args.

Implementations MUST NOT panic on non-zero exit codes; they should populate Result and return a non-nil error so callers can distinguish process failures (e.g. "git not installed") from command failures (e.g. "fatal: not a git repository").

func NewExecRunner

func NewExecRunner(gitBin string) Runner

NewExecRunner returns a Runner backed by os/exec. Pass "" to default to "git" on $PATH.

Jump to

Keyboard shortcuts

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