Skip to content

Comments

feat: support filesystem paths for switching and deleting worktrees#105

Merged
k1LoW merged 11 commits intok1LoW:mainfrom
dgrant:filesystem-path-deletion
Feb 6, 2026
Merged

feat: support filesystem paths for switching and deleting worktrees#105
k1LoW merged 11 commits intok1LoW:mainfrom
dgrant:filesystem-path-deletion

Conversation

@dgrant
Copy link
Contributor

@dgrant dgrant commented Feb 4, 2026

Summary

  • Allow git wt and git wt -d to accept filesystem paths (relative or absolute)
  • Makes behavior more consistent with native git worktree commands
  • Documents the three argument types (branch, worktree, path) in README

Examples

# Switch by path
git wt ../sibling        # switch to sibling worktree
git wt /absolute/path    # switch by absolute path

# Delete by path
git wt -d .              # delete current worktree
git wt -d ../sibling     # delete sibling worktree
git wt -d /absolute/path # delete by absolute path

Test plan

  • Added tests for . path deletion
  • Added tests for relative path (../sibling) deletion
  • Added tests for absolute path deletion
  • Added test verifying worktree name takes precedence over local directory (delete)
  • Added tests for switching by relative path
  • Added tests for switching by absolute path
  • Added test verifying branch name takes precedence over filesystem path (switch)

Fixes #104

🤖 Generated with Claude Code

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]>
Copilot AI review requested due to automatic review settings February 4, 2026 21:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 FindWorktreeByBranchOrDir to 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.

dgrant and others added 3 commits February 4, 2026 13:50
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]>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Owner

@k1LoW k1LoW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dgrant
NICE IDEA!! Thank you!!

@k1LoW k1LoW added enhancement New feature or request tagpr:minor labels Feb 5, 2026
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]>
@dgrant
Copy link
Contributor Author

dgrant commented Feb 6, 2026

Oops, I forgot, the doc should be updated

dgrant and others added 3 commits February 6, 2026 02:08
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]>
@dgrant dgrant changed the title feat: support filesystem paths in worktree deletion feat: support filesystem paths for switching and deleting worktrees Feb 6, 2026
Copy link
Owner

@k1LoW k1LoW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!!

@k1LoW k1LoW merged commit a74a3dd into k1LoW:main Feb 6, 2026
3 checks passed
@github-actions github-actions bot mentioned this pull request Feb 6, 2026
@dgrant dgrant deleted the filesystem-path-deletion branch February 6, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request tagpr:minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support filesystem paths in worktree deletion (and switching)

2 participants