git

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsoluteWatchPath added in v1.6.0

func AbsoluteWatchPath(root, path string) string

func CurrentBranch

func CurrentBranch() (string, error)

CurrentBranch returns the current branch name, or "HEAD" when detached.

func FileContentFromIndex

func FileContentFromIndex(path string) ([]byte, error)

FileContentFromIndex returns a file's staged content.

func IgnoredDirectories added in v1.6.0

func IgnoredDirectories(paths ...string) ([]string, error)

IgnoredDirectories returns collapsed ignored paths so watchers can avoid descending into build outputs and dependency directories at startup.

func IgnoredPath added in v1.6.0

func IgnoredPath(path string) (bool, error)

func IsGitRepo

func IsGitRepo() bool

IsGitRepo checks if the current directory is inside a git repository.

func WatchFiles added in v1.6.0

func WatchFiles(paths []string) ([]string, error)

Types

type ChangeStatus

type ChangeStatus int

ChangeStatus represents the type of change to a file.

const (
	StatusModified ChangeStatus = iota
	StatusAdded
	StatusDeleted
	StatusRenamed
	StatusUntracked
	StatusBinary
)

func (ChangeStatus) String

func (s ChangeStatus) String() string

String returns the review.json status string for a change status.

type DeletedLine

type DeletedLine struct {
	OldLineNum int
	Content    string
	Inline     []InlineSegment
}

DeletedLine represents a line that was deleted from the old version.

type DiffInfo

type DiffInfo struct {
	// PairedLines maps added source lines to similar deleted lines.  Zero marks
	// an unpaired addition; missing entries retain legacy positional alignment.
	PairedLines   map[int]int             `json:",omitempty"`
	CommonLines   map[int]int             `json:",omitempty"` // new-to-old coordinates supplied by the patch
	ChangedLines  map[int]bool            // added/modified line numbers (1-based) in new file
	InlineChanges map[int][]InlineSegment // inline changes keyed by new-file line number
	DeletedAfter  map[int][]DeletedLine   // deleted lines keyed by the new-file line they appear after (0 = before line 1)
}

DiffInfo contains parsed diff information for a single file.

func DiffFile

func DiffFile(path, oldPath, ref string) (*DiffInfo, error)

DiffFile returns full diff information for a file relative to the given ref. oldPath is the file's previous path when it was renamed, else "".

func DiffFileStaged

func DiffFileStaged(path, oldPath string) (*DiffInfo, error)

DiffFileStaged returns diff information for the indexed version of a file. oldPath is the file's previous path when it was renamed, else "".

func (*DiffInfo) IgnoreWhitespace

func (info *DiffInfo) IgnoreWhitespace(newLines []string) *DiffInfo

IgnoreWhitespace compares each replacement block without horizontal ASCII whitespace. It preserves source text and coordinates, including for partial patches, and never changes the original diff or hides added/deleted lines that have no matching line on the other side.

type FileChange

type FileChange struct {
	Textconv Textconv
	Path     string
	Status   ChangeStatus
	OldPath  string // for renames
	Binary   bool
}

FileChange describes a single changed file.

func (FileChange) IsBinary

func (f FileChange) IsBinary() bool

IsBinary also recognizes snapshots saved before binary detection was separated from the change status.

func (FileChange) ReviewStatus

func (f FileChange) ReviewStatus() string

ReviewStatus preserves the Crit-compatible status for binary files.

type InlineSegment

type InlineSegment struct {
	Content string
	Changed bool
}

InlineSegment is a changed or unchanged portion of a replacement line.

type Patch

type Patch struct {
	Raw   string
	Files []PatchFile
}

Patch is a self-contained snapshot: reopening it never reads worktree files.

func LoadPatch

func LoadPatch(path string) (*Patch, error)

func ParsePatch

func ParsePatch(r io.Reader) (*Patch, error)

ParsePatch accepts Git-style unified diffs, including git show preambles.

func (*Patch) Changes

func (p *Patch) Changes() []FileChange

func (*Patch) File

func (p *Patch) File(path string) *PatchFile

type PatchFile

type PatchFile struct {
	Change  FileChange
	Content string
	Diff    *DiffInfo
	// Known is nil for complete content, otherwise it identifies the lines
	// supplied by the patch.  Empty placeholders must never become anchors.
	Known map[int]bool
}

type ReviewSource

type ReviewSource struct {
	TextconvDrivers []string `json:"textconv_drivers,omitempty"`
	Scope           string
	Range           string
	Base            string
	Head            string
}

ReviewSource describes both sides of a code review without treating refs as command options or reading working-tree contents for committed comparisons.

func ResolveCommit added in v1.6.0

func ResolveCommit(value string) (ReviewSource, error)

ResolveCommit compares a commit with its first parent, or the empty tree for a root commit. It uses the same snapshot representation as a range.

func ResolveRange

func ResolveRange(value string) (ReviewSource, error)

func (ReviewSource) Content

func (s ReviewSource) Content(path string) ([]byte, error)

func (ReviewSource) Diff

func (s ReviewSource) Diff(path, oldPath string) (*DiffInfo, error)

Diff returns the diff of path. oldPath is the file's previous path when it was renamed, else "".

func (ReviewSource) Files

func (s ReviewSource) Files() ([]FileChange, error)

func (ReviewSource) Fingerprint added in v1.6.0

func (s ReviewSource) Fingerprint(files []FileChange) (string, error)

Fingerprint detects source changes without loading file contents or running text conversions. Working files contribute their size, mode, and mtime; committed and index contents contribute Git object IDs.

func (ReviewSource) ObjectIDs added in v1.6.0

func (s ReviewSource) ObjectIDs(paths []string) (map[string]string, error)

ObjectIDs returns the selected immutable blob IDs in one Git invocation.

func (ReviewSource) PreviewContent

func (s ReviewSource) PreviewContent(path string, before bool, limit int64) ([]byte, error)

PreviewContent bounds reads before loading binary data into memory.

func (ReviewSource) Snapshot

func (s ReviewSource) Snapshot() (ReviewSource, string, error)

Snapshot records raw changes, including mode and binary changes, without applying the display's whitespace filtering.

func (ReviewSource) TextContent added in v1.5.0

func (s ReviewSource) TextContent(path string, conversion Textconv) ([]byte, error)

TextContent applies the configured driver to the selected revision. It never executes metadata read from a review; callers obtain the driver from Git.

func (ReviewSource) WatchInputs added in v1.6.0

func (s ReviewSource) WatchInputs() (string, []string, error)

WatchInputs resolves worktree-local metadata through Git, including linked worktrees whose index and HEAD live outside the working directory.

type Textconv added in v1.5.0

type Textconv struct {
	Driver  string `json:"driver"`
	Command string `json:"command"`
}

Textconv identifies the representation whose lines are used in a review. Command is Git configuration, not a command supplied by review JSON.

Jump to

Keyboard shortcuts

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