Help us shape the future of Go! Take the 2026 Go Developer Survey

gitstatus

package
v0.60.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 8 Imported by: 0

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

func RemoteCoordinates(remote string) (host, owner, repo string)

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

func NewService(logger zerolog.Logger, g Git, workers int) *Service

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

func (s *Service) Read(ctx context.Context, path string, opts Options) Status

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

func (s *Service) ReadBatch(ctx context.Context, paths []string, opts Options) map[string]Status

ReadBatch reads every path, each under its own timeout, with at most the service's worker count running at once.

func (*Service) ReadSession

func (s *Service) ReadSession(ctx context.Context, sess session.Session) Status

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.

func (Status) Error

func (s Status) Error() error

Error returns the failure a caller shows, preferring a checkout read over the routine unpushed failure.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL