git

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBatchSessionPoisoned = errors.New("git batch session is poisoned after repeated errors")

ErrBatchSessionPoisoned is returned when repeated errors poison the batch session.

View Source
var ErrNotGitRepository = errors.New("not a git repository")

ErrNotGitRepository indicates that cwd does not contain a Git repository.

Functions

func ApplyTextconvFilter added in v0.15.0

func ApplyTextconvFilter(cwd, driver, filePath string) ([]byte, bool, error)

ApplyTextconvFilter runs a configured textconv filter for driver on filePath. If driver has no configured textconv command in Git config or filePath does not exist, it returns nil, false, nil.

func CheckDiffAttr added in v0.15.0

func CheckDiffAttr(cwd string, paths ...string) map[string]FileDiffAttr

CheckDiffAttr queries Git for the diff and binary attributes of the given paths. If neither cwd nor any path is inside a Git repository, it returns an empty map without running git.

func ClearCache added in v0.12.0

func ClearCache()

ClearCache resets cached repo metadata. Mainly used to isolate test runs.

func FindRepoRoot added in v0.14.0

func FindRepoRoot(cwd string) string

FindRepoRoot walks up from cwd looking for a .git directory or file (for worktrees and submodules). Returns an empty string if not in a git repo.

func GetBatchContent added in v0.12.0

func GetBatchContent(cwd string, reqs []BlobRequest) (map[BlobRequest][]byte, error)

GetBatchContent fetches blobs in one git cat-file --batch pass. When Revision is empty, it reads the working-tree file straight from disk.

func GetContent

func GetContent(cwd, path, revision string, useTextconv bool) ([]byte, error)

GetContent reads a file at a given revision (e.g. "HEAD", a hash, or ":" for index). If revision is empty, it reads the local file on disk (applying textconv filter only if useTextconv is true).

func GetRepoPrefix added in v0.7.0

func GetRepoPrefix(cwd string) (string, error)

GetRepoPrefix returns the path prefix of cwd relative to the Git repository worktree root.

func IsGitRepository

func IsGitRepository(cwd string) bool

IsGitRepository checks if the directory is a Git repository.

func IsNullOID added in v0.14.0

func IsNullOID(s string) bool

IsNullOID reports whether s is non-empty and consists entirely of '0' characters (a Git null OID).

func IsTrackedFile added in v0.7.0

func IsTrackedFile(cwd, path string) bool

IsTrackedFile checks if a path is tracked in the Git repository index or tree.

func IsValidRevision

func IsValidRevision(cwd, ref string) bool

IsValidRevision checks if a string is a valid Git revision.

func ListRefs added in v0.9.0

func ListRefs(cwd string, toComplete string) ([]string, error)

ListRefs returns Git revisions for shell completion, optionally filtered by prefix.

func RunGit

func RunGit(cwd string, args ...string) ([]byte, error)

RunGit runs a git command in the specified directory.

Types

type BatchSession added in v0.14.0

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

BatchSession keeps a git cat-file --batch process open to fetch blobs sequentially without spawning a new process per object.

func StartBatchSession added in v0.14.0

func StartBatchSession(cwd string) (*BatchSession, error)

StartBatchSession starts a git cat-file --batch process in cwd.

func (*BatchSession) Close added in v0.14.0

func (s *BatchSession) Close() error

Close stops the batch process and waits for it to exit.

func (*BatchSession) Fetch added in v0.14.0

func (s *BatchSession) Fetch(oid string) ([]byte, error)

Fetch gets the raw blob for an object ID. Returns (nil, nil) if the object is missing so the caller can fall back to disk.

func (*BatchSession) IsPoisoned added in v0.14.0

func (s *BatchSession) IsPoisoned() bool

IsPoisoned reports whether the session was shut down after repeated errors.

type BlobRequest added in v0.12.0

type BlobRequest struct {
	Path     string
	Revision string
}

BlobRequest pairs a repository-relative path with a Git revision.

type DiffAttr added in v0.15.0

type DiffAttr int

DiffAttr represents the diff behavior specified in .gitattributes for a file.

const (
	// DiffAttrUnspecified means no diff attribute was set.
	DiffAttrUnspecified DiffAttr = iota
	// DiffAttrText forces text diffing (attribute 'diff').
	DiffAttrText
	// DiffAttrBinary forces binary treatment (attribute '-diff' or 'binary').
	DiffAttrBinary
)

type FileDiffAttr added in v0.15.0

type FileDiffAttr struct {
	Attr   DiffAttr // Configured diff behavior (unspecified, text, or binary).
	Driver string   // Custom diff driver name, if set (e.g. "pdfconv").
}

FileDiffAttr holds gitattributes diff settings for a file.

type GitFile

type GitFile struct {
	Path     string
	OldPath  string // Non-empty if the file was renamed
	Status   string // 2-character porcelain status code (e.g. " M", "M ", "??")
	Staged   bool   // True if there are staged changes
	Unstaged bool   // True if there are unstaged changes or untracked
	IsBinary bool   // True if the file was identified as binary
}

GitFile represents a modified or untracked file in the repository.

func GetChangedFiles

func GetChangedFiles(cwd, refA, refB string, pathFilter string) ([]GitFile, error)

GetChangedFiles lists files changed between refA and refB. If refA is empty, it returns current working directory status. If refB is empty, it compares refA against the working tree.

func GetStatus

func GetStatus(cwd string, pathFilter string) ([]GitFile, error)

GetStatus returns the Git status of the repository.

Jump to

Keyboard shortcuts

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