Skip to content

Fix worktree branch selection context#2868

Open
tonymmm1 wants to merge 2 commits into
pingdotgg:mainfrom
tonymmm1:fix-thread-worktree-git-context
Open

Fix worktree branch selection context#2868
tonymmm1 wants to merge 2 commits into
pingdotgg:mainfrom
tonymmm1:fix-thread-worktree-git-context

Conversation

@tonymmm1
Copy link
Copy Markdown

@tonymmm1 tonymmm1 commented May 30, 2026

Summary

  • Keep branch changes inside the active thread worktree unless the selected ref explicitly points at another checkout.
  • Preserve the existing path-clearing behavior only when a ref reports the main project checkout as its worktree.
  • Update the BranchToolbar logic regression coverage.

Verification

  • bun run --cwd apps/web test src/components/BranchToolbar.logic.test.ts
  • bun fmt
  • bun lint
  • bun typecheck

Note

Medium Risk
Changes thread/workspace targeting for branch switches in worktree mode; wrong paths could check out the wrong directory, but scope is limited to BranchToolbar logic with updated unit tests.

Overview
Branch picker checkout now stays in the active thread worktree unless the selected ref is already checked out somewhere else (including jumping back to the main repo when that ref’s worktreePath is the project root).

resolveBranchSelectionTarget no longer uses isDefault on VcsRef. For refs with no existing worktree, it always uses the current worktree path (or main activeProjectCwd when none) for both checkoutCwd and nextWorktreePath, instead of clearing the worktree and checking out the default branch in the main repo. Logic tests were updated to match.

Reviewed by Cursor Bugbot for commit f76837e. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Fix resolveBranchSelectionTarget to keep checkout in current worktree when selected ref has no existing worktree

Previously, resolveBranchSelectionTarget in BranchToolbar.logic.ts would switch to the main repo when the selected ref was a default ref with no existing worktree. Now, when no existing worktree is found for the selected ref, checkout always stays in the active worktree and nextWorktreePath is set to the active worktree path. The isDefault field is removed from the refName input type as it is no longer needed.

Macroscope summarized f76837e.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 30, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3333c094-2c8c-4517-89a4-db9da0eadf8b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels May 30, 2026
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit daf456a. Configure here.

Comment thread apps/web/src/components/BranchToolbar.logic.ts
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented May 30, 2026

Approvability

Verdict: Needs human review

This PR changes runtime behavior for worktree branch selection - removing the logic that switched to the main repo when selecting a default branch from a worktree. While scoped and well-tested, this behavioral change in a non-trivial feature area warrants human review.

You can customize Macroscope's approvability policy. Learn more.

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

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant