Skip to content

Fix detached worktree name handling#15

Merged
dev-ankit merged 3 commits into
mainfrom
claude/fix-detached-worktree-abCq3
Jan 19, 2026
Merged

Fix detached worktree name handling#15
dev-ankit merged 3 commits into
mainfrom
claude/fix-detached-worktree-abCq3

Conversation

@dev-ankit

Copy link
Copy Markdown
Owner

Previously, all detached worktrees showed as "(Detached)" in lists, making
them indistinguishable. Also, couldn't switch to detached worktrees by the
name given during creation.

Changes:

  • Store user-given names in per-worktree git config using worktreeConfig extension
  • Enable extensions.worktreeConfig to support per-worktree config
  • Retrieve stored names when listing worktrees, fallback to (detached-)
  • Fix base branch selection: detached worktrees now use HEAD instead of default_base
  • Add comprehensive tests for detached worktree operations

Implementation:

  • Added enable_worktree_config(), set_worktree_name(), get_worktree_name() in git.py
  • Modified create_worktree() to store names for detached worktrees
  • Modified list_worktrees() to retrieve stored names
  • find_worktree_by_name() now works for detached worktrees

This fix makes detached worktrees fully functional for list/switch/run/delete commands.

Previously, all detached worktrees showed as "(Detached)" in lists, making
them indistinguishable. Also, couldn't switch to detached worktrees by the
name given during creation.

Changes:
- Store user-given names in per-worktree git config using worktreeConfig extension
- Enable extensions.worktreeConfig to support per-worktree config
- Retrieve stored names when listing worktrees, fallback to (detached-<commit>)
- Fix base branch selection: detached worktrees now use HEAD instead of default_base
- Add comprehensive tests for detached worktree operations

Implementation:
- Added enable_worktree_config(), set_worktree_name(), get_worktree_name() in git.py
- Modified create_worktree() to store names for detached worktrees
- Modified list_worktrees() to retrieve stored names
- find_worktree_by_name() now works for detached worktrees

This fix makes detached worktrees fully functional for list/switch/run/delete commands.
Copilot AI review requested due to automatic review settings January 19, 2026 08:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes a critical usability issue where all detached worktrees were indistinguishable in listings and couldn't be referenced by their user-given names. The solution stores user-provided names in per-worktree git config using the worktreeConfig extension.

Changes:

  • Store and retrieve user-given names for detached worktrees using per-worktree git config
  • Fix base branch selection logic for detached worktrees to use HEAD instead of default_base
  • Add comprehensive test coverage for all detached worktree operations (create, list, switch, run, delete)

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tools/wt-worktree/wt/git.py Added three new functions to enable worktree config extension and manage per-worktree name storage
tools/wt-worktree/wt/worktree.py Modified list_worktrees() to retrieve stored names, updated create_worktree() to store names and fix base branch logic, updated comment in find_worktree_by_name()
tools/wt-worktree/tests/test_cli.py Added 6 comprehensive integration tests covering all detached worktree operations
tools/wt-worktree/notes.md Documented the problem, solution, implementation details, and lessons learned
tools/wt-worktree/README.md Added documentation and examples for detached worktree usage
Agents.md Added workflow tips and testing guidelines for development

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Detached worktrees created before this fix (or via raw git commands)
don't have stored names in config. Added path-based inference to handle
these cases.

Changes:
- Added _infer_name_from_path() method to infer names from worktree paths
- Fallback chain: stored config → inferred from path → (detached-<commit>)
- Works with common path patterns like ../{repo}-{name} and ../{name}
- Added test for backward compatibility scenario

This ensures switch/list/run commands work even for legacy detached worktrees.
@dev-ankit dev-ankit merged commit 86da0b5 into main Jan 19, 2026
3 checks passed
@dev-ankit dev-ankit deleted the claude/fix-detached-worktree-abCq3 branch January 19, 2026 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants