worktreedelete

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 9 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 worktreedelete owns the "Delete Worktree?" confirmation shared by every surface that can delete a worktree.

The project workspace (internal/plugins/workspace) and the global Workspaces browser (internal/overview) are two projections of one model, so the confirmation they raise must be one construction, not two that resemble each other. This package holds the whole of it: the modal's sections, the branch cleanup options, and the key/mouse routing that turns a press into a decision. Hosts own only what is genuinely theirs — how the target is selected, and how the deletion is executed afterwards.

Index

Constants

View Source
const (
	LocalBranchID  = "delete-confirm-local-branch"
	RemoteBranchID = "delete-confirm-remote-branch"
	DeleteID       = "delete-confirm-delete"
	CancelID       = "delete-confirm-cancel"
)

Action IDs. They are exported because hosts route mouse and keyboard actions through the same identifiers.

View Source
const (
	// DirtyLine is shown only when git reported work that removal would destroy.
	DirtyLine = "Uncommitted changes will be lost"
	// CleanLine is shown when git reported a clean worktree.
	CleanLine = "No uncommitted changes to lose"
	// UnknownDirtinessLine is shown until git answers, and if it cannot.
	UnknownDirtinessLine = "Checking for uncommitted changes…"
)

The three things the confirmation can say about uncommitted work. They are exported so each host's tests assert against the shared wording rather than its own copy of it.

View Source
const Title = "Delete Worktree?"

Title is the confirmation's heading. Exported so a host's tests can assert the shared modal is the one on screen.

View Source
const Width = 58

Width is the confirmation's preferred width before clamping.

Variables

This section is empty.

Functions

func ClampWidth

func ClampWidth(avail int) int

ClampWidth is the confirmation's width on a surface `avail` cells wide.

Types

type Dirtiness

type Dirtiness int

Dirtiness is what the host knows about uncommitted work in the target.

It is three values rather than a bool because a confirmation opens before git can answer: "we have not asked yet" and "we asked and it is clean" are different sentences, and rendering the second while the first is true would be the same lie as the old unconditional warning, only pointed the other way.

const (
	// DirtinessUnknown means no answer has arrived — or git could not give one.
	DirtinessUnknown Dirtiness = iota
	// DirtinessClean means git reported nothing to lose.
	DirtinessClean
	// DirtinessDirty means git reported uncommitted or untracked work.
	DirtinessDirty
)

func ProbeDirtiness

func ProbeDirtiness(ctx context.Context, path string, missing bool) Dirtiness

ProbeDirtiness asks git whether a worktree holds work a removal would destroy, in the form the confirmation renders.

Both hosts call this, off the keypress path, when the confirmation opens — one `git status` for the one worktree the user named, rather than a status per worktree per inventory refresh. An unreadable worktree stays Unknown: telling a user their worktree is clean because git failed is exactly the reassurance this ticket exists to remove. A missing directory is Unknown too; the confirmation already says the directory is gone.

type Outcome

type Outcome int

Outcome is what a key or click asked for.

const (
	// OutcomeNone means the input was absorbed without a decision.
	OutcomeNone Outcome = iota
	// OutcomeConfirm means the user asked for the deletion to proceed.
	OutcomeConfirm
	// OutcomeCancel means the user dismissed the confirmation.
	OutcomeCancel
)

type State

type State struct {

	// IsMainBranch protects the repository's primary branch: while true the
	// branch cleanup options are not offered at all.
	IsMainBranch bool
	// HasRemote reports that the branch exists on origin. Hosts may resolve it
	// asynchronously; the modal reads it at render time.
	HasRemote bool
	// DeleteLocal and DeleteRemote are the optional branch cleanup choices.
	DeleteLocal  bool
	DeleteRemote bool

	// Dirty is what git says about uncommitted work in the target. Hosts
	// resolve it asynchronously, as they do HasRemote, and call Invalidate.
	Dirty Dirtiness
	// contains filtered or unexported fields
}

State is one open confirmation. The zero value is closed.

func (*State) Active

func (s *State) Active() bool

Active reports that a confirmation is open.

func (*State) Clear

func (s *State) Clear()

Clear closes the confirmation and drops its state.

func (*State) DeleteRemoteBranch

func (s *State) DeleteRemoteBranch() bool

DeleteRemoteBranch reports whether the remote branch should be deleted: the box is only meaningful when a remote branch was actually found.

func (*State) HandleKey

func (s *State) HandleKey(avail int, msg tea.KeyPressMsg) (Outcome, tea.Cmd)

HandleKey routes a key press to the open confirmation. Hosts act on the returned outcome; the tea.Cmd belongs to the modal's own widgets.

func (*State) HandleMouse

func (s *State) HandleMouse(avail int, msg tea.MouseMsg, handler *mouse.Handler) Outcome

HandleMouse routes a mouse event to the open confirmation.

func (*State) Invalidate

func (s *State) Invalidate()

Invalidate discards the cached modal so the next render rebuilds it. Hosts call it after an asynchronous answer (remote branch existence) lands.

func (*State) Modal

func (s *State) Modal(avail int) *modal.Modal

Modal builds (and caches) the confirmation for a surface `avail` cells wide. It returns nil while no confirmation is open.

func (*State) Open

func (s *State) Open(target Target, isMainBranch bool)

Open arms the confirmation for a target. isMainBranch is the host's answer about the repository's primary branch; HasRemote may be filled in later.

func (*State) Target

func (s *State) Target() Target

Target is the worktree the open confirmation refers to.

func (*State) WheelAtBoundary

func (s *State) WheelAtBoundary(avail int, msg tea.MouseWheelMsg, handler *mouse.Handler) bool

WheelAtBoundary reports that the confirmation cannot scroll further, so the host may pass the wheel on.

type Target

type Target struct {
	Name      string
	Branch    string
	Path      string
	IsMissing bool
}

Target is the presentation-neutral identity of the worktree being deleted.

Jump to

Keyboard shortcuts

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