Skip to content

Conversation

@lerenn
Copy link
Owner

@lerenn lerenn commented Dec 30, 2025

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's EnsureBranchExists will create branches from the default branch if they don't exist on remote.

Changes

  • Updated shouldSkipWorktreeCreation to always attempt worktree creation (never skip)
  • Refactored branch status logging into separate logBranchStatus function for better code organization
  • Updated E2E tests to expect worktrees for all branches, even when they don't exist initially

Testing

  • ✅ All unit tests passing
  • ✅ All integration tests passing
  • ✅ All E2E tests passing
  • ✅ Linting passes

Example

Before: Adding a repository with only main branch to a workspace with branches extract-lgtm and extract-homeassistant would only update workspace files but not create worktrees.

After: Worktrees are created for both extract-lgtm and extract-homeassistant, with branches created from the default branch if they don't exist.

Previously, when adding a repository to an existing workspace, 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.

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's EnsureBranchExists will create branches from the default
branch if they don't exist on remote.

Changes:
- Updated shouldSkipWorktreeCreation to always attempt worktree creation
- Refactored branch status logging into separate logBranchStatus function
- Updated E2E tests to expect worktrees for all branches

Fixes the issue where worktrees were not created when adding repositories
to workspaces with branches that don't exist in the new repository.
@lerenn lerenn merged commit 95476c1 into main Dec 30, 2025
9 checks passed
@lerenn lerenn deleted the fix-ws-add branch December 30, 2025 17:16
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