feat: implement git_worktree_remove tool (Issue #5) #18

Merged
david merged 2 commits from issue-5 into main 2026-07-25 02:21:03 +00:00
Owner

Summary

Implement git_worktree_remove tool with proper validation and error handling.

Changes

  • Add pi-worktree-remove.ts — pure validation functions for remove operation
    • validateRemoveWorktreeInput() — validates path is non-empty
    • isMainRepository() — refuses removal of main repo root (suggests git worktree prune)
    • hasUncommittedChanges() — checks git status --porcelain output
    • buildWorktreeRemoveCommand() — builds git worktree remove args with optional --force
  • Add pi-worktree-remove.test.ts — 17 unit tests covering all validation paths
  • Wire up createRemoveWorktreeTool() in main extension with full validation pipeline

Testing

  • All 72 tests pass (55 existing + 17 new)
  • No regressions in existing test suite
  • Manual verification — remove a worktree, try removing main repo, try removing worktree with changes

Checklist

  • Self-reviewed the diff
  • Code follows project conventions (pure functions, fail-fast validation)
  • Descriptive naming (no single-character variables)
## Summary Implement `git_worktree_remove` tool with proper validation and error handling. ## Changes - Add `pi-worktree-remove.ts` — pure validation functions for remove operation - `validateRemoveWorktreeInput()` — validates path is non-empty - `isMainRepository()` — refuses removal of main repo root (suggests `git worktree prune`) - `hasUncommittedChanges()` — checks git status --porcelain output - `buildWorktreeRemoveCommand()` — builds `git worktree remove` args with optional `--force` - Add `pi-worktree-remove.test.ts` — 17 unit tests covering all validation paths - Wire up `createRemoveWorktreeTool()` in main extension with full validation pipeline ## Testing - [x] All 72 tests pass (55 existing + 17 new) - [x] No regressions in existing test suite - [ ] Manual verification — remove a worktree, try removing main repo, try removing worktree with changes ## Checklist - [x] Self-reviewed the diff - [x] Code follows project conventions (pure functions, fail-fast validation) - [x] Descriptive naming (no single-character variables)
david added 1 commit 2026-07-24 21:23:52 +00:00
Add validation and error handling for removing linked worktrees:
- validateRemoveWorktreeInput() — validates path is non-empty
- isMainRepository() — refuses removal of main repo root
- hasUncommittedChanges() — checks git status --porcelain output
- buildWorktreeRemoveCommand() — builds git worktree remove args

Wire up createRemoveWorktreeTool with full validation pipeline:
1. Validate input parameters (path)
2. Check if target is the main repo — refuse with prune suggestion
3. Check for uncommitted changes — refuse with stash/commit message
4. Run git worktree remove <path>
5. Surface git errors with helpful suggestions
david added 1 commit 2026-07-25 02:13:03 +00:00
Critical:
- Handle git status failure with clear error instead of silently skipping uncommitted-changes guard
- Add path-exists check before removal attempt (fail-fast)

Major:
- Reuse WorktreeError from create module instead of duplicating WorktreeRemoveError
- Add force parameter to TypeBox schema and wire it through to command builder
- Add baseDir parameter to isMainRepository for deterministic relative path resolution
- Fix environment-dependent test (use absolute paths / explicit baseDir)

Minor:
- Update stale JSDoc on resolveWorktreeTarget
- Add integration test section for execute path
- Include branch name in success response
- Add test for relative path with explicit baseDir

Suggestions:
- List remaining worktrees in success response details
david merged commit 8761c3af5f into main 2026-07-25 02:21:03 +00:00
david deleted branch issue-5 2026-07-25 02:21:03 +00:00
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#18
No description provided.