git

package
v0.17.4 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: AGPL-3.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotARepo = errors.New("not a git repository")

ErrNotARepo is WorkingDiff's answer for a directory with no git directory it may use: none at all, or one that resolves outside the root.

Functions

func IsRepo

func IsRepo(ctx context.Context, dir string) bool

IsRepo reports whether dir contains a .git entry, in any of its forms or as a symlink to one (os.Stat follows symlinks).

func WorkingDiff added in v0.12.0

func WorkingDiff(ctx context.Context, root *os.Root, name string, maxBytes int) (staged, unstaged string, err error)

WorkingDiff returns the staged and unstaged diff of the repository at name inside root, each cut to maxBytes. git gets descriptors opened through root as GIT_WORK_TREE, GIT_DIR and GIT_COMMON_DIR, which outrank core.worktree, so no swapped component, outside .git or core.worktree can point it elsewhere.

Types

type Handler

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

Handler implements git HTTP endpoints (non-AI operations).

func NewHandler

func NewHandler(workDir string, opts ...Option) *Handler

NewHandler returns a Handler scoped to workDir. Shutdown ends the status scans it runs behind its answers.

func (*Handler) RegisterRoutes

func (h *Handler) RegisterRoutes(mux *http.ServeMux)

RegisterRoutes installs the /api/git/* mux entries.

func (*Handler) RepoRemotes

func (h *Handler) RepoRemotes(ctx context.Context) []RepoRemote

RepoRemotes resolves every discovered workspace repo's `origin` remote.

Discovery reuses cachedDiscoverRepos, so this shares the singleflighted scan the git views already perform rather than walking the workspace again. The one subprocess per repo is `git remote get-url origin`, which reads config and touches no network.

func (*Handler) Shutdown added in v0.17.0

func (h *Handler) Shutdown(ctx context.Context) error

Shutdown cancels the status scans in flight, refuses any later one, and returns once those in flight have, or with ctx's error when ctx ends first. It may be called more than once.

type Option

type Option func(*Handler)

Option configures a Handler at construction time.

func WithShowMax added in v0.13.0

func WithShowMax(n int64) Option

WithShowMax caps the blob /api/git/show serves at n bytes; a larger revision answers 413. Non-positive keeps the default.

type RepoRemote

type RepoRemote struct {
	// Name is the workspace directory ("." for the workspace root itself), the
	// name the git panel addresses the repository by.
	Name string
	// WebBase is the origin's scheme and authority when the remote is an http or
	// https URL, and "" for an ssh or scp-like remote.
	WebBase string
	Slug    string
}

RepoRemote is one workspace repo's origin in the coordinates a forge addresses it by: WebBase selects the forge connection, Slug is the owner/name path. A repo with no parseable origin is absent.

type ShowRefusal added in v0.13.0

type ShowRefusal struct {
	Error string          `json:"error"`
	Code  ShowRefusalCode `json:"code"`
}

ShowRefusal is a refused GET /api/git/show's body; it carries no content.

type ShowRefusalCode added in v0.13.0

type ShowRefusalCode string

ShowRefusalCode is the machine-readable reason on a ShowRefusal.

type ShowResponse added in v0.13.0

type ShowResponse struct {
	Content string `json:"content"`
	Absent  bool   `json:"absent,omitempty"`
}

ShowResponse is GET /api/git/show's success reply. Absent marks a path the ref does not hold, whose Content is legitimately empty.

Jump to

Keyboard shortcuts

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