Skip to content

Fix SCM repository resolution and add branch name support#302321

Open
wolfsilver wants to merge 4 commits intomicrosoft:mainfrom
wolfsilver:optimize-terminal-tabs-branch-name
Open

Fix SCM repository resolution and add branch name support#302321
wolfsilver wants to merge 4 commits intomicrosoft:mainfrom
wolfsilver:optimize-terminal-tabs-branch-name

Conversation

@wolfsilver
Copy link
Copy Markdown

This pull request adds support for displaying the current Git branch name in the integrated terminal's tab labels and descriptions. It achieves this by exposing the branch name from the Git extension through the SCM provider, making it observable, and wiring it into the terminal label computation and updates. The changes also include tests and documentation for the new ${branch} variable.

These changes allow the terminal UI to dynamically display the current Git branch, improving user awareness and workflow integration.

Fixes #237004

This fixes the issue where _scmService.getRepository() returns undefined when called with a URI that points exactly to the repository root directory.
Copilot AI review requested due to automatic review settings March 17, 2026 02:19
@vs-code-engineering
Copy link
Copy Markdown
Contributor

vs-code-engineering Bot commented Mar 17, 2026

📬 CODENOTIFY

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

@lszomoru

Matched files:

  • extensions/git/src/repository.ts
  • src/vs/workbench/contrib/scm/common/scm.ts
  • src/vs/workbench/contrib/scm/common/scmService.ts

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new ${branch} terminal tab label/description variable by plumbing the current Git branch name from the Git extension through the SCM provider layer into the terminal label computation, alongside a small fix to SCM repository resolution.

Changes:

  • Expose an SCM provider branchName (observable) end-to-end: extension host SourceControl.branchName → ext host protocol DTO → main thread SCM provider.
  • Add ${branch} support in terminal tab label computation and update terminal label docs plus a unit test.
  • Fix SCM repository resolution to correctly match when the resource URI is exactly the repository root.

Reviewed changes

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

Show a summary per file
File Description
src/vscode-dts/vscode.d.ts Adds SourceControl.branchName?: string to the public API surface.
src/vs/workbench/contrib/terminal/test/browser/terminalInstance.test.ts Adds a unit test validating ${branch} resolves in terminal labels.
src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts Documents the new ${branch} variable in terminal tab label settings.
src/vs/workbench/contrib/terminal/browser/terminalInstance.ts Wires ${branch} into label templating and adds branch-change-driven label refresh logic.
src/vs/workbench/contrib/scm/common/scmService.ts Fixes repository matching for resources at the repo root.
src/vs/workbench/contrib/scm/common/scm.ts Adds `branchName: IObservable<string
src/vs/workbench/api/common/extHostSCM.ts Adds branchName property on ExtHostSourceControl and forwards updates to main thread.
src/vs/workbench/api/common/extHost.protocol.ts Adds branchName?: string to SCMProviderFeatures DTO.
src/vs/workbench/api/browser/mainThreadSCM.ts Stores branch name as an observable on the main-thread SCM provider and updates it via $updateSourceControl.
extensions/git/src/repository.ts Updates SourceControl.branchName based on the repository HEAD on status refresh.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/vs/workbench/api/browser/mainThreadSCM.ts Outdated
this._setTitle(this.title, TitleEventSource.Config);
// Subscribe to branch name changes for the new cwd
this._subscribeToBranchNameChanges(e);
}));
}

try {
const cwdUri = URI.file(cwd);
}

try {
const cwdUri = URI.file(cwd);
wolfsilver and others added 2 commits March 17, 2026 11:17
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

terminal title supports branch variable

3 participants