feat: implement git_worktree_switch tool (Issue #6) #19

Open
david wants to merge 1 commit from issue-6 into main
Owner

Summary

Implement git_worktree_switch tool that switches pi's working directory to a linked worktree.

Changes

  • New pi-worktree-switch.ts module with pure functions for validation and resolution
  • Full tool pipeline: validate → resolve → already-there check → uncommitted changes check → chdir → success
  • 21 unit tests covering all pure functions
  • Removed dead resolveWorktreeTarget from main module (moved to switch module)

Testing

  • All tests pass (103 total, 0 regressions)
  • Full test suite run with no regressions
  • Manual verification (requires running pi with the extension)

Checklist

  • Self-reviewed the diff
  • Code follows project conventions
  • Descriptive naming (no single-character variables)
  • Documentation updated (if applicable)
## Summary Implement `git_worktree_switch` tool that switches pi's working directory to a linked worktree. ## Changes - New `pi-worktree-switch.ts` module with pure functions for validation and resolution - Full tool pipeline: validate → resolve → already-there check → uncommitted changes check → chdir → success - 21 unit tests covering all pure functions - Removed dead `resolveWorktreeTarget` from main module (moved to switch module) ## Testing - [x] All tests pass (103 total, 0 regressions) - [x] Full test suite run with no regressions - [ ] Manual verification (requires running pi with the extension) ## Checklist - [x] Self-reviewed the diff - [x] Code follows project conventions - [x] Descriptive naming (no single-character variables) - [x] Documentation updated (if applicable)
david added 1 commit 2026-07-25 02:30:58 +00:00
- Add pi-worktree-switch.ts with pure functions:
  - validateSwitchInput: validates target is non-empty
  - resolveWorktreeTarget: resolves path or branch name to worktree path
  - isAlreadyInWorktree: checks if cwd matches target
- Wire up createSwitchWorktreeTool with full validation pipeline:
  1. Validate input parameters
  2. List worktrees and resolve target to path
  3. Refuse if already in target worktree
  4. Fail fast on uncommitted changes in source
  5. Change cwd via ctx.chdir()
  6. Return success with branch info
- Remove dead resolveWorktreeTarget from main module
- 21 unit tests, 103 total passing, 0 regressions
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin issue-6:issue-6
git checkout issue-6

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git checkout main
git merge --no-ff issue-6
git checkout issue-6
git rebase main
git checkout main
git merge --ff-only issue-6
git checkout issue-6
git rebase main
git checkout main
git merge --no-ff issue-6
git checkout main
git merge --squash issue-6
git checkout main
git merge --ff-only issue-6
git checkout main
git merge issue-6
git push origin main
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: david/pi-worktrees#19
No description provided.