gitx

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package gitx is the small amount of git this server needs to answer two questions about a delegated task: what did the worker change, and can it be given a working directory of its own.

It shells out to git rather than linking a library. The worker is already driving the same repository through the same binary, and matching its view exactly matters more here than avoiding a process — a library reading the index differently from the git the agent just ran would report changes that are not there.

Every function is read-only unless its name says otherwise, and every one of them degrades to a clear error rather than guessing when the directory is not a repository.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddWorktree

func AddWorktree(ctx context.Context, repo, path, branch string) error

AddWorktree checks out a new branch at path, sharing the repository's history but with a working directory of its own.

This is what lets several workers run at once without fighting: agents edit files, and two of them in the same checkout will overwrite each other's work and produce a diff neither of them intended. A worktree gives each one an isolated tree while keeping one git history, so the result can still be reviewed and merged normally.

func Available

func Available() (string, bool)

Available reports whether git can be found on this machine.

func Branch

func Branch(ctx context.Context, dir string) string

Branch returns the checked-out branch, or "" when HEAD is detached.

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

Head returns the commit dir is currently on. It returns "" with no error in a repository that has no commits yet, which is a legitimate state rather than a failure — a task can still be started there.

func RemoveWorktree

func RemoveWorktree(ctx context.Context, repo, path, branch string, force bool) error

RemoveWorktree deletes a worktree and its branch. Without force it refuses when the tree still holds uncommitted work, which is the whole reason the worktree existed.

func Root

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

Root returns the top level of the repository containing dir.

Types

type FileChange

type FileChange struct {
	Path    string `json:"path"`
	Status  string `json:"status"` // human-readable: modified, added, deleted, renamed, untracked
	Added   int    `json:"added,omitempty"`
	Deleted int    `json:"deleted,omitempty"`
}

FileChange is one path the worker touched.

type Report

type Report struct {
	Repo       bool         `json:"repo"`
	Root       string       `json:"root,omitempty"`
	Branch     string       `json:"branch,omitempty"`
	BaseCommit string       `json:"base_commit,omitempty"`
	HeadCommit string       `json:"head_commit,omitempty"`
	Commits    []string     `json:"commits,omitempty"` // made since base, newest first
	Files      []FileChange `json:"files,omitempty"`
	Added      int          `json:"lines_added"`
	Deleted    int          `json:"lines_deleted"`
	Patch      string       `json:"patch,omitempty"`
	Truncated  bool         `json:"patch_truncated,omitempty"`
	Dirty      bool         `json:"dirty"` // uncommitted changes are present
}

Report is everything that changed in a working directory since a base commit.

func Summarize

func Summarize(ctx context.Context, dir, base string, patch bool, maxPatchBytes int) (Report, error)

Summarize reports what changed in dir since base.

base is the commit the task started from. Comparing against it — rather than against HEAD — is what makes the answer useful when the worker committed its own work: a diff against HEAD would show nothing at all and read as "the agent changed no files", which is the opposite of the truth.

An empty base falls back to comparing the working tree against HEAD, which is all that can be known when the starting point was never recorded.

func (Report) Text

func (r Report) Text() string

Text renders a report the way a person would want to read it.

Jump to

Keyboard shortcuts

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