git: add rebase to branch context menu in graph view#280111
git: add rebase to branch context menu in graph view#280111reena96 wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Adds "Rebase onto Branch" option to the right-click context menu when clicking on a branch reference in the Git Graph pane. Fixes microsoft#276712 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Register _dropdownAction and _cancelAction with this._register() to ensure proper disposal when the toolbar is disposed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
📬 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
This PR adds a "Rebase onto Branch" command to the Git Graph's branch context menu, allowing users to rebase directly from the graph UI without using the Command Palette. The implementation follows established patterns for git.graph.* commands by creating a new command handler that wraps the existing repository.rebase() method.
Key changes:
- Add
git.graph.rebasecommand with appropriate menu integration and visibility controls - Register the command in the SCM history item ref context menu for local and remote branches (excluding tags)
- Include proper localization and command palette hiding
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| extensions/git/src/commands.ts | Adds graphRebase command handler that calls repository.rebase() with the selected branch name |
| extensions/git/package.json | Registers the command, adds menu contribution to scm/historyItemRef/context, and hides from command palette |
| extensions/git/package.nls.json | Adds localized display string "Rebase onto Branch" |
| src/vs/workbench/contrib/scm/browser/scmViewPane.ts | Unrelated fix: wraps Action instances with this._register() to prevent memory leaks (should be in separate PR) |
| this._dropdownAction = this._register(new Action( | ||
| 'scmInputMoreActions', | ||
| localize('scmInputMoreActions', "More Actions..."), | ||
| 'codicon-chevron-down'); | ||
| 'codicon-chevron-down')); | ||
|
|
||
| this._cancelAction = new MenuItemAction({ | ||
| this._cancelAction = this._register(new MenuItemAction({ | ||
| id: SCMInputWidgetCommandId.CancelAction, | ||
| title: localize('scmInputCancelAction', "Cancel"), | ||
| icon: Codicon.stopCircle, | ||
| }, undefined, undefined, undefined, undefined, contextKeyService, commandService); | ||
| }, undefined, undefined, undefined, undefined, contextKeyService, commandService)); |
There was a problem hiding this comment.
[nitpick] These changes to register Actions for proper disposal are good and fix potential memory leaks. However, they appear unrelated to the PR's stated purpose of adding git graph rebase functionality. Consider moving these SCM toolbar fixes to a separate PR for better change tracking and easier code review.
| if (!historyItemRef?.name) { | ||
| return; | ||
| } | ||
|
|
There was a problem hiding this comment.
Consider adding validation to prevent rebasing onto the current branch, similar to how git.graph.deleteBranch prevents deleting the active branch (lines 3073-3076). Without this check, attempting to rebase onto the current branch will fail at the git level without a user-friendly error message. Suggested addition:
if (historyItemRef.id === repository.historyProvider.currentHistoryItemRef?.id) {
window.showInformationMessage(l10n.t('Cannot rebase onto the current branch.'));
return;
}| // Prevent rebasing onto the current branch | |
| if (historyItemRef.id === repository.historyProvider.currentHistoryItemRef?.id) { | |
| window.showInformationMessage(l10n.t('Cannot rebase onto the current branch.')); | |
| return; | |
| } |
| } | ||
|
|
||
| @command('git.graph.rebase', { repository: true }) | ||
| async graphRebase(repository: Repository, historyItem?: SourceControlHistoryItem, historyItemRefId?: string): Promise<void> { |
There was a problem hiding this comment.
The method name graphRebase doesn't follow the established naming convention for git.graph.* commands. Other graph commands use numbered suffixes (e.g., checkout2, deleteBranch2, cherryPick2). Consider renaming this method to rebase2 to maintain consistency with existing patterns.
| async graphRebase(repository: Repository, historyItem?: SourceControlHistoryItem, historyItemRefId?: string): Promise<void> { | |
| async rebase2(repository: Repository, historyItem?: SourceControlHistoryItem, historyItemRefId?: string): Promise<void> { |
|
@reena96 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
Adds "Rebase onto Branch" option to the right-click context menu when clicking on a branch reference in the Git Graph pane.
Fixes #276712
Problem
Currently, when right-clicking on a branch in the Git Graph view, users can checkout or delete the branch, but there's no option to rebase onto it. Users who want to rebase must use the Command Palette (
Git: Rebase Branch...) or the terminal.Solution
Add a "Rebase onto Branch" context menu item that appears when right-clicking on local or remote branches in the Git Graph.
Before
After
Key Benefits
Implementation Details
Changes Made
extensions/git/package.jsonextensions/git/package.nls.jsonextensions/git/src/commands.tsgraphRebasecommand handlerHow It Works
repository.rebase()method with the branch nameMenu Visibility
The menu item appears for:
refs/heads/*)refs/remotes/*)whenclause)Testing Instructions
origin/main)git.graph.rebasedoes NOT appearValidation
git.graph.*command patternsPerformance Impact
Minimal - the command is a thin wrapper around the existing
repository.rebase()method.