Skip to content

Implement Branch discovery, occupancy, and safe switching #12

Description

@codeacme17

Tracks #1.

Summary

Implement cached Branch discovery, Branch Occupancy, and safe switching to existing Local or Remote-tracking Branches.

Scope

  • Search separate Local and cached Remote-tracking Branch groups; exclude tags and remote symbolic HEAD aliases.
  • Use opaque exact ref IDs and show Remote-qualified names.
  • Compute Branch Occupancy across every registered Worktree.
  • Permit switching only in a fully clean Worktree with no Conflict or In-progress Git Operation.
  • Allow clean Detached HEAD to Local Branch switching; warn before leaving a commit not reachable from another named ref.
  • Disable an occupied Local Branch, identify the occupying Worktree, and offer navigation to it.
  • Allow the narrow Remote-tracking exception: create a same-name Local Tracking Branch only when target, name, local collision, upstream, and occupancy checks all pass.
  • Revalidate Worktree revision, topology/occupancy, cleanliness, HEAD, and target ref immediately before execution.
  • Run through the Repository Branch lane and clear stale file/diff selection after success.

Acceptance criteria

  • Clean switches succeed; dirty, conflicted, and In-progress Worktrees are blocked without stash/discard/carry behavior.
  • A Branch checked out in another Worktree cannot be overridden and the correct Worktree is identified.
  • Remote-tracking selection creates only the permitted same-name Tracking Branch and never rewrites an existing Branch/upstream.
  • Branch discovery does not Fetch implicitly.
  • Two simultaneous switch requests cannot race Branch Occupancy and are never silently queued.
  • External occupancy/ref changes produce a stale rejection and refreshed state.

Out of scope

  • Arbitrary Branch creation, rename, deletion, force checkout, or automatic Fetch.

Dependencies

PRD coverage

  • FR6; AC-11–13, AC-20–22.

Verification

  • Real multi-Worktree occupancy tests, clean/dirty/detached/unreachable fixtures, Remote-tracking collision matrices, and Branch-lane races.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Core reachable product behavior required for the MVPenhancementNew feature or request

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions