workspaces

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package workspaces removes and unregisters workspaces, refusing whatever would lose work.

Index

Constants

View Source
const (
	KindRemoved      = "workspace_removed"      // Key = workspace id, Data = "branch <b> head <sha>"
	KindUnregistered = "workspace_unregistered" // Key = workspace id, Data = "branch <b> head unknown"
)

The kinds of the events a removal and an unregistration write.

View Source
const NotACheckout = "not a git checkout"

NotACheckout is the refusal of a workspace path without a .git entry, where git would read an enclosing repository instead.

View Source
const NotFetchedToday = "not fetched today"

NotFetchedToday is the refusal of a workspace whose remote was not fetched on the clock's current day; Fetch lifts it.

Variables

This section is empty.

Functions

func Disposable

func Disposable(list []string, rel string) bool

Disposable tells whether rel, a clean slash path, names an entry of list in any of its parts or is compiled Python.

Types

type FetchLog

type FetchLog interface {
	Last(ctx context.Context, id string) (time.Time, error)
	Mark(ctx context.Context, id string, at time.Time) error
}

FetchLog records when each workspace was last fetched.

type Files

type Files interface {
	// Same tells whether a and b hold the same bytes; directories compare
	// entry by entry. A missing side is not the same.
	Same(a, b string) (bool, error)
	Exists(path string) bool
	// Link tells whether path is a symbolic link.
	Link(path string) bool
	// Repos lists the git repositories at or below dir by slash path
	// relative to it, "." for dir itself, looking into none of them.
	Repos(dir string) ([]string, error)
}

Files compares and inspects paths on disk.

type Manager

type Manager interface {
	List(ctx context.Context) ([]workspace.Workspace, error)
	Repos(ctx context.Context) ([]workspace.Repo, error)
	Remove(ctx context.Context, id string, force bool) error
	Unregister(ctx context.Context, id string) error
}

Manager is the workspace manager as removal sees it.

type PRInfo

type PRInfo struct {
	Unit   unit.Unit
	Number int
	Head   string
	Open   bool
}

PRInfo is the pull request a workspace belongs to; zero when none.

type Refusal

type Refusal struct {
	Reason string
	Backup string
	Paths  []string
}

Refusal is why a removal does not run. Backup is the command that saves the commits it would lose, Paths the files it would lose.

func (Refusal) Error

func (r Refusal) Error() string

type Remote

type Remote interface {
	// Tracking is the remote and branch the checkout's branch tracks: origin
	// and "" when it tracks none.
	Tracking(ctx context.Context, dir string) (remote, branch string, err error)
	// FetchTracking fetches the tracked remote, the pull request's head when
	// number is set, and forgets the tracked branch when the remote no
	// longer has it.
	FetchTracking(ctx context.Context, dir string, number int) error
	RemoteHasBranch(ctx context.Context, dir, remote, branch string) (bool, error)
	// Unpushed counts the commits of HEAD that no remote-tracking ref holds.
	Unpushed(ctx context.Context, dir string) (int, error)
	// PRHolds tells whether prHead contains HEAD; an unknown prHead holds
	// nothing.
	PRHolds(ctx context.Context, dir, prHead string) (bool, error)
}

Remote is what the remotes hold of a checkout. Only FetchTracking reaches the network; the rest read what the last fetch left.

type Rounds

type Rounds interface {
	SkipFirstRound(ctx context.Context, u unit.Unit) error
}

Rounds opts a pull request out of its automatic first round.

type Service

type Service struct {
	Manager  Manager
	Remote   Remote
	Tree     Tree
	Sessions SessionGuard
	Files    Files
	Rounds   Rounds
	Fetched  FetchLog
	// Disposable names the files and directories removal may lose.
	Disposable func() []string
	// Viewer is the user's login, the prefix of a backup branch.
	Viewer func() string
	Pub    port.Publisher
	Clock  port.Clock
}

Service removes and unregisters workspaces behind the guards.

func (*Service) Fetch

func (s *Service) Fetch(ctx context.Context, w workspace.Workspace, pr PRInfo) error

Fetch fetches w's remote and records the day; the guards read what it fetched.

func (*Service) Loose

func (s *Service) Loose(ctx context.Context, w workspace.Workspace) ([]string, error)

Loose lists the untracked and ignored paths of w that removing it would lose: a nested repository holding anything its remotes lack, and any other path outside the disposable list, not a symbolic link and not identical to the main checkout's copy.

func (*Service) Remove

func (s *Service) Remove(ctx context.Context, w workspace.Workspace, pr PRInfo, force bool) error

Remove closes w's sessions and removes it, recording its branch and head. Without force it fetches and checks again, then, with the sessions closed, looks a last time right before the removal, returning a Refusal when anything would be lost. Removing an open pull request's workspace opts the pull request out of its automatic first round.

func (*Service) RemoveRefusal

func (s *Service) RemoveRefusal(ctx context.Context, w workspace.Workspace, pr PRInfo) (refusal, backup string, err error)

RemoveRefusal is why removing w would lose work, "" when nothing would be lost, with the command that backs up its commits when they are the reason. It fetches nothing and writes nothing.

func (*Service) RemoveRefusalAsFetched

func (s *Service) RemoveRefusalAsFetched(ctx context.Context, w workspace.Workspace, pr PRInfo) (refusal, backup string, err error)

RemoveRefusalAsFetched is RemoveRefusal on what the last fetch left, however old.

func (*Service) Unregister

func (s *Service) Unregister(ctx context.Context, w workspace.Workspace) error

Unregister drops w from the manager once its checkout is gone.

type SessionGuard

type SessionGuard interface {
	// Refusal is why a live session of the workspace may not be closed, ""
	// when every one may.
	Refusal(ctx context.Context, workspaceID string) (string, error)
	// CloseAll closes the workspace's live sessions, each recording its
	// resume line.
	CloseAll(ctx context.Context, workspaceID, reason string) error
}

SessionGuard is what the agent sessions of a workspace allow.

type Tree

type Tree interface {
	// Changed counts modified and untracked files.
	Changed(ctx context.Context, dir string) (int, error)
	// DirtyTracked counts modified tracked files.
	DirtyTracked(ctx context.Context, dir string) (int, error)
	// Ignored lists the untracked files and the ignored paths; an ignored
	// directory, or an untracked repository, is one entry ending in "/",
	// what it holds unlisted.
	Ignored(ctx context.Context, dir string) (untracked, ignored []string, err error)
	Head(ctx context.Context, dir string) (string, error)
	// Kept is what the repository at dir holds that no remote has: commits
	// any local ref or HEAD reaches, a stash, or no remote at all; "" when
	// nothing.
	Kept(ctx context.Context, dir string) (string, error)
}

Tree is the working tree of a checkout.

Directories

Path Synopsis
Package workspacestest holds the fakes of the workspaces ports, the checkouts they stand for, and the contracts every implementation passes.
Package workspacestest holds the fakes of the workspaces ports, the checkouts they stand for, and the contracts every implementation passes.

Jump to

Keyboard shortcuts

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