git

package
v0.0.0-...-0531573 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package git reads repository state for the viewer: discovery of repos under a folder, per-repo status, and whole-file diffs. It never writes to a repository (no optional locks, no index refresh).

The entry points are Discover (discover.go), GetStatus (status.go), GetFileDiff (filediff.go) and Patch (patch.go).

Index

Constants

View Source
const MaxFileBytes = 4 << 20

MaxFileBytes is the largest file GetFileDiff renders; bigger files come back with TooLarge set.

Variables

This section is empty.

Functions

func GetFileDiff

func GetFileDiff(ctx context.Context, repoPath string, fc FileChange) (*diff.FileDiff, error)

GetFileDiff returns the whole-file diff of fc between HEAD and the working tree (staged and unstaged changes combined): every line of the file, with unchanged lines as Context. Untracked files are all Added, deleted files all Deleted. Binary or oversized files come back with Binary/TooLarge set.

func Patch

func Patch(ctx context.Context, repoPath string, files []FileChange, maxBytes int) (string, error)

Patch returns a compact unified diff (a few lines of context) of the given changes, untracked files rendered as new-file diffs, for sending to Claude. Output is cut at maxBytes with a note saying what was left out; the note comes after the cut. maxBytes <= 0 means no limit.

Types

type FileChange

type FileChange struct {
	Path     string // repo-relative, forward slashes; the new path for renames
	OldPath  string // previous path for renames/copies, "" otherwise
	Kind     Kind
	Staged   bool // the index differs from HEAD
	Unstaged bool // the working tree differs from the index (always true for untracked)
	Added    int  // lines added vs HEAD; 0 when Binary
	Deleted  int  // lines deleted vs HEAD; 0 when Binary
	Binary   bool
	// Submodule marks a submodule, or with Kind Untracked a nested repository
	// git does not look into. Neither has lines of its own, so Added and
	// Deleted stay 0.
	Submodule bool
}

FileChange is one changed file of a repo.

type Kind

type Kind uint8

Kind is the kind of change a file has relative to HEAD.

const (
	Modified Kind = iota
	Added         // new file in the index
	Deleted
	Renamed
	Copied
	Untracked
	TypeChanged
	Conflicted
)

func (Kind) Letter

func (k Kind) Letter() string

Letter is the one-letter status shown in the sidebar.

type Repo

type Repo struct {
	Name string // path relative to the scan root, forward slashes; the folder name when the root is itself in a repo
	Path string // absolute working-tree root, OS-native separators
}

Repo is one discovered repository.

func Discover

func Discover(root string, maxDepth int) ([]Repo, error)

Discover returns the repositories to review. If root is inside a git repository, that repository alone is returned. Otherwise the folders below root are scanned up to maxDepth levels (skipping node_modules and hidden folders, never descending into a found repo), sorted by Name.

type Status

type Status struct {
	Branch   string // current branch, "" when detached
	Head     string // short commit hash, "" for a repo without commits
	Upstream string
	Ahead    int
	Behind   int
	Files    []FileChange // sorted by Path
	// Fingerprint changes whenever the set of changes or the content of any
	// changed file changes, so polling can skip work when nothing moved. A
	// snapshot taken while a changed file was being written gets a
	// fingerprint of its own, so the next poll is never skipped as a repeat.
	Fingerprint string
}

Status is a snapshot of one repo's uncommitted changes.

func GetStatus

func GetStatus(ctx context.Context, repoPath string) (Status, error)

GetStatus reads the uncommitted changes of the repo at repoPath (HEAD → working tree, untracked files included individually).

Jump to

Keyboard shortcuts

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