feat: support filesystem paths for switching and deleting worktrees#105
feat: support filesystem paths for switching and deleting worktrees#105k1LoW merged 11 commits intok1LoW:mainfrom
Conversation
Allow `git wt -d` to accept filesystem paths (relative or absolute), making it more consistent with native `git worktree remove`. Examples: git wt -d . # delete current worktree git wt -d ../sibling # delete sibling worktree git wt -d /absolute/path # delete by absolute path Priority order: 1. Branch name 2. Directory name relative to baseDir 3. Filesystem path (new) Fixes k1LoW#104 Co-Authored-By: Claude Opus 4.5 <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR adds support for filesystem paths (relative or absolute) in worktree deletion, making git wt -d more consistent with native git worktree remove. The implementation maintains the documented priority order: branch name → directory name → filesystem path.
Changes:
- Extended
FindWorktreeByBranchOrDirto accept and resolve filesystem paths - Added e2e tests for dot path (
.), relative path (../sibling), and absolute path deletion - Added test to verify worktree name precedence over local directories with the same name
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| internal/git/worktree.go | Added filesystem path resolution logic to FindWorktreeByBranchOrDir function |
| e2e/delete_test.go | Added comprehensive e2e tests for new path deletion features |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Compare absolute paths directly instead of computing relative paths. This also allows matching worktrees outside the baseDir. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Use filepath.EvalSymlinks to handle systems where paths contain symlinks (e.g., macOS /var -> /private/var). Git resolves symlinks in worktree paths, so we need to do the same for the query path. Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add assertion that wtPath is absolute in delete_with_absolute_path - Simplify precedence test: local dir in main repo vs worktree with same name - No symlinks needed, matches real-world scenario Co-Authored-By: Claude Opus 4.5 <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Resolve symlinks on both the query path and wt.Path to ensure consistent comparison regardless of symlink configurations. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Oops, I forgot, the doc should be updated |
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Add TestE2E_SwitchWorktreeByPath with subtests for relative path, absolute path, and branch-name-takes-precedence scenarios. Also document the three argument types (branch, worktree, path) in the README and update help text to include path in switch usage. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Summary
git wtandgit wt -dto accept filesystem paths (relative or absolute)git worktreecommandsExamples
Test plan
.path deletion../sibling) deletionFixes #104
🤖 Generated with Claude Code