Skip to content

feat: support existing branches when adding worktrees#37

Open
nelson870708 wants to merge 1 commit into
the0807:mainfrom
nelson870708:feat/add-existing-branch-worktree
Open

feat: support existing branches when adding worktrees#37
nelson870708 wants to merge 1 commit into
the0807:mainfrom
nelson870708:feat/add-existing-branch-worktree

Conversation

@nelson870708

@nelson870708 nelson870708 commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Pull Request

1. Summary

Support creating worktrees from existing branches in addition to creating a new branch. The add-worktree modal now separates existing-branch and new-branch flows, filters out branches already checked out in worktrees, and uses cleaner default worktree paths based on the main worktree.

2. Related Issue

  • NA

3. Changes

Extension (src/)

  • src/extension.ts
    • Resolve the main worktree path before building the default add-worktree folder.
    • Default new worktrees under <main-repo>.worktrees.
  • src/__tests__/extension.test.ts
    • Add coverage for add-worktree default path resolution when the active repo is a linked worktree.

Webview (webview-ui/)

  • webview-ui/src/components/modals/AddWorktreeModal.svelte
    • Add separate modes for using an existing branch and creating a new branch.
    • Show only the existing branch selector in existing-branch mode.
    • Show Start at and branch name fields only in new-branch mode.
    • Filter out branches already checked out in worktrees.
    • Generate default worktree folders as child paths under the default base folder.
  • webview-ui/src/components/modals/__tests__/AddWorktreeModal.test.ts
    • Update modal tests for the new mode selection behavior.
    • Add coverage for branch filtering and default folder path generation.
  • webview-ui/src/lib/i18n/en.ts
  • webview-ui/src/lib/i18n/ko.ts
  • webview-ui/src/lib/i18n/zh.ts
    • Add localized strings for the new add-worktree mode labels.

Other (build, config, docs, etc.)

  • N/A

4. Type of Change

Check all that apply.

  • New feature
  • Bug fix
  • Refactoring (no functional changes)
  • Style / UI update
  • i18n (localization) addition or update
  • Build / configuration change
  • Documentation update
  • Test addition or update

5. Testing

Describe how you verified the changes.

  • npm test passed
  • npm run lint passed
  • Manually tested via VS Code Extension Host
  • Verified in both dark and light themes (if UI was changed)

6. Screenshots (optional)

Before change

before

After change

after, existing branch

after, new branch

7. Checklist

  • New message types are defined in message-bus.ts (if applicable)
  • UI strings are added to both en.ts and ko.ts (if applicable)
  • Extension-side strings are added to both l10n/bundle.l10n.json and bundle.l10n.ko.json (if applicable)
  • No leftover console.log or debug code

8. Additional Context (optional)

The existing-branch option intentionally excludes branches already checked out in worktrees because Git does not allow the same branch to be checked out in multiple worktrees.

Filter out branches already checked out in worktrees and default new worktree paths beside the main worktree.
@codecov

codecov Bot commented Jun 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@nelson870708 nelson870708 marked this pull request as ready for review June 14, 2026 15:23
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.

1 participant