Documentation
¶
Overview ¶
Package create provides functionality for creating new stacked branches.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Deps ¶ added in v0.30.1
type Deps struct {
Engine Engine
actions.MutationDeps
Log output.Logger
// Verify runs git commit hooks when set (the inverse of --no-verify).
Verify bool
// Worktrees backs --worktree; it may be nil when --worktree is not used.
Worktrees Worktrees
}
Deps are the collaborators create needs. Adapters build them from their own runtime state; the action never sees bootstrap types.
type Engine ¶ added in v0.30.1
type Engine interface {
validation.BranchValidationEngine
actions.OwnershipEngine
CurrentBranch(ctx context.Context) *engine.Branch
Trunk() engine.Branch
IsTrunk(branch engine.Branch) bool
AllBranches() engine.Branches
BranchNames() *engine.BranchSet
Graph(ctx context.Context, strategy engine.SortStrategy) *engine.StackGraph
SortBranchesTopologically(ctx context.Context, branches engine.Branches) engine.Branches
GetScope(branch engine.Branch) engine.Scope
SetScope(ctx context.Context, branch engine.Branch, scope engine.Scope) error
GetUserName(ctx context.Context) (string, error)
GetWorkingTreeStatus(ctx context.Context) (git.WorktreeStatus, error)
GetCommitTemplate(ctx context.Context) (string, error)
StageChanges(ctx context.Context, opts git.StagingOptions) error
StageAll(ctx context.Context) error
Commit(ctx context.Context, opts git.CommitOptions) error
CreateBranch(ctx context.Context, branchName string, startPoint string) error
CreateAndCheckoutBranch(ctx context.Context, branch engine.Branch) error
CheckoutBranch(ctx context.Context, branch engine.Branch) error
DeleteBranch(ctx context.Context, branch engine.Branch) error
TrackBranch(ctx context.Context, branchName string, parentBranchName string) error
ReparentBranchesToParents(ctx context.Context, moves []engine.BranchParentMove, opts engine.ReparentOpts) error
RestackBranches(ctx context.Context, branches engine.Branches, opts engine.RestackOpts) (engine.RestackBatchResult, error)
ConfigureRemoteMetadataSync(ctx context.Context) error
}
Engine lists exactly the engine methods create calls.
type Handler ¶
type Handler interface {
// Start is called at the beginning of create
Start(parentBranch string)
// OnStep is called for each step in the create process
OnStep(step Step, status handler.StepStatus, message string)
// Complete is called when create finishes
Complete(result Result)
// Cleanup restores terminal state (may be no-op)
Cleanup()
// IsInteractive returns true if the handler supports interactive prompts
IsInteractive() bool
// PromptStageChanges prompts user to stage unstaged changes
PromptStageChanges() (bool, error)
// PromptScope prompts user for a scope value when pattern contains {scope}
// The patternHint shows the current branch pattern to the user
PromptScope(patternHint string) (string, error)
// PromptChildToMove asks which of the current branch's children should be
// moved onto a newly inserted branch. Returns "all" to move every child, or
// a specific child name. Only called when IsInteractive() is true.
PromptChildToMove(children []string) (string, error)
}
Handler receives events from create action
type NullHandler ¶
type NullHandler struct {
handler.NullBase
handler.NullProgress[Step]
}
NullHandler is a no-op handler for when nil is passed
func (*NullHandler) Complete ¶
func (h *NullHandler) Complete(_ Result)
Complete implements Handler.
func (*NullHandler) PromptChildToMove ¶ added in v0.27.1
func (h *NullHandler) PromptChildToMove(_ []string) (string, error)
PromptChildToMove implements Handler. Returns "all" (move every child).
func (*NullHandler) PromptScope ¶
func (h *NullHandler) PromptScope(_ string) (string, error)
PromptScope implements Handler.
func (*NullHandler) PromptStageChanges ¶
func (h *NullHandler) PromptStageChanges() (bool, error)
PromptStageChanges implements Handler.
type Options ¶
type Options struct {
BranchName string
Message string
Scope string
All bool
Insert bool
Patch bool
Update bool
Verbose int
BranchPattern config.BranchPattern
// SelectedChildren is used to specify which children to move during insert
// in non-interactive mode (mostly for tests)
SelectedChildren []string
// Onto creates the branch as a tracked child of this branch instead of the
// current branch, without checking it out. Mutually exclusive with
// Worktree and Insert.
Onto string
// Worktree creates a dedicated worktree for this stack (only valid from trunk)
Worktree bool
// AllowEmpty permits creating a branch with no commit when the working tree
// has unstaged/untracked changes in non-interactive mode (otherwise that is
// treated as a "forgot to stage" mistake and rejected).
AllowEmpty bool
}
Options contains options for the create command
type Result ¶
type Result struct {
BranchName string
ParentBranch string
HasCommit bool
WorktreePath engine.WorktreePath
}
Result contains the result of the create action.
type Worktrees ¶ added in v0.30.1
type Worktrees interface {
// CreateAnchored creates a managed worktree anchored on branchName and
// returns its path.
CreateAnchored(ctx context.Context, branchName, name, scope string) (engine.WorktreePath, error)
// RunPostCreateHooks runs the configured post-create hooks in path.
RunPostCreateHooks(ctx context.Context, path engine.WorktreePath) error
}
Worktrees creates the dedicated worktree for `create --worktree`. Adapters implement it on top of the worktree actions.