Skip to content

fix: route SCM title click to its repo in multi-repo workspaces#3

Merged
rbonestell merged 1 commit into
ShiftinBits:mainfrom
ozgur-d:feat/multi-repo-scm-routing
Apr 24, 2026
Merged

fix: route SCM title click to its repo in multi-repo workspaces#3
rbonestell merged 1 commit into
ShiftinBits:mainfrom
ozgur-d:feat/multi-repo-scm-routing

Conversation

@ozgur-d

@ozgur-d ozgur-d commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

Summary

In workspaces where a root folder contains multiple nested .git sub-folders (each shown as its own repo in the SCM view), clicking the Generate Commit Message with Claude button would always read the staged diff from api.repositories[0], producing No staged changes found. whenever the staged changes were in a different sub-repo. Single-repo workspaces were unaffected.

VS Code passes the SourceControl associated with the clicked title button as the first argument to the command. This PR consumes that argument, extracts its rootUri, and routes the generation to the correct repository.

Changes

  • src/scm.ts (new) — safe extractor for the rootUri on the SCM command argument. Returns undefined for palette/keybinding invocations, preserving existing fallback behavior.
  • src/extension.ts, src/extension.web.ts — command handlers accept the argument and forward the extracted URI.
  • src/generateCommitMessage.ts — new optional targetUri parameter passed through to the git resolver.
  • src/git.tsgetGitRepository(targetUri?) prefers api.getRepository(uri), then a rootUri.fsPath match, before falling back to single-repo / active-editor / first-repo heuristics.

Behavior matrix

Invocation Before After
SCM title click, single repo works works (unchanged)
SCM title click, multi-repo always picks first repo picks the clicked repo
Command palette / keybinding active editor → first repo active editor → first repo (unchanged)

Test plan

  • npm run check-types — clean
  • npm test85/85 pass (9 new tests: scm helper, getGitRepository URI-hint paths, generateCommitMessage URI forwarding)
  • Manual: workspace with nested .git sub-folders — click Generate in each sub-repo's SCM title, verify each receives a message from its own staged diff
  • Manual: single-repo workspace — regression check
  • Manual: command palette / Ctrl+Shift+Alt+C invocation — still resolves via active editor / first-repo fallback

When the Generate button is clicked in the SCM title of a specific repo
in a workspace with nested .git sub-folders, VS Code passes the
SourceControl as the command argument. The extension ignored it and fell
back to api.repositories[0], causing "No staged changes found" when the
staged changes lived in another sub-repo.

Read the rootUri from the command argument and forward it to
getGitRepository, which prefers api.getRepository(uri) / rootUri match
before the existing single-repo / active-editor / first-repo fallbacks.
Palette and keybinding invocations keep the prior behavior.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@snyk-io

snyk-io Bot commented Apr 18, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@codecov

codecov Bot commented Apr 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@rbonestell

Copy link
Copy Markdown
Contributor

Good catch, and thanks for the contribution!

@rbonestell
rbonestell merged commit 862dc51 into ShiftinBits:main Apr 24, 2026
5 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.

2 participants