fix(worktree): clean error when restoring/promoting onto an occupied branch - #3606
Closed
posthog[bot] wants to merge 1 commit into
Closed
fix(worktree): clean error when restoring/promoting onto an occupied branch#3606posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
…branch createWorktreeForExistingBranch only checked that the branch existed and that the worktree name/path was free -- never whether the branch was already checked out in another worktree. When it was, git failed with a raw "git worktree add exited with code 128" error that escaped through the restore and promote paths into error tracking. The workspace creation path already caught the "is already used by worktree" message and surfaced a friendly error, but the restore (suspension/archive) and promote paths did not. Detect the occupied branch up front in createWorktreeForExistingBranch and throw a clean, actionable message instead. The wording mirrors git's own so existing consumers that key on the "is already used by worktree" substring keep recognising the case. Fixing it at this shared chokepoint covers all three callers (create, restore, promote). Generated-By: PostHog Code Task-Id: c5eefa8e-bed0-4490-bb76-948ba7260998
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
|
This PR has had no activity for 7 days and has been marked stale. We are moving to the monorepo and tightening PR staleness in preparation, so it will be closed in 7 days if no further activity occurs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Restoring a suspended task (or promoting a local task to worktree mode) failed with a raw
git worktree add exited with code 128error whenever the task's branch was still checked out in another worktree.createWorktreeForExistingBranchonly verified the branch existed and the worktree name/path was free — never whether the branch was already live elsewhere — so git bailed and the raw failure escaped through the restore/promote paths into error tracking as an uncaught exception.The workspace creation path already caught the
"is already used by worktree"message and turned it into a friendly error, but the restore (suspension/unarchive) and promote paths did not. This hit the team dogfooding PostHog Code — low volume but real, and the raw exception spammed error tracking even though the restore UI already degrades to a helpful toast.Changes
Detect the occupied branch up front in
createWorktreeForExistingBranchand throw a clean, actionable message (Branch '<x>' is already used by worktree at '<path>') instead of letting the opaque git exit-128 error surface. The wording deliberately keeps the"is already used by worktree"substring, so the existing consumers that key on it — the workspace creation path and the restore toast — keep recognising the case unchanged.Fixing it at this shared chokepoint gives the restore and promote paths the same occupied-branch handling the creation path already had, and also covers the archive/unarchive path, in one place. The check degrades gracefully: if the worktree list can't be read, it falls through to the prior behaviour rather than blocking creation.
How did you test this?
createWorktreeForExistingBranchthrows a clean occupied-branch error (matchingis already used by worktree, and notexited with code 128) when the branch is already checked out.pnpm --filter @posthog/git typecheckandbiome linton the changed files pass.git commit, which every fixture'sbeforeEachseed relies on — pre-existing tests fail the same way); the new test mirrors the existing lifecycle tests and runs under CI's real git.Automatic notifications
Created with PostHog Code from this inbox report.