Documentation
¶
Overview ¶
Package gitstatus reads the git state of session checkouts: branch, dirty tree, unpushed commits and the line delta against the default branch.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RemoteCoordinates ¶
RemoteCoordinates reads the host, owner and repo off a remote. The host is lowered so a forge match and a cache key are canonical however the remote spells it.
A remote naming no host returns nothing: git.ExtractOwnerRepo is host-agnostic and would read the last two path segments of a local path.
Types ¶
type Git ¶
type Git interface {
Branch(ctx context.Context, dir string) (string, error)
IsClean(ctx context.Context, dir string) (bool, error)
HasUnpushedCommits(ctx context.Context, dir string) (bool, error)
DiffStats(ctx context.Context, dir string) (additions, deletions int, err error)
}
Git is the subset of git.Git a status read needs.
type Options ¶
type Options struct {
Unpushed bool
}
Options picks the optional reads. The unpushed check costs up to three git calls, so a caller that does not show it leaves it off.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
NewService returns a Service that runs at most workers reads at once in a batch. A workers value below one means one.
func (*Service) Read ¶
Read reads one checkout. A failed branch read stands for the whole status, because every other read needs the working checkout it proves.
func (*Service) ReadBatch ¶
ReadBatch reads every path, each under its own timeout, with at most the service's worker count running at once.
func (*Service) ReadSession ¶
ReadSession reads a session's checkout with every read, and adds the remote's coordinates. A session with no checkout (not active, or no path) returns the zero Status: there is nothing to read, which is not a failure.
type Status ¶
type Status struct {
Path string
Branch string
Dirty bool
Unpushed bool
// Additions and Deletions are lines against the default branch, not HEAD.
Additions int
Deletions int
// Host, Owner and Repo are the remote's coordinates. They are empty for a
// remote that names no host, such as a local path.
Host string
Owner string
Repo string
Resolved bool
// Err is the first failed read of the branch, the dirty check or the diff.
Err error
// UnpushedErr is kept apart from Err because a branch with no upstream
// fails this read on every poll, and that must not hide the rest.
UnpushedErr error
}
Status is one checkout's git state.
Resolved separates "git answered" from the zero value. Err carries why a read failed and is never a substitute for it: a failed IsClean leaves Dirty false rather than assuming dirty, because a badge claiming uncommitted work on a git that never ran is a lie the user acts on.