Documentation
¶
Overview ¶
Package worktree provides utilities for executing operations in Git worktrees.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RemovePath ¶ added in v0.25.0
func RemovePath(ctx context.Context, eng engine.Engine, path string, policy RemovalPolicy) (removed bool, err error)
RemovePath removes a linked worktree when its directory exists. A missing directory is not an error: callers can prune Git's stale administrative entry according to their own lifecycle policy.
Types ¶
type CreateSessionOptions ¶
type CreateSessionOptions struct {
// Ref is the git ref (branch, commit, tag) to checkout in the worktree.
// If empty, defaults to trunk.
Ref string
// NamePattern is the pattern for the worktree directory name.
// Uses Go's os.MkdirTemp pattern (e.g., "stackit-work-*").
NamePattern string
// PullTrunk determines whether to pull the latest trunk before returning.
// Only applicable when Ref is trunk or empty.
PullTrunk bool
}
CreateSessionOptions configures how a worktree session is created.
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor creates and manages temporary worktrees for executing operations.
func NewExecutor ¶
NewExecutor creates a new worktree executor.
func (*Executor) CreateSession ¶
CreateSession creates a new worktree session. The caller is responsible for calling Close() on the returned session.
type RemovalPolicy ¶ added in v0.25.0
type RemovalPolicy uint8
RemovalPolicy makes the destructive intent of worktree removal explicit.
const ( RemovalRespectChanges RemovalPolicy = iota RemovalDiscardChanges )
func (RemovalPolicy) DiscardsChanges ¶ added in v0.25.0
func (p RemovalPolicy) DiscardsChanges() bool
DiscardsChanges reports whether removal may discard uncommitted changes.
type Session ¶
type Session struct {
Path engine.WorktreePath // Path to the worktree directory
Engine engine.Engine // Engine initialized for the worktree
// contains filtered or unexported fields
}
Session represents an active worktree session that can be used to execute operations. The caller must call Close() when done to clean up the worktree.
func (*Session) Close ¶
func (s *Session) Close()
Close cleans up the worktree session. This should be called when done with the session.
func (*Session) GetCurrentRevision ¶
GetCurrentRevision returns the current commit SHA of the worktree.
func (*Session) ResetToRef ¶
ResetToRef resets the worktree to the specified ref.