Skip to content

Conversation

@lerenn
Copy link
Owner

@lerenn lerenn commented Dec 24, 2025

This PR adds two new commands to the CM CLI:

Features

cm ws add [-w workspace_name] [repository_name]

  • Adds a repository to an existing workspace
  • Creates worktrees in the new repository for all branches that already have worktrees in ALL existing repositories
  • Updates all existing .code-workspace files to include the new repository
  • Supports interactive selection for both workspace and repository names

cm ws remove [-w workspace_name] [repository_name]

  • Removes a repository from an existing workspace
  • Updates all existing .code-workspace files to remove the repository folder entries
  • Does NOT delete the associated worktrees in the repositories
  • Supports interactive selection for both workspace and repository names

Implementation Details

  • Added business logic in pkg/code-manager/workspace_add.go and pkg/code-manager/workspace_remove.go
  • Added CLI commands in cmd/cm/workspace/add.go and cmd/cm/workspace/remove.go
  • Added comprehensive unit tests and e2e tests
  • Fixed worktree creation to skip if already exists
  • All lint errors resolved

@lerenn lerenn force-pushed the feat-add-repos-to-existing-workspace branch from 50f6b6c to ac2b996 Compare December 24, 2025 13:34
@lerenn lerenn changed the title feat: Add repository to existing workspace and remove repository from workspace feat: add/remove repository to existing workspace Dec 24, 2025
- Fixed TestAddRepositoryToWorkspaceWithWorktrees to handle local branches correctly
- Fixed TestAddRepositoryToWorkspaceNoMatchingBranches to skip worktrees for non-existent branches
- Added support for checking branches in original repository path before cloning
- Improved branch existence validation to handle both local and remote branches
- Made worktree creation idempotent by checking status before creation
- Added verification to remove worktrees for non-existent branches from status
- Refactored complex functions to reduce cyclomatic and cognitive complexity
- Fixed all linting issues (line length, complexity, nested if statements)
- All TestAddRepositoryToWorkspace* tests now pass
- Fixed TestWorktree_Create_DirectoryExists to include GetWorktree mock
- Updated all TestAddRepositoryToWorkspace* tests to include mocks for:
  - GetRepository at start of createWorktreesForBranches
  - GetMainRepositoryPath for branch checks
  - BranchExists before and after worktree creation
  - verifyAndCleanupWorktree calls
- Fixed TestCreateWorkspace* tests to include mocks for cloning process:
  - GetRepository with original and normalized URLs
  - GetDefaultBranch, MkdirAll, Clone
  - Updated remote URLs to use full HTTPS format for proper normalization

All unit tests now pass with the new branch existence validation logic.
@lerenn lerenn merged commit d235078 into main Dec 27, 2025
9 checks passed
@lerenn lerenn deleted the feat-add-repos-to-existing-workspace branch December 27, 2025 19:12
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