feat: pin/unpin git branches in Git: Checkout#319214
feat: pin/unpin git branches in Git: Checkout#319214TomasMartinsFerreira wants to merge 1 commit into
Conversation
We added a button to each branch item in the Git: Checkout interface that allows users to pin and unpin their git branches. Pinned branches appear at the top with an additional icon for visual distinction. The following commands were also created to allow for quicker pinning/unpinning (executable from the command palette): - Git: Pin Branch - Git: Unpin Branch - Git: Pin Current Branch Closes microsoft#285828 Co-authored-by: Tomás Ferreira <tomasmartinsferreira@tecnico.ulisboa.pt>
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @lszomoruMatched files:
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds the ability to pin/unpin Git branches so that they appear at the top of the branch picker for quick access. Pinned branches are persisted per-repository in globalState, exposed via three new commands, and surfaced in the existing checkout quick pick with inline pin/unpin buttons.
Changes:
- Adds
pinBranch/unpinBranch/isBranchPinnedAPIs onRepository, persisted underpinnedBranches:<root>inglobalState, and auto-unpins when a branch is deleted. - Updates the checkout quick pick to render a
PinnedCheckoutItem, group pinned branches under a "pinned" separator, and provide inline pin/unpin buttons that refresh the pick in place. - Adds three new commands (
git.pinBranch,git.unpinBranch,git.pinCurrentBranch) with corresponding NLS entries, plus tests for the pinning logic.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| extensions/git/src/repository.ts | Implements pin/unpin storage and unpins on branch deletion. |
| extensions/git/src/commands.ts | Adds pinned UI, inline buttons, separator grouping, and new commands. |
| extensions/git/package.json | Registers the three new pin-related commands. |
| extensions/git/package.nls.json | Adds command titles for pin/unpin commands. |
| extensions/git/src/test/repository.test.ts | Adds tests for branch pinning behavior. |
| const pinnedBranches = this.getPinnedBranches(); | ||
| pinnedBranches.push(branch); | ||
|
|
||
| this.globalState.update(this.getPinnedBranchesStorageKey(), pinnedBranches); |
| const pinnedBranches = this.getPinnedBranches(); | ||
| pinnedBranches.push(branch); | ||
|
|
||
| this.globalState.update(this.getPinnedBranchesStorageKey(), pinnedBranches); |
| icon: isPinned | ||
| ? 'star-full' | ||
| : 'star-empty', | ||
| label: isPinned | ||
| ? 'Unpin Branch' | ||
| : 'Pin Branch', |
| return pinned.length === 0 | ||
| ? result | ||
| : [new RefItemSeparator(undefined, 'pinned'), ...pinned, ...unpinned]; |
| constructor(override readonly ref: Branch, shortCommitLength: number, private readonly inner: CheckoutItem) { | ||
| super(ref, shortCommitLength); | ||
| this.inner = inner; | ||
| } |
| disposables.push((quickPick.onDidTriggerItemButton(async (e) => { | ||
| const item = e.item as CheckoutItem; | ||
| if (button.actual && item.refName) { | ||
| button.actual.run(item.refRemote ? item.refName.substring(item.refRemote.length + 1) : item.refName); | ||
| const button = e.button as QuickInputButton & { | ||
| actual: RemoteSourceAction | PinBranchAction; | ||
| }; | ||
|
|
||
| if (!button.actual || !item.refName) { | ||
| return; | ||
| } | ||
|
|
||
| button.actual.run(item.refRemote ? item.refName.substring(item.refRemote.length + 1) : item.refName); |
| function createRepository(root: string, globalState: Memento): Repository { | ||
| const repository = Object.create(Repository.prototype) as Record<string, unknown>; | ||
| repository.repository = { | ||
| root, | ||
| rootRealPath: undefined, | ||
| dotGit: undefined, | ||
| kind: 'repository' | ||
| }; | ||
| repository.globalState = globalState; | ||
| return repository as unknown as Repository; | ||
| } |
@microsoft-github-policy-service agree |
Closes #285828
Issue
Issue #285828 requests a feature that allows users to pin and unpin branches in VS Code. This feature should also include a clear visual distinction between pinned and unpinned branches.
Solution
We added a button to each branch item in the Git: Checkout interface that allows users to pin and unpin their git branches. Pinned branches appear at the top with an additional icon for visual distinction.
The following commands were also created to allow for quicker pinning/unpinning (executable from the command palette):