Observed Behavior
Executing treefort remove <worktree_name> --delete-branch passes worktree_name directly to git.delete_branch(worktree_name, force=force). If the worktree's checked-out branch name does not match its directory name (for instance, when checked out into a custom folder or when the branch name was normalized), git attempts to delete a branch named after the directory rather than the actual branch. This either fails or risks deleting an unrelated branch.
Expected Behavior
RemoveCommand should inspect the worktree before deleting it (e.g. via git.list_worktrees() or querying HEAD in the worktree directory) to determine the actual branch associated with the worktree, and delete that branch.
Steps to Reproduce
- In an initialized repository, add a worktree with a directory name different from the branch name:
git worktree add custom-dir -b my-feature
- Run
treefort remove custom-dir --delete-branch.
git worktree remove successfully deletes custom-dir.
- The command then runs
git.delete_branch("custom-dir"), which fails because no branch named custom-dir exists (my-feature is left undeleted).
Minimal Reproduction Environment / Conditions
- Version / Branch / Commit:
release-v0.5.x@6d07c0c
- Component:
treefort.commands.remove.RemoveCommand
Errors, Logs & Telemetry
WARNING: Failed to delete branch 'custom-dir': Command failed, with exit status 1: git branch -d -- custom-dir
error: branch 'custom-dir' not found.
Code location in src/treefort/commands/remove.py:50-54:
if delete_branch:
try:
self._runtime.git.delete_branch(worktree_name, force=force)
except CommandError as e:
self._logger.warning(f"Failed to delete branch '{worktree_name}': {e}")
Deliverables & Testing Requirements
- Determine the actual target branch from the worktree before removing the directory.
- Delete the resolved branch name rather than blindly using the directory name.
- Regression Safety: Add a unit test in
tests/commands/test_remove.py verifying that when directory name and branch name differ, the correct branch name is deleted.
Technical Pointers & Root Cause Clues
- Suspected Components:
src/treefort/commands/remove.py:50-54
- Related Commits:
c953c29 (Update remove command to have option of deleting branch)
Notes & Edge Cases
- If the worktree is in a detached HEAD state, branch deletion should be skipped gracefully with an informative log message.
Metadata
Severity / Priority: P2 (Normal)
Area: bug, remove, 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.
Observed Behavior
Executing
treefort remove <worktree_name> --delete-branchpassesworktree_namedirectly togit.delete_branch(worktree_name, force=force). If the worktree's checked-out branch name does not match its directory name (for instance, when checked out into a custom folder or when the branch name was normalized), git attempts to delete a branch named after the directory rather than the actual branch. This either fails or risks deleting an unrelated branch.Expected Behavior
RemoveCommandshould inspect the worktree before deleting it (e.g. viagit.list_worktrees()or querying HEAD in the worktree directory) to determine the actual branch associated with the worktree, and delete that branch.Steps to Reproduce
git worktree add custom-dir -b my-featuretreefort remove custom-dir --delete-branch.git worktree removesuccessfully deletescustom-dir.git.delete_branch("custom-dir"), which fails because no branch namedcustom-direxists (my-featureis left undeleted).Minimal Reproduction Environment / Conditions
release-v0.5.x@6d07c0ctreefort.commands.remove.RemoveCommandErrors, Logs & Telemetry
Code location in
src/treefort/commands/remove.py:50-54:Deliverables & Testing Requirements
tests/commands/test_remove.pyverifying that when directory name and branch name differ, the correct branch name is deleted.Technical Pointers & Root Cause Clues
src/treefort/commands/remove.py:50-54c953c29(Update remove command to have option of deleting branch)Notes & Edge Cases
Metadata
Severity / Priority: P2 (Normal)
Area:
bug,remove,gitAI 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.