Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CurrentBranch ¶
CurrentBranch returns the current branch name when dir is the root of a Git repository. Returns empty string if dir is not a repo, git is unavailable, or on error.
func Fetch ¶
Fetch updates the remote-tracking refs for dir.
This is the only function here that touches the network, and it exists so that reaching the network is something a user asks for by name. Discovery, status, and provenance must never call it.
func IsRepository ¶
IsRepository reports whether dir is the root of a checkout.
The check is for dir's own .git rather than asking Git, because `git status` inside a plain directory answers for the nearest enclosing repository. A plugins directory that happens to sit inside someone's home checkout would otherwise give every plugin that repository's commit.
Types ¶
type ChangeStatus ¶
type ChangeStatus string
const ( StatusAdded ChangeStatus = "added" StatusModified ChangeStatus = "modified" StatusDeleted ChangeStatus = "deleted" StatusRenamed ChangeStatus = "renamed" )
type ChangedFile ¶
type ChangedFile struct {
Path string `json:"path"`
OldPath string `json:"old_path,omitempty"`
Status ChangeStatus `json:"status"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
Patch string `json:"patch,omitempty"`
Binary bool `json:"binary,omitempty"`
Truncated bool `json:"truncated,omitempty"`
}
type Status ¶
type Status struct {
// Commit is the full hash HEAD points at, empty on an unborn branch.
Commit string
// Branch is empty when HEAD is detached.
Branch string
Detached bool
// Dirty covers tracked modifications and untracked files alike: either
// means the directory is not the commit it names.
Dirty bool
// HasUpstream reports whether the branch tracks one. Ahead and Behind
// count commits against the tracking ref as it is known locally, so they
// are only current for as long as the last fetch is.
HasUpstream bool
Ahead int
Behind int
}
Status is what local Git metadata says about a working tree.
Nothing here contacts a remote. Plugin discovery may never make a network request, and a status read that could block on the network would put that invariant one flag away from being broken.
func ReadStatus ¶
ReadStatus reads commit, branch, and dirty state in one Git invocation.
Porcelain v2 reports all three: the header lines carry the commit and branch, and any non-header line is a change. Asking separately would cost a process per fact on a path a run repeats.
type WorkspaceDiff ¶
type WorkspaceDiff struct {
Workspace string `json:"workspace"`
Files []ChangedFile `json:"files"`
Error string `json:"error,omitempty"`
}
func ReadWorkspace ¶
func ReadWorkspace(ctx context.Context, workspace string) (WorkspaceDiff, error)