fix: create worktrees for all workspace branches when adding repository #123
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
When adding a repository to an existing workspace using
ws add, worktrees were only created for branches that already existed in the new repository. If a branch didn't exist locally or on remote, worktree creation was skipped, even though the workspace file was updated.Solution
This fix ensures that worktrees are created for ALL branches defined in
workspace.Worktrees, even if they don't exist in the new repository. The worktree package'sEnsureBranchExistswill create branches from the default branch if they don't exist on remote.Changes
shouldSkipWorktreeCreationto always attempt worktree creation (never skip)logBranchStatusfunction for better code organizationTesting
Example
Before: Adding a repository with only
mainbranch to a workspace with branchesextract-lgtmandextract-homeassistantwould only update workspace files but not create worktrees.After: Worktrees are created for both
extract-lgtmandextract-homeassistant, with branches created from the default branch if they don't exist.