Skip to content

set-parent: allow selecting a parent that is checked out in another worktree - #6298

Merged
kevgo merged 1 commit into
git-town:mainfrom
efim0v:fix/6279-set-parent-other-worktree
Oct 13, 2026
Merged

kevgo merged 1 commit into
git-town:mainfrom
efim0v:fix/6279-set-parent-other-worktree

Conversation

@efim0v

@efim0v efim0v commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #6279

The dialog of git town set-parent is built on the dialog of git town switch (dialog.SwitchBranch). That dialog disables branches that are active in another worktree (newSwitchBranchListEntries sets Disabled: entry.OtherWorktree), because git town switch cannot check them out. This restriction doesn't apply when selecting a parent, and as noted in the issue, git town set-parent <branch> already accepts such a branch.

Because the cursor skips disabled entries, the scenario from the issue does more than gray out the branch: pressing down on main wraps around to <none> (make perennial), so enter makes the current branch perennial.

The same dialog asks for the parent in git town hack --beam and when Git Town prompts for a missing parent branch, so these dialogs had the same problem.

Changes

  • dialog.SwitchBranchArgs and dialog.SwitchModel get a DisableBranchesInOtherWorktrees field. Branches in other worktrees are disabled only when it is set, also when a rebuilds the list.
  • git town switch sets it to true, so its behavior doesn't change. The three parent dialogs set it to false.
  • The dialogs still show these branches dimmed and marked with +. In the parent dialogs they can now be selected.

Tests

  • New E2E scenarios that select a branch that is active in another worktree as the parent. They fail on main, where down skips that branch and selects <none> (make perennial) instead:
    • features/set_parent/worktree/new_parent_in_other_worktree.feature
    • features/diff_parent/worktree/parent_in_other_worktree.feature (prompt for a missing parent)
    • features/hack/beam/parent_in_other_worktree.feature
  • Unit tests in internal/cli/dialog/switch_branch_test.go that toggle the branch list with a, with and without the new setting.
  • Ran on macOS with Go 1.26.1: the unit tests (UNIT_TEST_DIRS from the Makefile), the full E2E suite, go vet, golangci-lint 2.12.2, staticcheck 2026.1, exhaustruct, gofumpt, the custom linters from make lint, ghokin, gherkin-lint, and cucumber-sort. In the E2E suite, 2712 of 2724 scenarios pass. The 12 failing scenarios are in the lang/es.feature files and need Git's Spanish translations. They fail the same way on main without them.

…orktree

The dialogs that ask for a parent branch reuse the dialog of "git town
switch", which disables branches that are active in another worktree
because "git town switch" cannot check them out. This restriction does
not apply when selecting a parent. Since the cursor skips disabled
entries, the parent dialogs could not select such a branch, and moving
past it could select the "make perennial" entry instead.

Disable these branches only when the new
SwitchBranchArgs.DisableBranchesInOtherWorktrees setting is enabled,
which only "git town switch" does. This fixes the dialogs of
"git town set-parent", "git town hack --beam", and the prompt for
missing parent branches.

Fixes #6279
@efim0v
efim0v requested a review from kevgo as a code owner October 13, 2026 02:28
@kevgo
kevgo merged commit c950d51 into git-town:main Oct 13, 2026
5 checks passed
@kevgo

kevgo commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Thanks for building this! 💯

@efim0v

efim0v commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the fast review! git-town makes stacked branches so much easier to live with, so I was glad to give a little back.

@kevgo

kevgo commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

This is now available as part of Git Town 24.1.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

set-parent: should allow to set a branch as parent that is checked out in another worktree

2 participants