changes

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package changes defines the application boundary for read-only workspace change attribution. Concrete adapters live in subpackages; this package deliberately contains no process execution.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("coding changes: invalid value")

ErrInvalid means a snapshot or report violates the change contract.

Functions

func CountUnifiedDiffLines

func CountUnifiedDiffLines(diff string) (additions, deletions int)

CountUnifiedDiffLines counts added and deleted content lines inside unified diff hunks. File headers and no-newline markers are not content changes.

Types

type Branch

type Branch struct {
	Head     string
	OID      string
	Upstream string
	Ahead    int
	Behind   int
	Detached bool
	Unborn   bool
}

Branch describes the current repository head without resolving or changing refs.

type DiffSection

type DiffSection struct {
	Summary   DiffSummary
	Diff      string
	Truncated bool
}

DiffSection is one immutable-by-convention staged, unstaged, or untracked presentation payload.

type DiffSummary

type DiffSummary struct {
	Files     int
	Additions int
	Deletions int
	Binary    int
	Omitted   int
}

DiffSummary is a bounded section's aggregate.

type Entry

type Entry struct {
	Path         string
	PreviousPath string
	Kind         Kind
}

Entry is one normalized workspace-relative changed path.

type Inspector

type Inspector interface {
	Capture(context.Context) (Snapshot, error)
	Changes(context.Context, Snapshot) (Report, error)
}

Inspector captures an opaque baseline and later reports changes relative to it. Implementations own the snapshot format and must remain read-only.

type Kind

type Kind string

Kind classifies one observed workspace change.

const (
	KindAdded     Kind = "added"
	KindModified  Kind = "modified"
	KindDeleted   Kind = "deleted"
	KindRenamed   Kind = "renamed"
	KindUntracked Kind = "untracked"
	KindConflict  Kind = "conflict"
)

Change kinds shared by read-only inspectors.

type PathState

type PathState string

PathState is one Git index or worktree status column.

const (
	PathUnchanged   PathState = ""
	PathAdded       PathState = "added"
	PathModified    PathState = "modified"
	PathDeleted     PathState = "deleted"
	PathRenamed     PathState = "renamed"
	PathCopied      PathState = "copied"
	PathTypeChanged PathState = "type_changed"
	PathUnmerged    PathState = "unmerged"
	PathUntracked   PathState = "untracked"
)

Normalized Git path states.

type Report

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

Report is an immutable-by-API change list and optional bounded diff.

func NewReport

func NewReport(entries []Entry, diff string, truncated bool) (Report, error)

NewReport validates and defensively copies a change report.

func (Report) Diff

func (r Report) Diff() string

Diff returns the implementation-bounded human-readable diff.

func (Report) Entries

func (r Report) Entries() []Entry

Entries returns a defensive copy of changed paths.

func (Report) Summary

func (r Report) Summary() DiffSummary

Summary returns aggregate file and visible unified-diff line counts.

func (Report) Truncated

func (r Report) Truncated() bool

Truncated reports whether the Inspector bounded the diff or change list.

type Snapshot

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

Snapshot is immutable opaque state produced and consumed by one Inspector implementation. Format versions the private payload.

func NewSnapshot

func NewSnapshot(format string, payload []byte) (Snapshot, error)

NewSnapshot returns a defensively copied inspector snapshot.

func (Snapshot) Format

func (s Snapshot) Format() string

Format returns the implementation-owned snapshot format.

func (Snapshot) Payload

func (s Snapshot) Payload() []byte

Payload returns a defensive copy of opaque snapshot data.

type StatusEntry

type StatusEntry struct {
	Path         string
	PreviousPath string
	Index        PathState
	Worktree     PathState
	Conflict     bool
	Submodule    string
}

StatusEntry preserves Git's separate index and worktree columns.

type WorktreeInspector

type WorktreeInspector interface {
	Status(context.Context) (WorktreeStatus, error)
}

WorktreeInspector reports bounded point-in-time repository truth. It is deliberately separate from Inspector, whose reports attribute changes to one interaction baseline.

type WorktreeStatus

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

WorktreeStatus is a clone-safe point-in-time repository snapshot.

func NewWorktreeStatus

func NewWorktreeStatus(
	repository bool,
	branch Branch,
	entries []StatusEntry,
	staged, unstaged, untracked DiffSection,
	protectedOmitted int,
) (WorktreeStatus, error)

NewWorktreeStatus validates and defensively copies a repository snapshot.

func (WorktreeStatus) Branch

func (s WorktreeStatus) Branch() Branch

Branch returns the captured branch state.

func (WorktreeStatus) Entries

func (s WorktreeStatus) Entries() []StatusEntry

Entries returns a defensive copy of changed paths.

func (WorktreeStatus) ProtectedOmitted

func (s WorktreeStatus) ProtectedOmitted() int

ProtectedOmitted reports hidden product-metadata paths.

func (WorktreeStatus) Repository

func (s WorktreeStatus) Repository() bool

Repository reports whether the workspace is inside a Git work tree.

func (WorktreeStatus) Staged

func (s WorktreeStatus) Staged() DiffSection

Staged returns the bounded index diff.

func (WorktreeStatus) Unstaged

func (s WorktreeStatus) Unstaged() DiffSection

Unstaged returns the bounded worktree diff.

func (WorktreeStatus) Untracked

func (s WorktreeStatus) Untracked() DiffSection

Untracked returns bounded previews of untracked text files.

Directories

Path Synopsis
Package git attributes workspace changes relative to an in-memory-owned baseline using fixed read-only Git commands.
Package git attributes workspace changes relative to an in-memory-owned baseline using fixed read-only Git commands.

Jump to

Keyboard shortcuts

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