Skip to content

insert branches with modify#107

Draft
skarim wants to merge 1 commit into
skarim/modify-only-block-pr-changesfrom
skarim/insert-branch
Draft

insert branches with modify#107
skarim wants to merge 1 commit into
skarim/modify-only-block-pr-changesfrom
skarim/insert-branch

Conversation

@skarim
Copy link
Copy Markdown
Collaborator

@skarim skarim commented May 22, 2026

add insert branch operation to modify TUI

Add i (insert below) and I (insert above) key bindings to the
interactive modify view, allowing users to insert new empty branches
into an existing stack. This follows Vim-inspired semantics where
lowercase i inserts below the cursor and uppercase I inserts above.

TUI behavior

When the user presses i or I, the TUI enters an insert input mode
(similar to rename mode) where they type a new branch name. The input
is validated against git ref naming rules, local branch uniqueness, and
in-stack name collisions. On confirm, a placeholder node is inserted at
the correct position in the branch list with a green "✚ insert"
annotation badge and green connector styling.

Insert is a structure operation — it works alongside fold, rename, and
drop, but is mutually exclusive with reorder (consistent with existing
mode exclusivity rules). Undo (z) removes the inserted node cleanly.

Apply engine

At apply time (Step 2 in the pipeline, between renames and folds), the
engine creates the new git branch at the parent branch's tip via
git.CreateBranch and inserts a BranchRef into the stack metadata at
the correct position. If the insertion changes the base of a branch
that has an open PR, affectsPRs is set to trigger a required
gh stack submit afterward.

Header shortcut updates

  • Combined the fold shortcuts into a single line: d/u - fold down/up
  • Added insert shortcuts on their own line: i/I - insert below/above
  • Reordered fold references throughout to list "down" before "up" for
    consistency with the insert shortcut ordering

Files changed

  • types.go: ActionInsertBelow/ActionInsertAbove types, IsInserted field,
    InsertedBranches in ApplyResult
  • model.go: key bindings, insert input mode, undo, mode exclusivity,
    annotation, styling, header shortcuts, effective-index tracking to
    prevent false reorder detection when inserts shift node positions
  • styles.go: green insert badge/branch/connector styles
  • status.go: insert counting in pending change summary
  • help.go: new "Insert below / above" section, reordered fold heading
  • apply.go: BuildPlan and ApplyPlan handle insert actions
  • modify.go: updated command description and success summary
  • README.md: updated keybindings table

Test coverage

  • 16 new TUI tests: insert below/above, top/bottom edges, undo, mode
    exclusivity, merged branch guard, cancel/empty input, duplicate name
    validation, pending summary counting, annotation rendering, mixed
    operations with drop/fold, apply acceptance
  • 4 new apply tests: BuildPlan produces correct insert actions,
    ApplyPlan creates branches and updates stack metadata, insert at
    stack start uses trunk as parent, affectsPRs triggered when inserting
    before a branch with an open PR

Stack created with GitHub Stacks CLIGive Feedback 💬

Add `i` (insert below) and `I` (insert above) key bindings to the
interactive modify view, allowing users to insert new empty branches
into an existing stack. This follows Vim-inspired semantics where
lowercase `i` inserts below the cursor and uppercase `I` inserts above.

## TUI behavior

When the user presses `i` or `I`, the TUI enters an insert input mode
(similar to rename mode) where they type a new branch name. The input
is validated against git ref naming rules, local branch uniqueness, and
in-stack name collisions. On confirm, a placeholder node is inserted at
the correct position in the branch list with a green "✚ insert"
annotation badge and green connector styling.

Insert is a structure operation — it works alongside fold, rename, and
drop, but is mutually exclusive with reorder (consistent with existing
mode exclusivity rules). Undo (`z`) removes the inserted node cleanly.

## Apply engine

At apply time (Step 2 in the pipeline, between renames and folds), the
engine creates the new git branch at the parent branch's tip via
`git.CreateBranch` and inserts a `BranchRef` into the stack metadata at
the correct position. If the insertion changes the base of a branch
that has an open PR, `affectsPRs` is set to trigger a required
`gh stack submit` afterward.

## Header shortcut updates

- Combined the fold shortcuts into a single line: `d/u - fold down/up`
- Added insert shortcuts on their own line: `i/I - insert below/above`
- Reordered fold references throughout to list "down" before "up" for
  consistency with the insert shortcut ordering

## Files changed

- types.go: ActionInsertBelow/ActionInsertAbove types, IsInserted field,
  InsertedBranches in ApplyResult
- model.go: key bindings, insert input mode, undo, mode exclusivity,
  annotation, styling, header shortcuts, effective-index tracking to
  prevent false reorder detection when inserts shift node positions
- styles.go: green insert badge/branch/connector styles
- status.go: insert counting in pending change summary
- help.go: new "Insert below / above" section, reordered fold heading
- apply.go: BuildPlan and ApplyPlan handle insert actions
- modify.go: updated command description and success summary
- README.md: updated keybindings table

## Test coverage

- 16 new TUI tests: insert below/above, top/bottom edges, undo, mode
  exclusivity, merged branch guard, cancel/empty input, duplicate name
  validation, pending summary counting, annotation rendering, mixed
  operations with drop/fold, apply acceptance
- 4 new apply tests: BuildPlan produces correct insert actions,
  ApplyPlan creates branches and updates stack metadata, insert at
  stack start uses trunk as parent, affectsPRs triggered when inserting
  before a branch with an open PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant