Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

refactor(create): route insert's child-select prompt through the Handler #1241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jonnii wants to merge 1 commit into jonnii/20260605032227/extract-OpenEditor-into-internal/editor-out-of
base: jonnii/20260605032227/extract-OpenEditor-into-internal/editor-out-of
Choose a base branch
Loading
from jonnii/20260605033020/route-insert-s-child-select-prompt-through-the
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/actions/create/create.go
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func Action(ctx *app.Context, opts Options, h Handler) (Result, error) {
// Handle insert logic
if opts.Insert {
h.OnStep(StepInsert, handler.StatusStarted, "Inserting branch into stack")
if err := handleInsert(ctx.Context, branchName, currentBranch, ctx, &opts); err != nil {
if err := handleInsert(ctx.Context, branchName, currentBranch, ctx, &opts, h); err != nil {
h.OnStep(StepInsert, handler.StatusFailed, err.Error())
out.Info("Warning: failed to insert branch: %v", err)
} else {
Expand Down
8 changes: 8 additions & 0 deletions internal/actions/create/handler.go
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ type Handler interface {
// 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)
}

// NullHandler is a no-op handler for when nil is passed
Expand All @@ -67,3 +72,6 @@ func (h *NullHandler) PromptStageChanges() (bool, error) { return false, nil }

// PromptScope implements Handler.
func (h *NullHandler) PromptScope(_ string) (string, error) { return "", nil }

// PromptChildToMove implements Handler. Returns "all" (move every child).
func (h *NullHandler) PromptChildToMove(_ []string) (string, error) { return "all", nil }
15 changes: 3 additions & 12 deletions internal/actions/create/insert.go
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import (

"github.com/getstackit/stackit/internal/app"
"github.com/getstackit/stackit/internal/engine"
"github.com/getstackit/stackit/internal/tui"
"github.com/getstackit/stackit/internal/utils"
)

func handleInsert(ctx context.Context, newBranch, currentBranch string, runtimeCtx *app.Context, opts *Options) error {
func handleInsert(ctx context.Context, newBranch, currentBranch string, runtimeCtx *app.Context, opts *Options, h Handler) error {
// Build StackGraph for efficient traversals
graph := runtimeCtx.Engine.Graph(engine.SortStrategyAlphabetical)

Expand Down Expand Up @@ -39,16 +37,9 @@ func handleInsert(ctx context.Context, newBranch, currentBranch string, runtimeC
}
}
}
case len(siblings) > 1 && utils.IsInteractive():
case len(siblings) > 1 && h.IsInteractive():
runtimeCtx.Output.Info("Current branch has multiple children. Select which should be moved onto the new branch:")
options := []tui.SelectOption{
{Label: "All children", Value: "all"},
}
for _, child := range siblings {
options = append(options, tui.SelectOption{Label: child, Value: child})
}

selected, err := tui.PromptSelect("Which child should be moved onto the new branch?", options, 0)
selected, err := h.PromptChildToMove(siblings)
if err != nil {
return err
}
Expand Down
16 changes: 16 additions & 0 deletions internal/cli/branch/create_handlers.go
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ func (h *SimpleCreateHandler) PromptScope(_ string) (string, error) {
return "", nil
}

// PromptChildToMove returns "all" for the simple handler (non-interactive).
func (h *SimpleCreateHandler) PromptChildToMove(_ []string) (string, error) {
return "all", nil
}

func (h *SimpleCreateHandler) printStepCompleted(_ create.Step, _ string) {
// Most steps are silent - output is handled in Complete
// Only show certain steps for verbose feedback
Expand Down Expand Up @@ -113,3 +118,14 @@ func (h *InteractiveCreateHandler) PromptScope(patternHint string) (string, erro
prompt := fmt.Sprintf("Branch pattern uses {scope}: %s\nEnter scope (or Enter to skip):", patternHint)
return tui.PromptTextInput(prompt, "")
}

// PromptChildToMove asks which child branch to move onto the newly inserted
// branch, offering an "All children" option plus each child individually.
func (h *InteractiveCreateHandler) PromptChildToMove(children []string) (string, error) {
options := make([]tui.SelectOption, 0, 1+len(children))
options = append(options, tui.SelectOption{Label: "All children", Value: "all"})
for _, child := range children {
options = append(options, tui.SelectOption{Label: child, Value: child})
}
return tui.PromptSelect("Which child should be moved onto the new branch?", options, 0)
}
Loading

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /