gitdiff

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package gitdiff captures the full workspace diff after an agent run: staged + unstaged changes plus non-ignored untracked files. Ignored files are outside this evidence contract unless they are already tracked.

Index

Constants

This section is empty.

Variables

View Source
var ErrWorkspaceDiffLimit = errors.New("workspace diff byte limit exceeded")

Functions

func FilePatch

func FilePatch(ctx context.Context, path string, before, after FileVersion) (string, error)

FilePatch builds a git-compatible unified patch for one repository-relative path without touching the caller's worktree or index.

func HeadCommit

func HeadCommit(ctx context.Context, dir string) (string, error)

HeadCommit returns dir's HEAD commit SHA at call time. A non-git dir or a repository with no commits yet yields ("", nil); any other failure is an error, so a failed capture is never recorded as "no commits were made".

func WorkspaceDiff

func WorkspaceDiff(ctx context.Context, dir, destPath string, excludes ...string) (wrote bool, err error)

WorkspaceDiff streams the combined staged+unstaged+untracked diff for dir into destPath and reports whether anything was written. An empty diff leaves no file. A non-git dir is a no-op (false, nil) — not every workspace is a repo. excludes are workspace-relative paths (forward-slashed) kept out of the diff, e.g. the run bundle dir so a run never captures itself.

Untracked staging uses a private snapshot of the repository index. The caller's real index is never modified, even transiently, so an interrupted capture cannot leave intent-to-add entries behind or race an unrelated Git operation. `git add --pathspec-from-file` requires git >=2.25.

func WorkspaceDiffWithLimit

func WorkspaceDiffWithLimit(ctx context.Context, dir, destPath string, maxBytes int64, excludes ...string) (wrote bool, err error)

WorkspaceDiffWithLimit is WorkspaceDiff with an explicit maximum artifact size. Zero means unlimited. A limit failure aborts the secure temporary file, so callers never observe a partial workspace.diff.

func WorkspaceFiles

func WorkspaceFiles(ctx context.Context, dir string) ([]string, error)

WorkspaceFiles returns the tracked and untracked, non-ignored files in dir. It uses the same bounded context and scrubbed Git environment as the other evidence-capture helpers, so inherited repository overrides cannot redirect the listing away from dir.

Types

type FileVersion

type FileVersion struct {
	Exists  bool
	Content []byte
	// Mode is the source file's os.FileMode. Git records only the executable
	// bit for ordinary files; a zero mode preserves the historical 100644
	// default for callers that do not yet provide mode evidence.
	Mode os.FileMode
}

FileVersion is one side of a captured file edit. Exists distinguishes an added/deleted file from an existing empty file.

type Info

type Info struct {
	IsRepo    bool
	CommitSHA string
	Branch    string
	Dirty     bool
}

Info is the workspace git context recorded as run evidence: whether the workspace is a git repository, the commit the run started from (empty until the first commit exists), its branch (empty when detached), and whether the workspace already had uncommitted or untracked changes.

func WorkspaceInfo

func WorkspaceInfo(ctx context.Context, dir string, excludes ...string) (Info, error)

WorkspaceInfo reports dir's git context from a single `git status` call, so there is exactly one failure mode: a non-git dir is a no-op (zero Info, nil error) and any other git failure is returned rather than recording a possibly-wrong context as evidence. excludes follow WorkspaceDiff's contract — workspace-relative paths kept out of the dirty check. Nothing is implicitly excluded: callers must name the exact generated/control paths so legitimate tracked files under similarly named directories remain evidence.

Jump to

Keyboard shortcuts

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