Documentation
¶
Index ¶
- Variables
- func ApplyTextconvFilter(cwd, driver, filePath string) ([]byte, bool, error)
- func CheckDiffAttr(cwd string, paths ...string) map[string]FileDiffAttr
- func ClearCache()
- func FindRepoRoot(cwd string) string
- func GetBatchContent(cwd string, reqs []BlobRequest) (map[BlobRequest][]byte, error)
- func GetContent(cwd, path, revision string, useTextconv bool) ([]byte, error)
- func GetRepoPrefix(cwd string) (string, error)
- func IsGitRepository(cwd string) bool
- func IsNullOID(s string) bool
- func IsTrackedFile(cwd, path string) bool
- func IsValidRevision(cwd, ref string) bool
- func ListRefs(cwd string, toComplete string) ([]string, error)
- func RunGit(cwd string, args ...string) ([]byte, error)
- type BatchSession
- type BlobRequest
- type DiffAttr
- type FileDiffAttr
- type GitFile
Constants ¶
This section is empty.
Variables ¶
var ErrBatchSessionPoisoned = errors.New("git batch session is poisoned after repeated errors")
ErrBatchSessionPoisoned is returned when repeated errors poison the batch session.
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
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
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 ¶
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
GetRepoPrefix returns the path prefix of cwd relative to the Git repository worktree root.
func IsGitRepository ¶
IsGitRepository checks if the directory is a Git repository.
func IsNullOID ¶ added in v0.14.0
IsNullOID reports whether s is non-empty and consists entirely of '0' characters (a Git null OID).
func IsTrackedFile ¶ added in v0.7.0
IsTrackedFile checks if a path is tracked in the Git repository index or tree.
func IsValidRevision ¶
IsValidRevision checks if a string is a valid Git revision.
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
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.
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 ¶
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.