git: add headLabelOverride to Repository API#306517
Open
RockyWearsAHat wants to merge 5 commits intomicrosoft:mainfrom
Open
git: add headLabelOverride to Repository API#306517RockyWearsAHat wants to merge 5 commits intomicrosoft:mainfrom
RockyWearsAHat wants to merge 5 commits intomicrosoft:mainfrom
Conversation
Add a headLabelOverride property to the Git extension's Repository model. When set, headLabel and headShortName return the override instead of the real HEAD name. This is display-only — no git state is modified. Use case: extensions managing worktrees per window/session need the status bar to reflect the logical branch without actually checking it out. Fixes microsoft#306496
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @lszomoruMatched files:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new headLabelOverride property to the Git extension’s Repository API so extensions can temporarily override the branch label shown in SCM/status-bar display surfaces without changing the actual Git HEAD.
Changes:
- Add
headLabelOverridestorage + getter/setter on the internalRepositorymodel and have label getters consult it. - Expose
headLabelOverride: string | undefinedon the publicRepositoryAPI type (git.d.ts). - Plumb the property through the API wrapper (
ApiRepository) to the internal repository instance.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| extensions/git/src/repository.ts | Implements the override field and wires it into headShortName/headLabel plus status-change event firing. |
| extensions/git/src/api/git.d.ts | Extends the public Repository interface with the new headLabelOverride property and documentation. |
| extensions/git/src/api/api1.ts | Adds getter/setter on ApiRepository to delegate headLabelOverride to the internal repository. |
…x behavior Address review feedback: - Use !== undefined instead of truthiness check so empty string overrides work - Add no-op guard in setter to avoid firing event when value unchanged - Document in git.d.ts that override replaces entire label including suffixes
074e0b7 to
d5d4f1e
Compare
Replace reuse of _onDidChangeStatus (onDidRunGitStatus) with a dedicated _onDidChangeHeadLabel emitter so label changes are semantically distinct from git-status refreshes. - repository.ts: add _onDidChangeHeadLabel emitter, fire it from setter - statusbar.ts: subscribe CheckoutStatusBar to onDidChangeHeadLabel - api1.ts: forward onDidChangeHeadLabel to ApiRepository - git.d.ts: expose onDidChangeHeadLabel in the public API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
headLabelOverrideproperty to the Git extension'sRepositoryAPI, allowing extensions to temporarily replace the label shown in the Source Control view's branch indicator.Closes #306496
Problem
The Git extension derives its branch display label from the checked-out HEAD ref. Extensions that manage branch state externally — such as worktree managers, branch-per-chat session tools, or workspace isolation layers — cannot update the displayed branch name to reflect their logical context. This forces users to see misleading branch labels when the underlying checkout is managed programmatically.
Approach
Add a
headLabelOverrideproperty on theRepositoryinterface:Implementation:
repository.ts: Private_headLabelOverridefield with getter/setter. Setter fires_onDidChangeStatusso the Source Control view updates immediately.headLabelandheadShortNamegetters check the override before falling back to HEAD state.git.d.ts:headLabelOverride: string | undefinedon theRepositoryinterface.api1.ts: Getter/setter onApiRepositorydelegating to the internal repository.Design notes:
Use Cases
Testing
Manual verification that:
headLabelOverrideupdates the Source Control view branch labelundefinedrestores the original label