Help us shape the future of Go! Take the 2026 Go Developer Survey

git

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package git provides bounded, read-only repository inspection.

Index

Constants

View Source
const MaxFileBytes = 4 << 20

MaxFileBytes bounds a single file or small command output.

View Source
const NullPath = "/dev/null"

command binds every operation to the explicit root and object database. NullPath is the empty config/attributes path for Git. os.DevNull is "NUL" on Windows, which Git for Windows rejects; it maps "/dev/null" itself.

Variables

View Source
var ErrBlobTooLarge = errors.New("Git blob exceeds read limit")

ErrBlobTooLarge reports a blob above the caller's read limit.

Functions

func ChangedFiles

func ChangedFiles(ctx context.Context, root, base, head string) ([]string, error)

ChangedFiles lists paths that differ between base and head. head may be WORKTREE, which includes staged, unstaged and untracked non-ignored files. Renames are reported as both the old and the new path.

func CommonDir

func CommonDir(ctx context.Context, root string) (string, error)

CommonDir returns the absolute Git common directory shared by all worktrees.

func DefaultBranch

func DefaultBranch(ctx context.Context, root string) string

DefaultBranch guesses the integration base: the local counterpart of origin/HEAD, then main, master or trunk. It returns "" when none exists.

func Files

func Files(ctx context.Context, root, ref string) ([]string, error)

func Identity

func Identity(ctx context.Context, root string) string

Identity returns a location-independent repository identity derived from its root commits, shared by every clone and worktree. It returns "" when the directory is not a Git repository with history.

func IsAncestor

func IsAncestor(ctx context.Context, root, base, head string) (bool, error)

IsAncestor checks history without changing refs or relying on mutable branch names.

func MergeBase

func MergeBase(ctx context.Context, root, a, b string) (string, error)

MergeBase returns the best common ancestor of two commits.

func ReadBlob

func ReadBlob(ctx context.Context, root, oid string) ([]byte, error)

ReadBlob reads an immutable object, avoiding branch movement during analysis.

func ReadFile

func ReadFile(ctx context.Context, root, ref, path string) ([]byte, error)

func Resolve

func Resolve(ctx context.Context, root, ref string) (string, error)

func WorkingFiles

func WorkingFiles(ctx context.Context, root string) ([]string, error)

WorkingFiles lists tracked and untracked, non-ignored files below root, relative to root. It respects .gitignore and Git exclude settings.

func WorktreeBranches

func WorktreeBranches(ctx context.Context, root string) ([]string, error)

WorktreeBranches lists local branches checked out in any worktree of the repository, in `git worktree list` order. Detached worktrees are omitted.

Types

type BlobReader

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

BlobReader streams many objects through one `git cat-file --batch` process instead of spawning a subprocess per file.

func OpenBlobReader

func OpenBlobReader(ctx context.Context, root string) (*BlobReader, error)

OpenBlobReader starts a batch reader bound to ctx; Close releases it.

func (*BlobReader) Close

func (r *BlobReader) Close() error

Close stops the batch process.

func (*BlobReader) Read

func (r *BlobReader) Read(oid string, limit int64) ([]byte, error)

Read returns a blob's content. Blobs above limit are skipped and reported with ErrBlobTooLarge without loading them into memory.

type Info

type Info struct {
	Root      string   `json:"root"`
	Head      string   `json:"head"`
	Branch    string   `json:"branch"`
	Dirty     bool     `json:"dirty"`
	Worktrees []string `json:"worktrees"`
}

func Inspect

func Inspect(ctx context.Context, root string) (Info, error)

type TreeEntry

type TreeEntry struct {
	Path string
	Mode string
	Type string
	OID  string
	Size int64
}

TreeEntry records Git object metadata without following symlinks or submodules.

func Entries

func Entries(ctx context.Context, root, ref string) ([]TreeEntry, error)

type WorktreeStatus

type WorktreeStatus struct {
	Path                string   `json:"path"`
	Branch              string   `json:"branch,omitempty"`
	Commit              string   `json:"commit"`
	Detached            bool     `json:"detached"`
	Staged              []string `json:"staged"`
	Unstaged            []string `json:"unstaged"`
	Untracked           []string `json:"untracked"`
	InspectionError     string   `json:"inspection_error,omitempty"`
	CommitIncluded      bool     `json:"commit_included"`
	UncommittedIncluded bool     `json:"uncommitted_included"`
}

WorktreeStatus is a read-only boundary observation. Dirty files never enter committed integration candidates; ignored files are not enumerated.

func InspectWorktrees

func InspectWorktrees(ctx context.Context, root string) ([]WorktreeStatus, error)

Jump to

Keyboard shortcuts

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