Skip to content

Conversation

@kevinisyoung
Copy link

@kevinisyoung kevinisyoung commented Jan 19, 2026

Summary

  • Branches already checked out in worktrees are now hidden from the branch switch dropdown (since git doesn't allow checking out a branch that's in another worktree)
  • Worktree tabs now appear when worktrees exist, even if the "Use Worktrees" setting is disabled, so users can navigate to their existing worktrees

Problem

When users had worktrees but didn't have the "Use Worktrees" setting enabled:

  1. The branch dropdown showed branches marked with worktree info
  2. Clicking them failed with "git checkout failed: branch already checked out"
  3. The worktree tabs weren't visible, so users had no way to navigate to their worktrees

Test plan

  • Build passes
  • All tests pass
  • Manually verify branches in worktrees are hidden from dropdown
  • Manually verify worktree tabs appear when worktrees exist

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Improvements

    • Branches checked out in other worktrees are now excluded from branch switching, preventing conflicts.
    • Worktrees section visibility now adapts based on actual worktree presence in the repository.
  • Style

    • Minor code formatting adjustments.

✏️ Tip: You can customize this high-level summary in your review settings.

- Add checkedOutInWorktree field to BranchInfo to track which branches
  are already checked out in worktrees
- Filter out worktree branches from the branch switch dropdown since
  git doesn't allow checking out a branch that's in another worktree
- Show worktree tabs when worktrees exist, even if "Use Worktrees"
  setting is disabled, so users can navigate to their worktrees

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @kevinisyoung, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses user experience issues related to Git worktrees. It prevents common errors by intelligently filtering available branches in the UI and enhances discoverability by ensuring that existing worktrees are always visible, even when a specific feature setting is not explicitly enabled. The changes aim to make worktree management more intuitive and less prone to user frustration.

Highlights

  • Branch Switcher Improvement: Branches that are already checked out in a Git worktree are now hidden from the branch switch dropdown, preventing users from attempting to check out a branch that Git disallows.
  • Worktree Tab Visibility: Worktree tabs will now appear even if the 'Use Worktrees' setting is disabled, provided that existing worktrees are detected. This allows users to navigate to their worktrees regardless of the setting.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses two issues related to Git worktrees. Hiding branches already checked out in other worktrees from the branch switcher is a great UX improvement that prevents users from running into Git errors. Similarly, ensuring worktree tabs are visible when worktrees exist, regardless of the 'Use Worktrees' setting, provides a necessary navigation path for users who might have disabled the setting but still have active worktrees. The changes on both the server and UI sides are clear and well-implemented. I have one suggestion to improve error logging for better diagnostics.

Comment on lines +46 to +48
} catch {
// If we can't get worktree info, return empty map
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

While returning an empty map on failure is a reasonable fallback, swallowing the error completely can make debugging difficult if git worktree list fails for an unexpected reason. It's better to log the error using the existing logWorktreeError utility to aid in troubleshooting.

Suggested change
} catch {
// If we can't get worktree info, return empty map
}
} catch (error) {
// If we can't get worktree info, log it and return an empty map so the main functionality isn't blocked.
logWorktreeError(error, 'Failed to get worktree branches', cwd);
}

@coderabbitai
Copy link

coderabbitai bot commented Jan 19, 2026

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

The changes introduce worktree-awareness to branch listing by adding a checkedOutInWorktree field to BranchInfo across server and UI layers. The server fetches and maps branch-to-worktree associations, while UI components filter out branches already checked out in worktrees and adjust worktree panel visibility based on actual worktree presence.

Changes

Cohort / File(s) Summary
Server-side worktree branch tracking
apps/server/src/routes/worktree/routes/list-branches.ts
Added helper function to fetch worktree branches; extended BranchInfo interface with checkedOutInWorktree field; integrated worktree data into branch listing logic to mark branches checked out in worktrees
UI type definitions
apps/ui/src/components/views/board-view/worktree-panel/types.ts
Added checkedOutInWorktree: string | null property to BranchInfo interface to represent worktree path or null
UI branch filtering
apps/ui/src/components/views/board-view/worktree-panel/branch-switch-dropdown.tsx
Filters branches to exclude those with active worktree associations before rendering in dropdown menu
UI worktree panel visibility
apps/ui/src/components/views/board-view/worktree-panel/worktree-panel.tsx
Adjusted rendering condition to show worktree panel when either feature flag is enabled or non-main worktrees exist
Minor formatting
apps/ui/src/components/layout/sidebar/hooks/use-project-creation.ts
Reformatted function parameter destructuring to single line

Sequence Diagram

sequenceDiagram
    participant Server as Server API
    participant UI as UI Components
    participant User as User

    Server->>Server: Fetch local & remote branches
    Server->>Server: Query worktree checkout info
    Server->>Server: Map branches to worktree paths
    Server->>UI: Return BranchInfo[] with checkedOutInWorktree
    UI->>UI: Parse received branch data
    UI->>UI: Filter out branches with checkedOutInWorktree set
    UI->>UI: Check worktree panel visibility condition
    UI->>User: Render filtered branch dropdown & worktree panel
    User->>UI: Click branch or worktree
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested labels

Bug, Ready-To-Merge

Poem

🐰 A worktree branch now wears its path with pride,
No duplicate checkout hides inside!
The server maps, the UI filters clean,
Each branch knows where it's been.
Worktrees dance in harmony! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: hiding worktree branches from the branch switcher and showing worktree tabs, which aligns with the file-level changes and PR objectives.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/ui/src/components/views/board-view/worktree-panel/components/branch-switch-dropdown.tsx (1)

88-109: Edge case: empty dropdown after worktree filtering.

When all filteredBranches are checked out in worktrees, the filter at line 94 produces an empty list, but the empty state message at line 88 won't display (since filteredBranches.length > 0). Users would see an empty dropdown with no explanation.

Consider computing the displayable branches once and using that for both the empty state check and rendering:

Suggested approach
+          const displayableBranches = filteredBranches.filter(
+            (branch) => !branch.checkedOutInWorktree
+          );
           {isLoadingBranches ? (
             <DropdownMenuItem disabled className="text-xs">
               <Spinner size="xs" className="mr-2" />
               Loading branches...
             </DropdownMenuItem>
-          ) : filteredBranches.length === 0 ? (
+          ) : displayableBranches.length === 0 ? (
             <DropdownMenuItem disabled className="text-xs">
               {branchFilter ? 'No matching branches' : 'No branches found'}
             </DropdownMenuItem>
           ) : (
-            filteredBranches
-              .filter((branch) => !branch.checkedOutInWorktree) // Hide branches already in worktrees
-              .map((branch) => (
+            displayableBranches.map((branch) => (
               // ... rest unchanged
             ))
           )}
🤖 Fix all issues with AI agents
In `@apps/server/src/routes/worktree/routes/list-branches.ts`:
- Line 92: The local const worktreePath returned from
worktreeBranches.get(cleanName) shadows the worktreePath from the request body;
rename the local variable (e.g., branchWorktreePath or branchPath) at the
declaration where worktreeBranches.get(cleanName) is used and update all
subsequent references in this function (including any null/undefined checks and
uses when constructing the branch object) so the outer request body worktreePath
remains distinct and unshadowed.
♻️ Duplicate comments (1)
apps/server/src/routes/worktree/routes/list-branches.ts (1)

46-48: Swallowing errors silently makes debugging difficult.

This issue was already raised in a previous review: the empty catch block should log the error using logWorktreeError to aid troubleshooting when git worktree list fails unexpectedly.

🧹 Nitpick comments (2)
apps/ui/src/components/views/board-view/worktree-panel/components/branch-switch-dropdown.tsx (1)

19-19: Consider removing unused branches prop from interface.

The branches prop is declared in the interface but never used in the component (only filteredBranches is consumed). If this prop isn't needed for future functionality, removing it would clean up the API.

apps/server/src/routes/worktree/routes/list-branches.ts (1)

9-13: Consider importing execAsync from common.ts instead of re-declaring.

The execAsync utility is already exported from ../common.js. Importing it would reduce duplication and maintain consistency across worktree routes.

Suggested change
 import type { Request, Response } from 'express';
-import { exec } from 'child_process';
-import { promisify } from 'util';
-import { getErrorMessage, logWorktreeError } from '../common.js';
-
-const execAsync = promisify(exec);
+import { execAsync, getErrorMessage, logWorktreeError } from '../common.js';

.map((name) => {
// Remove any surrounding quotes (Windows git may preserve them)
const cleanName = name.trim().replace(/^['"]|['"]$/g, '');
const worktreePath = worktreeBranches.get(cleanName);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Variable shadowing: worktreePath shadows outer scope.

The variable worktreePath declared here shadows the worktreePath from the request body (line 56). This is confusing and could lead to subtle bugs if the outer variable is accidentally used.

Suggested rename
-          const worktreePath = worktreeBranches.get(cleanName);
+          const branchWorktreePath = worktreeBranches.get(cleanName);
           return {
             name: cleanName,
             isCurrent: cleanName === currentBranch,
             isRemote: false,
             // Mark if this branch is checked out in a worktree (and it's not the current worktree)
-            checkedOutInWorktree: worktreePath && cleanName !== currentBranch ? worktreePath : null,
+            checkedOutInWorktree: branchWorktreePath && cleanName !== currentBranch ? branchWorktreePath : null,
           };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const worktreePath = worktreeBranches.get(cleanName);
const branchWorktreePath = worktreeBranches.get(cleanName);
return {
name: cleanName,
isCurrent: cleanName === currentBranch,
isRemote: false,
// Mark if this branch is checked out in a worktree (and it's not the current worktree)
checkedOutInWorktree: branchWorktreePath && cleanName !== currentBranch ? branchWorktreePath : null,
};
🤖 Prompt for AI Agents
In `@apps/server/src/routes/worktree/routes/list-branches.ts` at line 92, The
local const worktreePath returned from worktreeBranches.get(cleanName) shadows
the worktreePath from the request body; rename the local variable (e.g.,
branchWorktreePath or branchPath) at the declaration where
worktreeBranches.get(cleanName) is used and update all subsequent references in
this function (including any null/undefined checks and uses when constructing
the branch object) so the outer request body worktreePath remains distinct and
unshadowed.

@webdevcody webdevcody deleted the branch AutoMaker-Org:v0.13.0rc January 20, 2026 23:48
@webdevcody webdevcody closed this Jan 20, 2026
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.

2 participants