Skip to content

fix: persist SCM repository visibility state across restarts#301029

Open
kno wants to merge 88 commits into
microsoft:mainfrom
kno:fix/scm-repo-visibility-persistence
Open

fix: persist SCM repository visibility state across restarts#301029
kno wants to merge 88 commits into
microsoft:mainfrom
kno:fix/scm-repo-visibility-persistence

Conversation

@kno

@kno kno commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #301028

  • isHidden repos (e.g., Copilot worktrees) no longer corrupt the visibility restoration on startup. They are skipped in the previousState logic since they were never part of the saved state.
  • New repos (not in previous state) are added as visible without resetting the visibility of existing repos or the didSelectRepository flag.

Changes

  • scmViewService.ts: Fixed onDidAddRepository to properly handle isHidden repos and new repos during state restoration
  • scmViewService.test.ts: Added 4 tests covering visibility persistence scenarios

Test plan

  • Open a multi-repo workspace, hide a repo in the SCM Repositories view, restart VS Code → hidden repo should remain hidden
  • Same scenario but with a Copilot worktree present → hidden repo should remain hidden
  • Add a new git repo to the workspace after hiding one, restart → new repo visible, previously hidden repo still hidden
  • Hidden repo registers before visible repos on startup → visibility correctly restored regardless of order

@vs-code-engineering

vs-code-engineering Bot commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@lszomoru

Matched files:

  • src/vs/workbench/contrib/scm/browser/menus.ts
  • src/vs/workbench/contrib/scm/browser/scmViewPane.ts
  • src/vs/workbench/contrib/scm/browser/scmViewService.ts
  • src/vs/workbench/contrib/scm/common/scmService.ts
  • src/vs/workbench/contrib/scm/test/browser/scmViewService.test.ts

@kno kno force-pushed the fix/scm-repo-visibility-persistence branch from 18fff29 to 1864f58 Compare March 12, 2026 06:23
@kno

kno commented Mar 12, 2026

Copy link
Copy Markdown
Contributor Author

@kno please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

SCM repository visibility was not properly restored on restart due to
two issues in the onDidAddRepository restoration logic:

1. Repositories with isHidden (e.g., Copilot worktrees) were not in the
   saved state but triggered the index === -1 path, which made ALL repos
   visible and reset the didSelectRepository flag.

2. Genuinely new repos (not in previous state) also triggered the same
   path, making all existing repos visible instead of only adding the
   new repo.

The fix:
- Skip the restoration logic for isHidden repos (they are still tracked
  internally but don't affect visibility restoration)
- New repos are added as visible without changing existing repos'
  visibility state
@kno kno force-pushed the fix/scm-repo-visibility-persistence branch from 1864f58 to a27b3d4 Compare March 13, 2026 08:13
kno added 24 commits March 15, 2026 11:50

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 encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

kno and others added 8 commits May 5, 2026 07:20
…w repo registers first

- Only include repos from previousState in the removed event (not new repos
  that remain visible), fixing spurious UI state disposal in SCMViewPane
- Clear all repos during the reset block so single-select mode correctly
  restores the saved selection even when a new repo registered earlier
- Re-apply visibility to new repos after the first restored repo is placed,
  merged into a single event to avoid bouncing add/removed deltas
- Add assertion that new repos never appear in removed events during startup

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

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

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Comment on lines +243 to +247
if (e.action && hasKey(e.action, 'keepOpen') && e.action.keepOpen) {
for (const item of this.viewItems) {
if (item instanceof BaseMenuActionViewItem) {
// Re-evaluate the action's state from context keys
if (hasKey(item.action, 'refreshState')) {
Comment on lines +28 to +33
/**
* When true, the context menu will not close when this item is triggered.
* This is useful for toggle actions in menus where the user may want to
* change multiple items without having to reopen the menu.
*/
keepOpen?: boolean;
Comment on lines +657 to +662
refreshState(): void {
(this as unknown as { enabled: boolean }).enabled = !this._precondition || this._contextKeyService.contextMatchesRules(this._precondition);
(this as unknown as { checked: boolean | undefined }).checked = this._toggledCondition
? this._contextKeyService.contextMatchesRules(this._toggledCondition)
: undefined;
}
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.

SCM repository visibility is not persisted across restarts

4 participants