Skip to content

fix: git plugin tracks selected workspace on tab switch#144

Open
marcus wants to merge 1 commit intomainfrom
shrike/fix-143-git-workspace-tracking
Open

fix: git plugin tracks selected workspace on tab switch#144
marcus wants to merge 1 commit intomainfrom
shrike/fix-143-git-workspace-tracking

Conversation

@marcus
Copy link
Owner

@marcus marcus commented Feb 11, 2026

Summary

Fixes #143 — Git plugin doesn't track selected workspace.

When navigating away from the workspace plugin to another tab (e.g., git), the app now checks if the workspace plugin has a different worktree selected and triggers a full context switch. This ensures the git plugin (branch, status, diff, commits) reflects the worktree the user was just looking at.

Changes

  • internal/plugin/plugin.go: Added WorkspaceContextProvider interface — optional capability for plugins that manage workspace/worktree selection
  • internal/plugins/workspace/plugin.go: Implemented SelectedWorkDir() on workspace plugin, returning the selected worktree path (including main worktree, fixing switch-back-to-main)
  • internal/app/model.go: SetActivePlugin() now checks if the leaving plugin implements WorkspaceContextProvider and triggers switchWorktree() when the selected workspace differs from current WorkDir
  • internal/plugins/workspace/selected_workdir_test.go: Unit tests for SelectedWorkDir()

How it works

  1. User is on workspace plugin, selects worktree feature-x
  2. User clicks git tab (or any other plugin tab)
  3. SetActivePlugin detects workspace plugin implements WorkspaceContextProvider
  4. Calls SelectedWorkDir() → returns /path/to/feature-x
  5. Compares with current WorkDir — they differ
  6. Triggers switchWorktree()switchProject()Registry.Reinit()
  7. All plugins (including git) reinitialize with the new worktree context

Bug fix detail

The previous (stashed) implementation returned empty string for the main worktree (IsMain check), which meant switching back to main from a feature worktree was silently skipped. Fixed by always returning the path and letting the caller's normalization comparison handle the no-op case.

Testing

  • go test ./... — all pass
  • Unit tests cover: main worktree selected, feature worktree selected, no worktrees

When navigating away from the workspace plugin, check if the selected
worktree differs from the current WorkDir and trigger a context switch.
This ensures the git plugin (and all other plugins) reinitialize with
the correct worktree when the user switches tabs.

Changes:
- Add WorkspaceContextProvider interface to plugin package
- Implement SelectedWorkDir() on workspace plugin
- Check workspace context in SetActivePlugin and trigger worktree switch
- Return path for main worktree too (fixes switch-back-to-main bug)

Fixes #143
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.

Git plugin doesn't track selected workspace

1 participant