Documentation
¶
Overview ¶
Package git provides repository operations through a configurable Git executable.
Repository supports immutable objects, materialization, checked edits, refs, history replay, and guarded local and remote branch updates. Explicit preconditions and a branch lock protect what concurrent dockhand processes both change. Callers own the lifetime of materialized snapshots and the meaning of branches and commits; this package supplies Git facts and mechanisms.
Index ¶
- Variables
- func RemoteBranchCommit(ctx context.Context, program Program, url, branch string) (string, error)
- func SHA1BlobID(data []byte) string
- func Unattended(ctx context.Context, program Program, dir string) []string
- func ValidAbbreviation(name string) bool
- func ValidBranchName(name string) bool
- func ValidObjectID(object string) bool
- func ValidRefName(name string) bool
- type Checkout
- type CherryCommit
- type Commit
- type CommitGraph
- type DatedTree
- type FileEdit
- type FileState
- type HistoryCommit
- type MergeCommitError
- type Program
- type Push
- type RefChange
- type RefConflict
- type RefValue
- type Remote
- type RemoteTag
- type ReplayOutcome
- type Replayed
- type Repository
- func (r *Repository) Add(ctx context.Context, paths ...string) error
- func (r *Repository) AddAll(ctx context.Context, paths ...string) error
- func (r *Repository) AddSparseWorktree(ctx context.Context, directory, branch string, cone []string) (err error)
- func (r *Repository) AllCheckouts(ctx context.Context) (map[string][]string, error)
- func (r *Repository) Amends(ctx context.Context, commit, other string) (bool, error)
- func (r *Repository) ApplyToWorkingFiles(ctx context.Context, edits []FileEdit) error
- func (r *Repository) Author(ctx context.Context) (Signature, error)
- func (r *Repository) BlobID(ctx context.Context, data []byte) (string, error)
- func (r *Repository) BoundaryGraph(ctx context.Context, heads, masters []string) (CommitGraph, error)
- func (r *Repository) Branch(ctx context.Context, name string) (commit, tree string, err error)
- func (r *Repository) BranchWasAt(ctx context.Context, branch, object string) (bool, error)
- func (r *Repository) Bundle(ctx context.Context, path, ref, commit string, exclude ...string) error
- func (r *Repository) ChangedPaths(ctx context.Context, before, after string) ([]string, error)
- func (r *Repository) ChangedPathsOf(ctx context.Context, pairs [][2]string) ([][]string, error)
- func (r *Repository) Checkouts(ctx context.Context, branch string) ([]string, error)
- func (r *Repository) Cherry(ctx context.Context, upstream, head string) ([]CherryCommit, error)
- func (r *Repository) CommitBefore(ctx context.Context, start string, before time.Time) (string, error)
- func (r *Repository) CommitTime(ctx context.Context, commit string) (time.Time, error)
- func (r *Repository) CommitTrees(ctx context.Context, commits []string) (map[string]string, error)
- func (r *Repository) ComposeTree(ctx context.Context, onto, from string, paths []string) (string, error)
- func (r *Repository) Conflicts(ctx context.Context) ([]string, error)
- func (r *Repository) CountCommits(ctx context.Context, base, head string) (int, error)
- func (r *Repository) CountCommitsNotIn(ctx context.Context, base, head string, others []string) (int, error)
- func (r *Repository) CountsFrom(ctx context.Context, base string, branches []string) (map[string]int, error)
- func (r *Repository) CreateBranch(ctx context.Context, name, commit string) error
- func (r *Repository) CurrentBranch(ctx context.Context) (string, error)
- func (r *Repository) DeleteBranch(ctx context.Context, name, commit string) error
- func (r *Repository) DeleteRemoteBranch(ctx context.Context, remote, branch string, expected RefValue) error
- func (r *Repository) DiffDirectories(ctx context.Context, root string) ([]byte, error)
- func (r *Repository) DiffTrees(ctx context.Context, before, after string, paths ...string) ([]byte, error)
- func (r *Repository) Directories(ctx context.Context, tree string, paths []string) (map[string]string, error)
- func (r *Repository) DirectoryTrees(ctx context.Context, tree string, directories []string) (map[string]string, error)
- func (r *Repository) EditTree(ctx context.Context, tree string, edits []FileEdit) (string, error)
- func (r *Repository) Entries(ctx context.Context, tree string, dirs []string) ([]string, error)
- func (r *Repository) ExistingPaths(ctx context.Context, tree string, paths []string) ([]string, error)
- func (r *Repository) ExpandSparse(ctx context.Context, directories ...string) error
- func (r *Repository) FetchBranch(ctx context.Context, remote, branch string) (commit, tree string, err error)
- func (r *Repository) FetchPullRequest(ctx context.Context, remote, repository string, number int) (string, error)
- func (r *Repository) File(ctx context.Context, tree, name string) (FileState, []byte, error)
- func (r *Repository) FileBlobs(ctx context.Context, tree string, paths []string) (map[string]string, error)
- func (r *Repository) FilesBelow(ctx context.Context, tree, directory string) ([]TreeEntry, error)
- func (r *Repository) FirstParentTrees(ctx context.Context, start string, limit int) ([]DatedTree, error)
- func (r *Repository) GrepTree(ctx context.Context, tree, pattern string, pathspecs ...string) ([]string, error)
- func (r *Repository) History(ctx context.Context, base, head string) ([]HistoryCommit, error)
- func (r *Repository) Ignored(ctx context.Context, paths ...string) ([]string, error)
- func (r *Repository) IgnoredFiles(ctx context.Context) ([]string, error)
- func (r *Repository) IndexTree(ctx context.Context) (string, error)
- func (r *Repository) IsAncestor(ctx context.Context, ancestor, descendant string) (bool, error)
- func (r *Repository) Materialize(ctx context.Context, tree string) (_ *Snapshot, err error)
- func (r *Repository) MaterializeInto(ctx context.Context, tree, directory string, include []string, ...) ([]TreeEntry, error)
- func (r *Repository) MergeBase(ctx context.Context, a, b string) (string, error)
- func (r *Repository) MoveCheckout(ctx context.Context, from, to string) error
- func (r *Repository) NarrowSparse(ctx context.Context, directories []string) error
- func (r *Repository) ObjectType(ctx context.Context, object string) (string, error)
- func (r *Repository) Parents(ctx context.Context, commit string) ([]string, error)
- func (r *Repository) PruneWorktrees(ctx context.Context) error
- func (r *Repository) Push(ctx context.Context, request Push) error
- func (r *Repository) ReadBlob(ctx context.Context, object string) ([]byte, error)
- func (r *Repository) ReadFiles(ctx context.Context, tree string, paths []string) (map[string][]byte, error)
- func (r *Repository) ReadRef(ctx context.Context, name string) (RefValue, error)
- func (r *Repository) ReadRefs(ctx context.Context, prefix string) (map[string]RefValue, error)
- func (r *Repository) ReadRefsMatching(ctx context.Context, pattern string) (map[string]RefValue, error)
- func (r *Repository) ReadTree(ctx context.Context, object string) ([]TreeEntry, error)
- func (r *Repository) RemoteHead(ctx context.Context, remote, branch string) (RefValue, error)
- func (r *Repository) Remotes(ctx context.Context) ([]Remote, error)
- func (r *Repository) RemoveUnchangedWorktree(ctx context.Context, directory string) error
- func (r *Repository) RemoveWorktree(ctx context.Context, directory string) error
- func (r *Repository) RenameBranch(ctx context.Context, old, next string) error
- func (r *Repository) Replay(ctx context.Context, onto, upstream, head string, committer Signature) (string, []Replayed, error)
- func (r *Repository) ResetIndex(ctx context.Context) error
- func (r *Repository) Resolve(ctx context.Context, revision string) (string, error)
- func (r *Repository) SetIndex(ctx context.Context, tree string) error
- func (r *Repository) SparseCone(ctx context.Context) ([]string, error)
- func (r *Repository) Switch(ctx context.Context, branch string) error
- func (r *Repository) SwitchNew(ctx context.Context, name string) error
- func (r *Repository) TrackedChanges(ctx context.Context) ([]string, error)
- func (r *Repository) Untracked(ctx context.Context) ([]string, error)
- func (r *Repository) UpdateRefs(ctx context.Context, changes []RefChange) error
- func (r *Repository) WithBranchLock(ctx context.Context, branch string, fn func(context.Context) error) (err error)
- func (r *Repository) WithFiles(ctx context.Context, tree string, paths []string) (string, error)
- func (r *Repository) WorkingTree(ctx context.Context) (head, tree string, err error)
- func (r *Repository) Worktree(root string) *Repository
- func (r *Repository) WriteBlob(ctx context.Context, data []byte) (string, error)
- func (r *Repository) WriteCommit(ctx context.Context, commit Commit) (string, error)
- func (r *Repository) WriteTree(ctx context.Context, entries []TreeEntry) (string, error)
- type Signature
- type Snapshot
- type TreeEntry
- type Version
Constants ¶
This section is empty.
Variables ¶
var ( ErrRefConflict = errors.New("git: ref precondition failed") ErrRefUpdateUncertain = errors.New("git: ref update outcome is uncertain") )
var AheadBehindVersion = Version{Major: 2, Minor: 41}
AheadBehindVersion is the first Git whose for-each-ref says how far each ref is ahead of a commit, %(ahead-behind:<commit>).
var ErrBranchExists = errors.New("git: branch already exists")
ErrBranchExists reports a branch name already in use.
var ErrBranchMissing = errors.New("git: local branch no longer exists")
var ErrFilePrecondition = errors.New("git: file precondition does not match")
var ErrNoHTTPSCredentials = errors.New("git has no credentials for this HTTPS remote")
sshRefused says a command's SSH refusal plainly, with what to look at, rather than as ssh's and git's raw words (the Vx port's field testing, 2026-10-04: with the agent's key gone, submit --plan stopped on "ssh_askpass: exec(/usr/X11R6/bin/ssh-askpass) … Permission denied (publickey)"). ssh's words are kept in the error, after it. ErrNoHTTPSCredentials is git holding no credentials for an HTTPS remote, where it may not ask at a terminal.
var ErrNoRef = errors.New("git: no ref of the remote is that name")
ErrNoRef is a name no ref of a remote resolves, as a fresh clone of it would read the name (CloneCheckout).
var ErrRebaseConflict = errors.New("git: the rebase stopped on conflicts")
ErrRebaseConflict reports a rebase that stopped on conflicts; the checkout was put back as it was.
var ErrSSHRefused = errors.New("git: the SSH server refused this Mac's keys")
ErrSSHRefused is a remote's SSH server refusing every key this Mac offered it.
var ErrWorkingFile = errors.New("git: working file")
ErrWorkingFile reports a working file that is not a regular file, or that changed since it was read.
var MinimumVersion = Version{Major: 2, Minor: 40}
MinimumVersion is the oldest Git dockhand works with: 2.40, whose merge-tree takes --merge-base, with which rebase replays a branch's commits (Replay).
Functions ¶
func RemoteBranchCommit ¶
RemoteBranchCommit is the commit a remote repository's branch, or HEAD, names, read by URL with ls-remote as MacPorts' git livecheck reads it (livecheck.type git: git ls-remote <url> <branch>, the first object it prints). It runs outside any checkout, and never prompts.
func SHA1BlobID ¶ added in v0.8.0
SHA1BlobID is the object ID data has as a blob in a repository of Git's SHA-1 object format, macports-ports' among them, worked out without a repository or a process: what one file's contents are where an evaluation records the files it loaded, and many are hashed a run.
func Unattended ¶ added in v0.6.0
Unattended is the environment git runs in where nobody can answer it, as under serve or a background worker: its ssh runs with BatchMode=yes, so a key whose passphrase no agent holds fails at once, an SSH refusal (sshRefused), where it would ask (the docs dig's I46), as GIT_TERMINAL_PROMPT=0 keeps git's HTTPS from asking. An ssh command the person chose, GIT_SSH_COMMAND or core.sshCommand where dir's configuration sets it, is kept, with the option added; GIT_SSH, a program that may not take ssh's options, is left as it is.
func ValidAbbreviation ¶
ValidAbbreviation reports whether name has the form of an abbreviated object name, gitrevisions(7)'s leading substring of one.
func ValidBranchName ¶
func ValidObjectID ¶
func ValidRefName ¶
ValidRefName accepts a complete literal Git ref, including its refs/ namespace.
Types ¶
type Checkout ¶
Checkout is what a fresh clone of a remote checks out at a name, as the remote's refs say: the commit, or, where no ref is the name and it has the form of an abbreviated object name, the abbreviation, which only a clone's objects expand, and which the commit checked out begins with.
func CloneCheckout ¶
CloneCheckout is the commit a fresh clone of url checks out at name, read from the remote's refs with ls-remote rather than a clone: what `git clone url && git checkout -q name` leaves HEAD at, as MacPorts' Git fetch does. An empty name is the clone's own checkout, the remote's HEAD. A whole commit is itself. Otherwise the name resolves among the refs a clone has (git-clone(1)): the remote's default branch as a local branch, every branch as origin/<branch>, and every tag. git-checkout(1) checks out a local branch by that name first; failing that, the first ref gitrevisions(7) finds for the name, a tag before a branch; failing that, the one remote-tracking branch of the name, which it guesses a new branch from. A name none resolves is an abbreviated commit, where it has that form, or ErrNoRef. It runs outside any checkout, so no repository's configuration applies, and never prompts for credentials.
type CherryCommit ¶
CherryCommit is one of a branch's commits that upstream lacks, and whether upstream has its change all the same, by patch-id.
type CommitGraph ¶ added in v0.8.1
CommitGraph is the included commit graph from a boundary rev-list, and the excluded commits it meets at the graph's boundary.
type HistoryCommit ¶
type HistoryCommit struct {
ID string
Parents []string
Tree string
Message string
Author Signature
// Paths are the files it changes against its first parent.
Paths []string
}
HistoryCommit is one commit of a branch, as tidy and submit read it.
func (HistoryCommit) Merge ¶
func (c HistoryCommit) Merge() bool
Merge reports whether the commit has more than one parent.
func (HistoryCommit) Subject ¶
func (c HistoryCommit) Subject() string
Subject is the message's first line.
type MergeCommitError ¶ added in v0.8.0
type MergeCommitError struct{ Commit string }
MergeCommitError is a replay refused for a merge commit among those it was given, which it doesn't replay.
func (*MergeCommitError) Error ¶ added in v0.8.0
func (e *MergeCommitError) Error() string
type Program ¶ added in v0.5.0
Program is the git dockhand runs, "git" on Env's PATH when Executable is empty, and the environment it runs in, which compose gives, git's own variables filtered from it (repositoryEnv). An Env of nil is refused, as none was given.
type RefConflict ¶
func (*RefConflict) Error ¶
func (e *RefConflict) Error() string
func (*RefConflict) Unwrap ¶
func (e *RefConflict) Unwrap() error
type RemoteTag ¶
type RemoteTag struct{ Name, Object string }
RemoteTag is a tag of a repository read by URL and the object it peels to: the commit an annotated tag finally names, or a lightweight tag's own object. ls-remote does not say what kind of object that is, so a tag that names a blob, as git/git's junio-gpg-pub does, reads like any other.
func ListPublicTags ¶ added in v0.8.0
ListPublicTags reads a public repository's tags as ListRemoteTags does, as anyone would: no credential helper is asked, so a repository that's gone or private, which a forge answers by asking for credentials, fails rather than reaching the person's Keychain, and a redirect isn't followed, so a repository that moved fails too, for its caller to read the move where it can be said (a forge's API).
func ListRemoteTags ¶
func ListRemoteTags(ctx context.Context, program Program, url string, names ...string) ([]RemoteTag, error)
ListRemoteTags reads a remote repository's tags by URL with ls-remote, with no checkout of its own, or only the named tags when names are given; a named tag the remote lacks is absent from the result. It runs outside any checkout, so no repository's configuration applies, and never prompts for credentials.
type ReplayOutcome ¶ added in v0.8.0
type ReplayOutcome string
ReplayOutcome is what a replay made of a commit.
const ( ReplayReplayed ReplayOutcome = "replay" ReplayDropped ReplayOutcome = "drop" ReplayConflict ReplayOutcome = "conflict" ReplayUntried ReplayOutcome = "untried" )
type Replayed ¶ added in v0.8.0
type Replayed struct {
Commit HistoryCommit
Outcome ReplayOutcome
Paths []string
}
Replayed is what a replay made of one of the commits it was given, in order: replayed, dropped as onto has its change, the conflict it stopped at, with its paths, or untried after that conflict.
type Repository ¶
func Init ¶ added in v0.5.0
Init makes an empty repository in an existing directory, its unborn branch named, and opens it: a scratch tree a tool builds and commits, as tools/corpus's slice.
func (*Repository) Add ¶
func (r *Repository) Add(ctx context.Context, paths ...string) error
Add stages new files in a worktree, so the next capture includes them.
func (*Repository) AddAll ¶
func (r *Repository) AddAll(ctx context.Context, paths ...string) error
AddAll stages paths as the working files have them, new, changed, or gone, as a directory moved elsewhere in the worktree is.
func (*Repository) AddSparseWorktree ¶
func (r *Repository) AddSparseWorktree(ctx context.Context, directory, branch string, cone []string) (err error)
AddSparseWorktree checks branch out into a new linked worktree at directory, holding only the cone paths given (and the files at the top of the tree, which cone mode always keeps). The sparse patterns belong to the new worktree alone; Git turns on extensions.worktreeConfig to keep them there. A directory that exists is refused. A worktree that fails partway is removed again.
func (*Repository) AllCheckouts ¶ added in v0.7.0
AllCheckouts are the worktrees each local branch is checked out in, by the branch's name, read in one git process for every branch: status opened each branch's worktree to ask, three processes a branch (Then's item 6).
func (*Repository) Amends ¶ added in v0.6.0
Amends reports whether a commit is another's amended: made on the same first parent, or holding in its tree each file the other changes as the other has it. An empty commit is amended only on its parent, since nothing of it is in any tree: D-S1's outside commit, reset away and replaced by a commit on master, was "amended" by a tree that held none of its changes (the rc4 full stage).
func (*Repository) ApplyToWorkingFiles ¶
func (r *Repository) ApplyToWorkingFiles(ctx context.Context, edits []FileEdit) error
ApplyToWorkingFiles writes edits into the checkout's working files, and nothing into its index or refs. Every file must still be as each edit's Before describes it: the same contents and executable bit, or absent. All are checked before any is written, so a file that changed since the edits were prepared leaves every file as it was.
func (*Repository) BoundaryGraph ¶ added in v0.8.1
func (r *Repository) BoundaryGraph(ctx context.Context, heads, masters []string) (CommitGraph, error)
BoundaryGraph lists commits reachable from any head but no master, and their parents, in one rev-list process. Excluded parents reached from the branch histories are returned as boundary commits.
func (*Repository) Branch ¶
Branch resolves a literal local branch, without revision-expression fallback.
func (*Repository) BranchWasAt ¶ added in v0.4.0
BranchWasAt reports whether a local branch's reflog shows it at an object at some time: the commit reset, fetched, or checked out onto it, as git reflog records each move. False where the branch has no reflog.
func (*Repository) Bundle ¶
Bundle writes a Git bundle at path holding commit under ref, less what the excluded commits already hold: a receiver needs those first.
func (*Repository) ChangedPaths ¶
ChangedPaths compares immutable commits or trees without rename folding, so moving a file exposes both its original and new paths to scope decisions.
func (*Repository) ChangedPathsOf ¶ added in v0.7.0
ChangedPathsOf is ChangedPaths for each pair of trees, in one git process: diff-tree reads the pairs on its input, and writes each pair's line before its paths. status read each branch's in one of its own (Then's item 6).
func (*Repository) Cherry ¶
func (r *Repository) Cherry(ctx context.Context, upstream, head string) ([]CherryCommit, error)
Cherry lists head's commits that upstream lacks, oldest first, each with whether upstream has its change all the same, by patch-id, as git cherry marks it "-": a branch merged by a rebase, as MacPorts merges, has its changes in master under other commits.
func (*Repository) CommitBefore ¶
func (r *Repository) CommitBefore(ctx context.Context, start string, before time.Time) (string, error)
CommitBefore is the newest first-parent ancestor of start, start itself included, committed at or before the instant; empty when none is.
func (*Repository) CommitTime ¶
CommitTime is the committer time of a commit.
func (*Repository) CommitTrees ¶
CommitTrees resolves immutable commit IDs in one Git invocation. Checking the original object as well as its tree rejects tags and trees that Git can peel.
func (*Repository) ComposeTree ¶
func (r *Repository) ComposeTree(ctx context.Context, onto, from string, paths []string) (string, error)
ComposeTree is onto's tree with each of paths as it is in from: its entry there, whatever its mode, or removed when from lacks it. Nothing but objects is written; a private index does the work.
func (*Repository) Conflicts ¶
func (r *Repository) Conflicts(ctx context.Context) ([]string, error)
Conflicts lists paths with unresolved merge conflicts.
func (*Repository) CountCommits ¶
CountCommits counts the commits reachable from head that base does not reach.
func (*Repository) CountCommitsNotIn ¶ added in v0.7.0
func (r *Repository) CountCommitsNotIn(ctx context.Context, base, head string, others []string) (int, error)
CountCommitsNotIn counts the commits reachable from head that base does not reach, and none of others does either.
func (*Repository) CountsFrom ¶ added in v0.7.0
func (r *Repository) CountsFrom(ctx context.Context, base string, branches []string) (map[string]int, error)
CountsFrom are how many commits each branch has that base doesn't, by the branch's name, in one git process, as CountCommits counts one; it needs AheadBehindVersion.
func (*Repository) CreateBranch ¶
func (r *Repository) CreateBranch(ctx context.Context, name, commit string) error
CreateBranch creates refs/heads/<name> at commit, refusing a branch that already exists rather than moving it.
func (*Repository) CurrentBranch ¶
func (r *Repository) CurrentBranch(ctx context.Context) (string, error)
func (*Repository) DeleteBranch ¶
func (r *Repository) DeleteBranch(ctx context.Context, name, commit string) error
DeleteBranch removes refs/heads/<name> only while it still points at commit, so a branch someone moved is never deleted.
func (*Repository) DeleteRemoteBranch ¶
func (r *Repository) DeleteRemoteBranch(ctx context.Context, remote, branch string, expected RefValue) error
DeleteRemoteBranch removes a remote branch only while it still holds the expected commit, using the same lease the push path relies on. A branch that is already gone is not an error; a moved branch is a RefConflict.
func (*Repository) DiffDirectories ¶
DiffDirectories is the patch from root/a to root/b, two directories outside any repository, as git diff --no-index makes it: a/ and b/ paths, and binary files named, not encoded.
func (*Repository) DiffTrees ¶
func (r *Repository) DiffTrees(ctx context.Context, before, after string, paths ...string) ([]byte, error)
DiffTrees is the patch from one tree to another, narrowed to paths when any are given.
func (*Repository) Directories ¶
func (r *Repository) Directories(ctx context.Context, tree string, paths []string) (map[string]string, error)
Directories maps each of paths that tree holds as a directory to its tree's object ID; a path the tree lacks is absent from the map.
func (*Repository) DirectoryTrees ¶ added in v0.8.0
func (r *Repository) DirectoryTrees(ctx context.Context, tree string, directories []string) (map[string]string, error)
DirectoryTrees are the tree IDs of directories within a tree, by directory, in one Git invocation; a directory the tree lacks is left out.
func (*Repository) EditTree ¶
EditTree writes new objects without moving refs or touching a worktree/index. All preconditions are checked against the same immutable input tree.
func (*Repository) Entries ¶ added in v0.8.0
Entries are the paths of the entries directly in each of dirs the tree holds, as dir/name, found in one listing; a directory the tree lacks gives none.
func (*Repository) ExistingPaths ¶
func (r *Repository) ExistingPaths(ctx context.Context, tree string, paths []string) ([]string, error)
ExistingPaths are those of the paths the tree holds, as files or directories, found in one listing.
func (*Repository) ExpandSparse ¶
func (r *Repository) ExpandSparse(ctx context.Context, directories ...string) error
ExpandSparse adds directories to the worktree's sparse cone and checks them out.
func (*Repository) FetchBranch ¶
func (r *Repository) FetchBranch(ctx context.Context, remote, branch string) (commit, tree string, err error)
FetchBranch freezes a remote branch without updating local branches, remote-tracking refs, or FETCH_HEAD. Concurrent fetches use separate refs.
func (*Repository) FetchPullRequest ¶
func (r *Repository) FetchPullRequest(ctx context.Context, remote, repository string, number int) (string, error)
FetchPullRequest fetches a GitHub pull request's head from remote, the repository (owner/name) it was opened in, into refs/dockhand/reviews/<owner>/<name>/<number>, where it stays for the next review, and returns its commit. The ref names the repository, so a sandbox's #145 and MacPorts' never share one (the rc6 full stage's G22). The ref of the number alone, refs/dockhand/reviews/<number>, which builds before kept, is never read, and is left as it is.
func (*Repository) FileBlobs ¶
func (r *Repository) FileBlobs(ctx context.Context, tree string, paths []string) (map[string]string, error)
FileBlobs maps each of paths that tree holds as a file to its object ID; a path the tree lacks is absent from the map.
func (*Repository) FilesBelow ¶ added in v0.7.0
FilesBelow are a tree's files below a directory, at any depth, each named by its path in the tree, as a port's Portfile and its files/ are, in ls-tree's order.
func (*Repository) FirstParentTrees ¶ added in v0.8.0
func (r *Repository) FirstParentTrees(ctx context.Context, start string, limit int) ([]DatedTree, error)
FirstParentTrees are the trees of start and its first-parent ancestors, newest first, at most limit of them, each with its commit's committer time: one rev-list, which a reader of what's cached by tree walks to find the newest it has, and dates what it found by.
func (*Repository) GrepTree ¶
func (r *Repository) GrepTree(ctx context.Context, tree, pattern string, pathspecs ...string) ([]string, error)
GrepTree lists the paths in a tree whose contents match an extended regular expression, within the pathspecs given, or every path with none.
func (*Repository) History ¶
func (r *Repository) History(ctx context.Context, base, head string) ([]HistoryCommit, error)
History lists the commits head has and base does not, oldest first.
func (*Repository) Ignored ¶
Ignored are the paths among those given that Git ignores, by a .gitignore in the worktree at any depth, .git/info/exclude, or core.excludesFile, as git check-ignore reads them: whatever Git itself would leave out of git add, dockhand leaves out too.
func (*Repository) IgnoredFiles ¶ added in v0.4.0
func (r *Repository) IgnoredFiles(ctx context.Context) ([]string, error)
IgnoredFiles lists the files in the checkout that Git ignores, as git ls-files --ignored reads them, a directory it ignores whole as one entry ending in a slash: what git worktree remove --force deletes with the worktree, unsaid.
func (*Repository) IndexTree ¶
func (r *Repository) IndexTree(ctx context.Context) (string, error)
IndexTree writes the index as it stands into a tree, as a commit would record it. Nothing but objects is written.
func (*Repository) IsAncestor ¶
IsAncestor reports whether ancestor is reachable from descendant.
func (*Repository) Materialize ¶
Materialize reads raw blobs, avoiding checkout filters and archive attributes. The returned directory is owned by the caller until Close.
func (*Repository) MaterializeInto ¶
func (r *Repository) MaterializeInto(ctx context.Context, tree, directory string, include []string, present map[string]bool) ([]TreeEntry, error)
MaterializeInto writes the tree's blobs under an existing directory: the paths the include pathspecs select, or every path with none, less the paths present already, which are skipped rather than created again. It returns the entries it wrote.
func (*Repository) MoveCheckout ¶
func (r *Repository) MoveCheckout(ctx context.Context, from, to string) error
MoveCheckout moves the branch this checkout has out, from commit from to commit to, with its index and working files, as git reset --keep does: the files that differ between the two are rewritten, within the checkout's sparse paths, and a local change to one of them, or an untracked file in the way, stops it with nothing changed. It is what undoes a rebase, whose files are the rebased commit's.
func (*Repository) NarrowSparse ¶
func (r *Repository) NarrowSparse(ctx context.Context, directories []string) error
NarrowSparse sets the worktree's sparse cone to directories, leaving the rest out; untracked files in a directory left out stay, as git leaves them.
func (*Repository) ObjectType ¶
func (*Repository) PruneWorktrees ¶
func (r *Repository) PruneWorktrees(ctx context.Context) error
PruneWorktrees forgets worktrees whose directories are gone, so their branches can be checked out again.
func (*Repository) Push ¶
func (r *Repository) Push(ctx context.Context, request Push) error
Push uses a literal destination ref and an explicit expected value, independent of remote-tracking refs. Repeating a confirmed desired head is a no-op.
func (*Repository) ReadFiles ¶
func (r *Repository) ReadFiles(ctx context.Context, tree string, paths []string) (map[string][]byte, error)
ReadFiles reads the blobs of a tree at the paths given, by path, in one process: a path the tree doesn't have, or that names a directory, is left out, and a symlink's is its target. Reading a few hundred Portfiles one at a time costs a process for each level of each path.
func (*Repository) ReadRefsMatching ¶ added in v0.7.0
func (r *Repository) ReadRefsMatching(ctx context.Context, pattern string) (map[string]RefValue, error)
ReadRefsMatching reads the refs a for-each-ref pattern matches, a glob such as refs/remotes/*/master, which a prefix can't say.
func (*Repository) RemoteHead ¶
func (*Repository) RemoveUnchangedWorktree ¶ added in v0.7.0
func (r *Repository) RemoveUnchangedWorktree(ctx context.Context, directory string) error
RemoveUnchangedWorktree removes a linked worktree as RemoveWorktree does, but git refuses one with tracked changes or untracked files, which go with no word where it forces.
func (*Repository) RemoveWorktree ¶
func (r *Repository) RemoveWorktree(ctx context.Context, directory string) error
RemoveWorktree removes a linked worktree and its administrative files, discarding its working files.
func (*Repository) RenameBranch ¶
func (r *Repository) RenameBranch(ctx context.Context, old, next string) error
RenameBranch renames refs/heads/<old> to refs/heads/<next>, with its reflog, and the worktree that has it checked out follows (git branch -m). A name another branch has is refused.
func (*Repository) Replay ¶
func (r *Repository) Replay(ctx context.Context, onto, upstream, head string, committer Signature) (string, []Replayed, error)
Replay replays the commits head has above upstream onto onto, as git rebase does, without touching a checkout or a ref, and returns the replayed head and what it made of each commit, which stops at a conflict as the replay does. Each commit's change is merged onto the replayed commit before it (git merge-tree, with the commit's parent as the merge base), and committed with its own author, date, and message, and the committer given. A commit whose change onto already has is dropped, as git rebase drops it; one that was empty to begin with is kept. A conflict is ErrRebaseConflict, naming the files, with nothing written that anything refers to. A merge commit is refused. It needs Git 2.40 or newer.
func (*Repository) ResetIndex ¶
func (r *Repository) ResetIndex(ctx context.Context) error
ResetIndex makes the index match HEAD and leaves the working files as they are: what follows moving a checked-out branch to a commit whose tree the working files already hold.
func (*Repository) SetIndex ¶
func (r *Repository) SetIndex(ctx context.Context, tree string) error
SetIndex makes the index hold a tree and leaves the working files as they are: what restores an index recorded earlier. It rewrites only the entries that differ, so a sparse checkout's entries outside its paths keep the skip-worktree bits a wholesale read-tree would drop, which would make every port outside them read as deleted.
func (*Repository) SparseCone ¶
func (r *Repository) SparseCone(ctx context.Context) ([]string, error)
SparseCone lists the worktree's sparse directories; empty when the checkout is not sparse.
func (*Repository) Switch ¶
func (r *Repository) Switch(ctx context.Context, branch string) error
Switch checks out an existing local branch in this checkout. Git refuses when the switch would overwrite local changes, and so does this.
func (*Repository) SwitchNew ¶ added in v0.4.0
func (r *Repository) SwitchNew(ctx context.Context, name string) error
SwitchNew starts a branch of a name at HEAD and checks it out, as git switch -c does: a detached HEAD on a branch of its own.
func (*Repository) TrackedChanges ¶
func (r *Repository) TrackedChanges(ctx context.Context) ([]string, error)
TrackedChanges lists tracked paths whose index or working contents differ from HEAD: the work a branch switch could displace. A rename lists both its paths. Untracked files are not listed.
func (*Repository) Untracked ¶
func (r *Repository) Untracked(ctx context.Context) ([]string, error)
Untracked lists files in the checkout that Git neither tracks nor ignores.
func (*Repository) UpdateRefs ¶
func (r *Repository) UpdateRefs(ctx context.Context, changes []RefChange) error
func (*Repository) WithBranchLock ¶
func (r *Repository) WithBranchLock(ctx context.Context, branch string, fn func(context.Context) error) (err error)
WithBranchLock serializes cooperating integrations across the state/ref gap. Keep the lock file: removing it could split waiters across different inodes.
func (*Repository) WithFiles ¶
WithFiles is tree with the named working files added as they are on disk, for untracked files a capture includes. Each must be a regular file.
func (*Repository) WorkingTree ¶
func (r *Repository) WorkingTree(ctx context.Context) (head, tree string, err error)
WorkingTree writes the checkout's tracked files, as they are on disk, into a tree: HEAD's tree with every tracked change applied, staged or not. A tracked file missing from disk is left out; untracked files are not read, and neither are files a sparse checkout leaves out. Nothing in the checkout, its index, or its refs changes; only objects are written. It returns HEAD's commit and the tree.
func (*Repository) Worktree ¶ added in v0.7.0
func (r *Repository) Worktree(root string) *Repository
Worktree is the repository's worktree at root, one AllCheckouts listed, opened without asking git where it is again.
func (*Repository) WriteCommit ¶
type Version ¶
type Version struct {
Major, Minor, Patch int
// Reported is all it said: "git version 2.54.0 (Apple Git-157)".
Reported string
// Path is the executable that said it.
Path string
}
Version is a Git's version, as git version reports it.
func ExecutableVersion ¶
ExecutableVersion runs the program's git, "git" on its PATH when empty, and reads its version.