Skip to content

feat: add branch selector and VCS checkout APIs#14266

Open
itskritix wants to merge 2 commits intoanomalyco:devfrom
itskritix:feat/vcs-branch-switcher
Open

feat: add branch selector and VCS checkout APIs#14266
itskritix wants to merge 2 commits intoanomalyco:devfrom
itskritix:feat/vcs-branch-switcher

Conversation

@itskritix
Copy link
Contributor

@itskritix itskritix commented Feb 19, 2026

Issue for this PR

Closes #14265

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

  • Adds VCS API endpoints for branch listing and checkout (/vcs/branches, /vcs/checkout) with typed errors and SDK generation.
  • Adds a branch/workspace selector in the session header to browse local and remote branches and switch from the UI.
  • Prevents switching to branches already checked out in another worktree.
  • Makes git worktree list --porcelain parsing CRLF-safe to avoid platform parsing issues.

How did you verify your code works?

  • bun run typecheck in packages/opencode
  • bun run typecheck in packages/app
  • OPENCODE_SERVER_PASSWORD= bun run test in packages/opencode
  • bun run test:unit in packages/app
  • bun run build in packages/opencode
  • bun run build in packages/app

Screenshots / recordings


Screenshot 2026-02-19 at 3 20 01 PM

opencode
  • UI change: session header now includes a branch/workspace popover with grouped local/remote branches and an "in use" badge.
  • I could not capture a screenshot from this CLI-only environment.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Copilot AI review requested due to automatic review settings February 19, 2026 10:17
@github-actions github-actions bot added contributor needs:compliance This means the issue will auto-close after 2 hours. labels Feb 19, 2026
@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Feb 19, 2026
@github-actions
Copy link
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds branch switching capabilities to the OpenCode IDE by implementing VCS API endpoints and a UI branch selector component. The feature is integrated into the session header and includes worktree-aware checkout logic to prevent conflicts when branches are used in multiple worktrees.

Changes:

  • Added vcs.branches and vcs.checkout API endpoints with typed error definitions (VcsBranchListFailedError, VcsBranchNotFoundError, VcsBranchCheckoutFailedError)
  • Generated TypeScript SDK bindings for the new VCS endpoints
  • Implemented a branch selector popover in the session header that displays local and remote branches, marks branches in use by other worktrees, and handles branch checkout

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/opencode/src/project/vcs.ts Added branches() and checkout() functions with worktree detection and git command execution
packages/opencode/src/server/server.ts Registered /vcs/branches (GET) and /vcs/checkout (POST) routes with error mapping
packages/sdk/js/src/v2/gen/types.gen.ts Generated TypeScript types for VcsBranch, VcsCheckoutInput, and response/error types
packages/sdk/js/src/v2/gen/sdk.gen.ts Generated SDK methods vcs.branches() and vcs.checkout()
packages/app/src/i18n/en.ts Added internationalization strings for branch groups, in-use badge, and error messages
packages/app/src/components/session/session-header.tsx Implemented branch selector popover with search, grouping, and worktree conflict prevention

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@itskritix
Copy link
Contributor Author

itskritix commented Feb 19, 2026

Addressed Copilot review notes in 5814ae23f:

  • added server-side worktree occupancy guard in Vcs.checkout, so API calls now fail early with a clear VcsBranchCheckoutFailedError when the branch is checked out elsewhere
  • hardened worktree porcelain parsing to also parse HEAD / detached lines while still mapping occupancy by branch refs
  • added explicit-remote safety check: when selecting a remote branch with an existing local branch, we now verify upstream/commit alignment before switching to avoid silently selecting a divergent local branch

Also re-ran local checks (typecheck for app/opencode, app unit tests).

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Add branch switcher in session header with worktree-aware checkout

1 participant

Comments