Skip to content

prune command fails to remove worktrees with slashes in their path #78

Description

@bjester

Observed Behavior

When worktrees are created within subdirectories or with paths containing slashes (e.g. feature/login), PruneCommand._iter_worktrees extracts Path(wt["path"]).name, truncating the path to only its basename (login). When _do_prune subsequently invokes git.remove_worktree("login"), git fails because no worktree named login exists in the project root.

Expected Behavior

PruneCommand should resolve the relative path of the worktree directory relative to project_dir so that nested worktrees (e.g. feature/login) can be accurately located and removed by git worktree remove.

Steps to Reproduce

  1. Check out a worktree containing a slash in the branch/worktree name:
    treefort checkout feature/my-feature (creates directory <project_dir>/feature/my-feature).
  2. Merge the corresponding PR on GitHub.
  3. Run treefort prune --yes.
  4. _iter_worktrees yields worktree_name = "my-feature" instead of "feature/my-feature".
  5. git worktree remove -- my-feature fails with exit code 128: fatal: 'my-feature' is not a working tree.

Minimal Reproduction Environment / Conditions

  • Version / Branch / Commit: release-v0.5.x@6d07c0c
  • Component: treefort.commands.prune.PruneCommand
  • Trigger: Any branch name containing slashes (e.g., feature/branch, bugfix/issue)

Errors, Logs & Telemetry

ERROR: Failed to prune 'my-feature': Command failed, with exit status 128: git worktree remove -- my-feature
fatal: 'my-feature' is not a working tree

Code location in src/treefort/commands/prune.py:72:

worktree_name = Path(wt["path"]).name  # Truncates 'feature/my-feature' to 'my-feature'

Deliverables & Testing Requirements

  • Preserve relative worktree subpaths by computing Path(wt["path"]).resolve().relative_to(project_dir.resolve()).as_posix() rather than taking .name.
  • Regression Safety: Add a unit test in tests/commands/test_prune.py verifying that a worktree at subpath/feature is correctly identified and pruned with its full relative path.

Technical Pointers & Root Cause Clues

  • Suspected Components: src/treefort/commands/prune.py:72, 118
  • Related Commits: bd7ed4c (Add new prune command for removing worktrees for merged PR branches)

Notes & Edge Cases

  • Branches containing slashes (feature/*, fix/*) are standard git conventions and are explicitly supported by open_worktree in GitCLI.

Metadata

Severity / Priority: P0 (Blocker)
Area: bug, prune, git

AI Usage

Drafted with Gemini following the DEEP framework based on code review findings against release-v0.5.x. Reproduction conditions and code references were verified in the codebase.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0 - CriticalCritical release blocking issuesbugSomething isn't working

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions