gitx

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gitx wraps the git command line for the few operations Spackle needs: reading the commit, cloning a target, creating a worktree for fixes, reading history, and bisecting.

Every call passes arguments as a vector, never through a shell, and disables hooks and prompts so a hostile repository cannot run code or block the run by asking for credentials.

Index

Constants

This section is empty.

Variables

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

ErrNotRepo is returned when a directory is not inside a git work tree.

View Source
var ErrUnsafeConfig = errors.New("the repository's own git configuration names a program for git to run")

ErrUnsafeConfig is returned, instead of running git, for a repository whose own configuration names a program for git to run. It also matches ErrNotRepo, so callers treat such a directory as one that is not in git.

View Source
var WholeFile = LineRange{Start: 1, End: math.MaxInt}

WholeFile is the range of a file that has no earlier version to compare with, such as an untracked file: every line of it is new.

Functions

func AddWorktree

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

AddWorktree creates a new branch at HEAD checked out in a new worktree at path. The caller's working tree and index are not touched.

func Apply

func Apply(ctx context.Context, dir, patchFile string) error

Apply applies a unified diff in dir. It works in a plain directory too, not only inside a repository.

func ApplyCheck

func ApplyCheck(ctx context.Context, dir, patchFile string) error

ApplyCheck reports whether a unified diff applies cleanly in dir.

func Archive

func Archive(ctx context.Context, dir, rev, dest string) error

Archive exports the tree at rev into dest (which must exist), without any .git directory. It is how a specific commit is handed to the sandbox.

func Available

func Available() bool

Available reports whether git is on PATH.

func ChangedLinesSince added in v0.2.0

func ChangedLinesSince(ctx context.Context, dir, rev string) (map[string][]LineRange, error)

ChangedLinesSince returns, for the files ChangedSince lists, the lines of their current version that were added or changed between the merge base of rev and HEAD. A pure deletion marks the two lines it sits between, so code next to removed code still counts as touched. A file whose change has no lines (a binary file, or a rename with no edit) has no entry.

func ChangedLinesStaged added in v0.2.0

func ChangedLinesStaged(ctx context.Context, dir string, exclude ...string) (map[string][]LineRange, error)

ChangedLinesStaged is ChangedLinesSince for the files ChangedStaged lists: the lines of their staged version that differ from HEAD.

func ChangedLinesUncommitted added in v0.2.0

func ChangedLinesUncommitted(ctx context.Context, dir string, exclude ...string) (map[string][]LineRange, error)

ChangedLinesUncommitted is ChangedLinesSince for the files ChangedUncommitted lists: the lines that differ from HEAD, staged or not. An untracked file, and every file before the first commit, is WholeFile.

func ChangedSince added in v0.2.0

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

ChangedSince lists the files under dir that were added, copied, modified or renamed between the merge base of rev and HEAD, and HEAD. It is the set of files a pull request against rev changes. Paths use forward slashes and are relative to dir; a change outside dir is not listed, and neither is a deleted file or a change that is not committed.

func ChangedStaged added in v0.2.0

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

ChangedStaged returns the files under dir, relative to it, whose staged version differs from HEAD: what the next commit would add or change. Before the first commit every staged file counts. Unstaged edits and untracked files are left out, and so are deleted files. exclude names directories under dir, relative to it, that are left out.

func ChangedUncommitted added in v0.2.0

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

ChangedUncommitted returns the files under dir, relative to it, that differ from HEAD (staged or not) plus the untracked files git does not ignore: what a commit made now could add. Deleted files are left out. Before the first commit every file in the index counts as changed. exclude names directories under dir, relative to it, that are left out, such as the state directory.

func Clone

func Clone(ctx context.Context, remote, dest string) error

Clone makes a shallow clone of remote into dest. Submodules are not fetched: they are separate code the operator did not name as the target.

func CloneRef added in v0.2.0

func CloneRef(ctx context.Context, remote, dest, ref string) error

CloneRef is Clone for a named branch or tag instead of the remote's default branch. An empty ref means the default branch.

func CommitAll

func CommitAll(ctx context.Context, dir, message string) error

CommitAll stages everything in dir and commits with the given message. It is only ever called inside a Spackle worktree, never the operator's working tree.

func Dirty added in v0.2.0

func Dirty(ctx context.Context, dir string, paths ...string) (bool, error)

Dirty reports whether any of the given paths (relative to dir) differs from HEAD: modified, staged, deleted or untracked.

func ExportDir added in v0.2.0

func ExportDir(parent string) (string, error)

ExportDir creates a world-readable directory named "src" inside parent (which stays private to the operator) for Archive to export into. The sandbox user must be able to traverse and read the export, and a directory made by os.MkdirTemp is mode 0700.

func HasTracked

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

HasTracked reports whether dir contains at least one tracked file.

func HeadSHA

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

HeadSHA returns the full commit hash of HEAD, or ErrNotRepo.

func IsClean

func IsClean(ctx context.Context, dir string) (bool, error)

IsClean reports whether the work tree has no uncommitted changes.

func IsCleanExcept added in v0.2.0

func IsCleanExcept(ctx context.Context, dir, except string) (bool, error)

IsCleanExcept reports whether the work tree has no uncommitted changes outside the named top-level directory. dir must be the top of the work tree.

func Log

func Log(ctx context.Context, dir, path string, n int) (string, error)

Log returns up to n one-line history entries for path (or the whole repository when path is empty).

func OpenPR

func OpenPR(ctx context.Context, req PRRequest) (string, error)

OpenPR pushes the branch to the "origin" remote and opens a pull request with the GitHub CLI. It is only called when the operator passed --pr: it is the one place Spackle writes anywhere other than the local machine.

The pull request is opened as a draft. A patch written by a model should be read by a person before it is merged, and a draft says so.

func Prefix

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

Prefix returns the path of dir relative to the top of its work tree, with forward slashes and no trailing slash ("" at the top). Asking git avoids comparing path spellings, which differ on Windows (short names, case).

func ResetWorktree added in v0.2.0

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

ResetWorktree throws away every uncommitted change in dir. It is only ever called inside a Spackle worktree, never the operator's working tree.

func RevList

func RevList(ctx context.Context, dir, good, bad string) ([]string, error)

RevList returns the commits from good (exclusive) to bad (inclusive), oldest first.

func Show

func Show(ctx context.Context, dir, rev, path string) (string, error)

Show returns the patch of one commit, limited to path when given.

func Status

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

Status returns `git status --porcelain` output. An empty string means the work tree is clean.

func TopLevel

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

TopLevel returns the root of the work tree containing dir.

func Tracked

func Tracked(ctx context.Context, dir string, paths ...string) bool

Tracked reports whether every given path (relative to dir) is tracked by git. A directory can sit inside some unrelated repository without being part of it (a temp folder under a home directory that is itself a repository, for example). Spackle only treats a target as "in git" when its files are tracked.

func UnstagedFiles added in v0.2.0

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

UnstagedFiles returns the files under dir, relative to it, whose working tree differs from the index: edits that are not staged.

Types

type LineRange added in v0.2.0

type LineRange struct {
	Start, End int
}

LineRange is an inclusive range of line numbers, counted from 1.

func (LineRange) Overlaps added in v0.2.0

func (r LineRange) Overlaps(start, end int) bool

Overlaps reports whether the lines start to end (inclusive) meet r.

type PRRequest

type PRRequest struct {
	// Dir is the worktree that holds the branch.
	Dir    string
	Branch string
	Title  string
	Body   string
}

PRRequest describes a pull request to open for a fix branch.

Jump to

Keyboard shortcuts

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