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 ¶
- Variables
- func AddWorktree(ctx context.Context, repo, path, branch string) error
- func Apply(ctx context.Context, dir, patchFile string) error
- func ApplyCheck(ctx context.Context, dir, patchFile string) error
- func Archive(ctx context.Context, dir, rev, dest string) error
- func Available() bool
- func ChangedLinesSince(ctx context.Context, dir, rev string) (map[string][]LineRange, error)
- func ChangedLinesStaged(ctx context.Context, dir string, exclude ...string) (map[string][]LineRange, error)
- func ChangedLinesUncommitted(ctx context.Context, dir string, exclude ...string) (map[string][]LineRange, error)
- func ChangedSince(ctx context.Context, dir, rev string) ([]string, error)
- func ChangedStaged(ctx context.Context, dir string, exclude ...string) ([]string, error)
- func ChangedUncommitted(ctx context.Context, dir string, exclude ...string) ([]string, error)
- func Clone(ctx context.Context, remote, dest string) error
- func CloneRef(ctx context.Context, remote, dest, ref string) error
- func CommitAll(ctx context.Context, dir, message string) error
- func Dirty(ctx context.Context, dir string, paths ...string) (bool, error)
- func ExportDir(parent string) (string, error)
- func HasTracked(ctx context.Context, dir string) bool
- func HeadSHA(ctx context.Context, dir string) (string, error)
- func IsClean(ctx context.Context, dir string) (bool, error)
- func IsCleanExcept(ctx context.Context, dir, except string) (bool, error)
- func Log(ctx context.Context, dir, path string, n int) (string, error)
- func OpenPR(ctx context.Context, req PRRequest) (string, error)
- func Prefix(ctx context.Context, dir string) (string, error)
- func ResetWorktree(ctx context.Context, dir string) error
- func RevList(ctx context.Context, dir, good, bad string) ([]string, error)
- func Show(ctx context.Context, dir, rev, path string) (string, error)
- func Status(ctx context.Context, dir string) (string, error)
- func TopLevel(ctx context.Context, dir string) (string, error)
- func Tracked(ctx context.Context, dir string, paths ...string) bool
- func UnstagedFiles(ctx context.Context, dir string, exclude ...string) ([]string, error)
- type LineRange
- type PRRequest
Constants ¶
This section is empty.
Variables ¶
var ErrNotRepo = errors.New("not a git repository")
ErrNotRepo is returned when a directory is not inside a git work tree.
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.
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 ¶
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 ¶
Apply applies a unified diff in dir. It works in a plain directory too, not only inside a repository.
func ApplyCheck ¶
ApplyCheck reports whether a unified diff applies cleanly in dir.
func Archive ¶
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 ChangedLinesSince ¶ added in v0.2.0
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
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
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
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 ¶
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
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 ¶
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
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
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 ¶
HasTracked reports whether dir contains at least one tracked file.
func IsCleanExcept ¶ added in v0.2.0
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 ¶
Log returns up to n one-line history entries for path (or the whole repository when path is empty).
func OpenPR ¶
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 ¶
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
ResetWorktree throws away every uncommitted change in dir. It is only ever called inside a Spackle worktree, never the operator's working tree.
func Status ¶
Status returns `git status --porcelain` output. An empty string means the work tree is clean.
func Tracked ¶
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.