SCM Auto Follow
Makes the Source Control Changes view switch to the repository of the file you are editing, like the Auto option of the Source Control Graph. Built for folders that contain many Git repositories and submodules.
Requires "scm.repositories.selectionMode": "single" (the default).
Note: VS Code has no public API for this, so the extension relies on VS Code internals. A VS Code update can break it. After every update it asks you to run a self-test, which tells you whether it still works (see below).
Features
- Changes follows your editor. Open a file and the Changes view (with its commit box and branch) switches to that file's repository. Works for submodules and nested repositories, and for diff tabs.
- Active Repository section. A section in the Source Control sidebar that always shows the repository currently in Changes, with its branch and number of changes, its parent repository (for a submodule) and its submodules. Click an entry to show it in Changes. Drag the section header to the top of the sidebar to keep it in view.
- Repositories list follows too. After each switch, the built-in Repositories section opens and scrolls to the repository. Click the eye icon on Active Repository to keep the Repositories section closed instead. The choice is remembered. The target icon scrolls to the repository once, on demand.
- Status bar toggle. Click
SCM Follow in the status bar to turn following on or off.
- Picking a repository manually in the Changes dropdown still works. The view follows the editor again when you switch to a file in another repository.
Getting started
- Install the extension and reload the window.
- Open the Source Control view once. Switching starts after that, because VS Code creates the commands the extension uses when the view is first shown.
- Run SCM Auto Follow: Run Self-Test from the Command Palette.
Logs are in Output → SCM Auto Follow.
Settings
| Setting |
Default |
Description |
scmAutoFollow.enabled |
true |
Switch the Changes view to the repository of the active editor. |
scmAutoFollow.revealInRepositoriesView |
true |
Open and scroll the Repositories section after each switch. Only happens while Active Repository is visible; briefly moves keyboard focus to the list and back to the editor. Turn off to keep the Repositories section closed. |
Commands
- SCM Auto Follow: Toggle Auto Follow Active Editor
- SCM Auto Follow: Run Self-Test
- SCM Auto Follow: Reveal Active Repository in Repositories List
- SCM Auto Follow: Toggle Auto-Open of Repositories Section
Why it may break after a VS Code update
VS Code has no public API for selecting a repository in the Changes view. This extension uses two internals:
- The command
workbench.scm.action.toggleRepositoryVisibility.scm<N>, one per repository in the Changes dropdown.
- The Git extension's exported model (
model.repositories[].sourceControl.handle), which gives the exact N for each repository.
- For scrolling the Repositories section: the view's focus command
workbench.scm.repositories.focus and the list command list.focusDown (with a count of 0).
Every switch is checked through the public Git API (repository.ui.selected). The extension never toggles the repository that is already shown, because that would hide it.
To catch breaking changes:
- After every VS Code version change, a notification and a yellow
$(warning) SCM Follow status bar item ask you to run SCM Auto Follow: Run Self-Test. The reminder repeats on every start until the self-test passes on that version.
- The self-test opens Source Control, switches to another repository, checks the result, and switches back.
- If the Git handles can't be read, or a switch can't be confirmed 3 times in a row, a warning offers to run the self-test, show the log, or turn the extension off.
If the self-test fails, check whether the command id or the Single-selection behaviour changed in src/vs/workbench/contrib/scm/browser/scmViewPane.ts / scmViewService.ts, or the Git model shape in extensions/git/src/api/extension.ts / repository.ts, for the new VS Code release. Then update createHost in extension.js or lib/switcher.js.
Development
npm test # unit tests
npm run package # quick local build: scm-auto-follow-<version>.vsix
npx @vscode/vsce package # Marketplace build
code --install-extension scm-auto-follow-<version>.vsix --force [--profile <name>]
Use --profile if your VS Code window uses a profile other than Default.
npm run test:integration opens a separate VS Code window with a throwaway profile and three temporary Git repositories. Set VSCODE_EXECUTABLE to use a different VS Code binary. Close other windows of the same VS Code build first if it refuses to start.
License
MIT. See the LICENSE file included with the extension.