Documentation
¶
Overview ¶
Package workspaces removes and unregisters workspaces, refusing whatever would lose work.
Index ¶
- Constants
- func Disposable(list []string, rel string) bool
- type FetchLog
- type Files
- type Manager
- type PRInfo
- type Refusal
- type Remote
- type Rounds
- type Service
- func (s *Service) Fetch(ctx context.Context, w workspace.Workspace, pr PRInfo) error
- func (s *Service) Loose(ctx context.Context, w workspace.Workspace) ([]string, error)
- func (s *Service) Remove(ctx context.Context, w workspace.Workspace, pr PRInfo, force bool) error
- func (s *Service) RemoveRefusal(ctx context.Context, w workspace.Workspace, pr PRInfo) (refusal, backup string, err error)
- func (s *Service) RemoveRefusalAsFetched(ctx context.Context, w workspace.Workspace, pr PRInfo) (refusal, backup string, err error)
- func (s *Service) Unregister(ctx context.Context, w workspace.Workspace) error
- type SessionGuard
- type Tree
Constants ¶
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.
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.
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 ¶
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 Refusal ¶
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.
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 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 ¶
Fetch fetches w's remote and records the day; the guards read what it fetched.
func (*Service) Loose ¶
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 ¶
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.
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. |