Skip to content

fix: update worktree .git pointers after context remove repo restore#50

Merged
guodong-sq merged 1 commit intomainfrom
fix/context-remove-worktree-pointers
Mar 22, 2026
Merged

fix: update worktree .git pointers after context remove repo restore#50
guodong-sq merged 1 commit intomainfrom
fix/context-remove-worktree-pointers

Conversation

@guodong-sq
Copy link
Collaborator

@guodong-sq guodong-sq commented Mar 22, 2026

Summary

Fixes a bug in wt context remove (PR #49) where reversing the repo migration breaks all existing worktrees.

When wt context remove moves the main repo back from ~/.wt/repos/<name>/base to the original location (e.g., ~/Dev/myrepo), worktrees' .git files still contain gitdir: pointers to the old .git path. This breaks all git operations in those worktrees.

Fix: After moving the repo, iterate .git/worktrees/*/, read each gitdir file to find the worktree's .git file, and rewrite the pointer to the new location.

Applies to both CLI (bin/wt-context) and plugin (DeleteContextAction.kt).

Test plan

  • CLI tests pass: cd test && bats unit/ integration/
  • Plugin tests pass: cd wt-jetbrains-plugin && ./gradlew test
  • New test: worktree .git pointers updated after repo move, git status works

🤖 Generated with Claude Code

@guodong-sq guodong-sq force-pushed the fix/context-remove-worktree-pointers branch from 6aa6c1f to 9357a15 Compare March 22, 2026 06:17
When wt context remove reverses the repo migration (moves the main
repo back to the symlink location), all existing worktrees' .git
files still contain gitdir: pointers to the old .git path, breaking
git operations in those worktrees.

After the move, iterate .git/worktrees/*/ and update each worktree's
.git file to point to the new .git location.

Applies to both CLI (bin/wt-context) and plugin (DeleteContextAction).
Also extracts repo restore logic from DeleteContextAction into
ContextService.removeContext() for clean separation of concerns.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@guodong-sq guodong-sq force-pushed the fix/context-remove-worktree-pointers branch from 9357a15 to d12ba0a Compare March 22, 2026 06:20
@guodong-sq guodong-sq merged commit 7fe2249 into main Mar 22, 2026
6 checks passed
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.

1 participant