{"modulePath":"github.com/TMHSDigital/spackle","version":"v0.2.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package gitx\n\nPackage 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.\n\nEvery 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.\n\n## Variables\n\n```go\nvar ErrNotRepo = errors.New(\"not a git repository\")\n```\nErrNotRepo is returned when a directory is not inside a git work tree.\n\n```go\nvar ErrUnsafeConfig = errors.New(\"the repository's own git configuration names a program for git to run\")\n```\nErrUnsafeConfig 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.\n\n```go\nvar WholeFile = LineRange{Start: 1, End: math.MaxInt}\n```\nWholeFile 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.\n\n## Functions\n\n```go\nfunc AddWorktree(ctx context.Context, repo, path, branch string) error\n```\nAddWorktree creates a new branch at HEAD checked out in a new worktree at path. The caller's working tree and index are not touched.\n\n```go\nfunc Apply(ctx context.Context, dir, patchFile string) error\n```\nApply applies a unified diff in dir. It works in a plain directory too, not only inside a repository.\n\n```go\nfunc ApplyCheck(ctx context.Context, dir, patchFile string) error\n```\nApplyCheck reports whether a unified diff applies cleanly in dir.\n\n```go\nfunc Archive(ctx context.Context, dir, rev, dest string) error\n```\nArchive 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.\n\n```go\nfunc Available() bool\n```\nAvailable reports whether git is on PATH.\n\n```go\nfunc ChangedLinesSince(ctx context.Context, dir, rev string) (map[string][]LineRange, error)\n```\nChangedLinesSince 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.\n\n```go\nfunc ChangedLinesStaged(ctx context.Context, dir string, exclude ...string) (map[string][]LineRange, error)\n```\nChangedLinesStaged is ChangedLinesSince for the files ChangedStaged lists: the lines of their staged version that differ from HEAD.\n\n```go\nfunc ChangedLinesUncommitted(ctx context.Context, dir string, exclude ...string) (map[string][]LineRange, error)\n```\nChangedLinesUncommitted 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.\n\n```go\nfunc ChangedSince(ctx context.Context, dir, rev string) ([]string, error)\n```\nChangedSince 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.\n\n```go\nfunc ChangedStaged(ctx context.Context, dir string, exclude ...string) ([]string, error)\n```\nChangedStaged 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.\n\n```go\nfunc ChangedUncommitted(ctx context.Context, dir string, exclude ...string) ([]string, error)\n```\nChangedUncommitted 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.\n\n```go\nfunc Clone(ctx context.Context, remote, dest string) error\n```\nClone makes a shallow clone of remote into dest. Submodules are not fetched: they are separate code the operator did not name as the target.\n\n```go\nfunc CloneRef(ctx context.Context, remote, dest, ref string) error\n```\nCloneRef is Clone for a named branch or tag instead of the remote's default branch. An empty ref means the default branch.\n\n```go\nfunc CommitAll(ctx context.Context, dir, message string) error\n```\nCommitAll 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.\n\n```go\nfunc Dirty(ctx context.Context, dir string, paths ...string) (bool, error)\n```\nDirty reports whether any of the given paths (relative to dir) differs from HEAD: modified, staged, deleted or untracked.\n\n```go\nfunc ExportDir(parent string) (string, error)\n```\nExportDir 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.\n\n```go\nfunc HasTracked(ctx context.Context, dir string) bool\n```\nHasTracked reports whether dir contains at least one tracked file.\n\n```go\nfunc HeadSHA(ctx context.Context, dir string) (string, error)\n```\nHeadSHA returns the full commit hash of HEAD, or ErrNotRepo.\n\n```go\nfunc IsClean(ctx context.Context, dir string) (bool, error)\n```\nIsClean reports whether the work tree has no uncommitted changes.\n\n```go\nfunc IsCleanExcept(ctx context.Context, dir, except string) (bool, error)\n```\nIsCleanExcept reports whether the work tree has no uncommitted changes outside the named top-level directory. dir must be the top of the work tree.\n\n```go\nfunc Log(ctx context.Context, dir, path string, n int) (string, error)\n```\nLog returns up to n one-line history entries for path (or the whole repository when path is empty).\n\n```go\nfunc OpenPR(ctx context.Context, req PRRequest) (string, error)\n```\nOpenPR 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.\n\nThe 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.\n\n```go\nfunc Prefix(ctx context.Context, dir string) (string, error)\n```\nPrefix 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).\n\n```go\nfunc ResetWorktree(ctx context.Context, dir string) error\n```\nResetWorktree throws away every uncommitted change in dir. It is only ever called inside a Spackle worktree, never the operator's working tree.\n\n```go\nfunc RevList(ctx context.Context, dir, good, bad string) ([]string, error)\n```\nRevList returns the commits from good (exclusive) to bad (inclusive), oldest first.\n\n```go\nfunc Show(ctx context.Context, dir, rev, path string) (string, error)\n```\nShow returns the patch of one commit, limited to path when given.\n\n```go\nfunc Status(ctx context.Context, dir string) (string, error)\n```\nStatus returns \\`git status --porcelain\\` output. An empty string means the work tree is clean.\n\n```go\nfunc TopLevel(ctx context.Context, dir string) (string, error)\n```\nTopLevel returns the root of the work tree containing dir.\n\n```go\nfunc Tracked(ctx context.Context, dir string, paths ...string) bool\n```\nTracked 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.\n\n```go\nfunc UnstagedFiles(ctx context.Context, dir string, exclude ...string) ([]string, error)\n```\nUnstagedFiles returns the files under dir, relative to it, whose working tree differs from the index: edits that are not staged.\n\n## Types\n\n```go\ntype LineRange struct {\n\tStart, End int\n}\n```\nLineRange is an inclusive range of line numbers, counted from 1.\n\n```go\nfunc (r LineRange) Overlaps(start, end int) bool\n```\nOverlaps reports whether the lines start to end (inclusive) meet r.\n\n```go\ntype PRRequest struct {\n\t// Dir is the worktree that holds the branch.\n\tDir    string\n\tBranch string\n\tTitle  string\n\tBody   string\n}\n```\nPRRequest describes a pull request to open for a fix branch.\n\n","path":"github.com/TMHSDigital/spackle/internal/gitx","name":"gitx","synopsis":"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.","isRedistributable":true}
