Fix libgit2 conflict when a branch is already checked out elsewhere - #155
Conversation
…144) createGitWorktree now forks a fresh branch (named via generateName()) off the requested ref instead of checking out that ref directly, so a new worktree never collides with a branch already checked out in the main repo or another linked worktree. checkoutGitRef keeps the literal in-place checkout but now pre-checks via findBranchCheckedOutElsewhere and returns a branchAlreadyCheckedOutError instead of a raw libgit2 error, while treating "already on that branch here" as a no-op. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
Next review available in: 19 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
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. Comment |
findBranchCheckedOutElsewhere only had one caller (checkoutGitRef), so fold it and its helper back into checkout.ts instead of keeping a separate single-use module. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Summary
createGitWorktreenow forks a fresh branch (named viagenerateName()) off the requested ref's commit and checks that new branch into the worktree, instead of attaching the literally requested branch — so it never collides with a branch already checked out in the main repo or another linked worktree.checkoutGitRefstill switches to the literal requested branch in place, but now pre-checks via a newfindBranchCheckedOutElsewherehelper and returns a domainGitBranchCheckedOutError/branchAlreadyCheckedOutErrorinstead of a raw libgit2 error, while treating "already on that branch here" as a no-op success.createGitWorktreefails (path validation,mkdir, or theworktree()call), the freshly created branch is cleaned up rather than left dangling.Fixes #144
Test plan
bun test:unit(Vitest workspace + CLI Bun suite) — all passbun run check:types— all packages cleanapps/cli/src/git/git.test.tscovering: worktree creation forks a new branch, worktree creation succeeds even when the source branch is checked out in the main repo, checkout is a no-op when already on the requested branch, checkout returnsGitBranchCheckedOutErrorwhen the branch is checked out in another worktree🤖 Generated with Claude Code