Skip to content

Fix the sidebar losing the selected branch after a rebase - #760

Merged
hannesa2 merged 1 commit into
masterfrom
fix-sidebar-selection-after-rebase
Oct 8, 2026
Merged

hannesa2 merged 1 commit into
masterfrom
fix-sidebar-selection-after-rebase

Conversation

@goneng

@goneng goneng commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

Keep the sidebar on the current branch after a rebase, and on a freshly opened window.

Problem

After "Rebase 'feat' onto 'master'" from the sidebar context menu, no branch was selected in the sidebar, while 'master' stayed highlighted in the history. A freshly opened window had no sidebar selection either.

Changes

  • Restoring the selection after a reload no longer counts as a user selection. Previously the refs reload that runs inside readCurrentBranch re-selected the stale row and wrote it back to currentBranch, undoing the update.
  • Rebuilding the worktree group and removing a branch now preserve the selection like the other reloads. They used a bare reloadData, which dropped it.
  • After a rebase the sidebar selects the checked-out branch (feat), not the branch that was right-clicked.

Test plan

  • PBGitWindowWiringTests and PBGitSidebarWorktreeGroupTests pass. The two new tests fail without the change.
  • In a built app on a diverged test repo, the sidebar had no selected row before the change. After it, feat is selected at startup and after the rebase (read through accessibility).
  • Not checked by eye.

@goneng
goneng marked this pull request as ready for review October 6, 2026 18:01
@goneng
goneng force-pushed the fix-sidebar-selection-after-rebase branch from c518bcc to da229dc Compare October 6, 2026 20:30
@goneng goneng added the bugfix label Oct 6, 2026
@goneng
goneng requested a review from hannesa2 October 6, 2026 21:42
@hannesa2
hannesa2 requested a balanced review from Copilot October 7, 2026 04:27

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.

Copilot review overview

🟡 Changes recommended

Recreated worktree rows are matched by object identity, so a selected worktree branch can still lose selection.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Keeps the sidebar aligned with the checked-out branch across repository and worktree reloads.

Changes:

  • Prevents restored selections from overwriting currentBranch.
  • Preserves selection during branch removal and worktree rebuilds.
  • Adds regression coverage for startup and branch rereads.
File Description
Classes/​Controllers/​PBGitSidebarController.m Adjusts sidebar selection restoration.
GitXTests/​PBGitWindowWiringTests.m Tests selection after rereading HEAD.
GitXTests/​PBGitSidebarWorktreeGroupTests.m Tests selection after worktree lookup.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +181 to +183
restoringSelection = YES;
[sourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
restoringSelection = NO;
Keep the sidebar on the current branch when the outline is reloaded
and when the repository re-reads which branch is current.

- Restoring the selection after a reload no longer counts as a user
  selection, so it cannot write the stale branch back to
  currentBranch.
- Rebuilding the worktree group and removing a branch preserve the
  selection like the other reloads do. The worktree lookup lands after
  startup, so a freshly opened window had nothing selected either.
- Add tests for both paths.
@goneng
goneng force-pushed the fix-sidebar-selection-after-rebase branch from da229dc to 648cf8e Compare October 7, 2026 22:24
@hannesa2
hannesa2 merged commit 008ad6c into master Oct 8, 2026
5 of 6 checks passed
@hannesa2
hannesa2 deleted the fix-sidebar-selection-after-rebase branch October 8, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants