git

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 IsGitRepo

func IsGitRepo() bool

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

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 {
	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 {
	Path    string
	Status  ChangeStatus
	OldPath string // for renames
	Binary  bool
}

FileChange describes a single changed file.

func ChangedFiles

func ChangedFiles() ([]FileChange, error)

ChangedFiles returns files with changes relative to HEAD (staged + unstaged + untracked).

func ChangedFilesFrom

func ChangedFilesFrom(ref string) ([]FileChange, error)

ChangedFilesFrom returns files changed relative to a ref (branch, commit, HEAD~N).

func ChangedFilesStaged

func ChangedFilesStaged() ([]FileChange, error)

ChangedFilesStaged returns files changed in the index relative to HEAD.

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 {
	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 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) 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.

Jump to

Keyboard shortcuts

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