From eaa1502b23c52fbdf933bad1a179bb82c7ae0697 Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Mon, 13 Jan 2025 17:20:46 +0100 Subject: [PATCH] Git - add more commands to the graph context menu (#237811) * Git - add "Delete Branch" and "Delete Tag" actions * Git - update the graph cherry pick command --- extensions/git/package.json | 60 ++++++++++++++++++++++++--------- extensions/git/package.nls.json | 8 +++-- extensions/git/src/commands.ts | 34 ++++++++++++++++--- 3 files changed, 79 insertions(+), 23 deletions(-) diff --git a/extensions/git/package.json b/extensions/git/package.json index 63dcda18c76..db47053cd32 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -448,14 +448,14 @@ "enablement": "!operationInProgress" }, { - "command": "git.checkoutDetached", - "title": "%command.checkoutDetached%", + "command": "git.graph.checkout", + "title": "%command.graphCheckout%", "category": "Git", "enablement": "!operationInProgress" }, { - "command": "git.graph.checkout", - "title": "%command.graphCheckout%", + "command": "git.checkoutDetached", + "title": "%command.checkoutDetached%", "category": "Git", "enablement": "!operationInProgress" }, @@ -483,6 +483,12 @@ "category": "Git", "enablement": "!operationInProgress" }, + { + "command": "git.graph.deleteBranch", + "title": "%command.graphDeleteBranch%", + "category": "Git", + "enablement": "!operationInProgress" + }, { "command": "git.renameBranch", "title": "%command.renameBranch%", @@ -519,6 +525,12 @@ "category": "Git", "enablement": "!operationInProgress" }, + { + "command": "git.graph.deleteTag", + "title": "%command.graphDeleteTag%", + "category": "Git", + "enablement": "!operationInProgress" + }, { "command": "git.deleteRemoteTag", "title": "%command.deleteRemoteTag%", @@ -632,8 +644,8 @@ "enablement": "!operationInProgress" }, { - "command": "git.cherryPickRef", - "title": "%command.cherryPickRef%", + "command": "git.graph.cherryPick", + "title": "%command.graphCherryPick%", "category": "Git", "enablement": "!operationInProgress" }, @@ -1474,7 +1486,15 @@ "when": "false" }, { - "command": "git.cherryPickRef", + "command": "git.graph.deleteBranch", + "when": "false" + }, + { + "command": "git.graph.deleteTag", + "when": "false" + }, + { + "command": "git.graph.cherryPick", "when": "false" }, { @@ -2001,20 +2021,20 @@ "when": "scmProvider == git", "group": "1_checkout@2" }, - { - "command": "git.createTag", - "when": "scmProvider == git", - "group": "2_create@1" - }, { "command": "git.branch", "when": "scmProvider == git", - "group": "2_create@2" + "group": "2_branch@2" }, { - "command": "git.cherryPickRef", + "command": "git.createTag", "when": "scmProvider == git", - "group": "3_modify@1" + "group": "3_tag@1" + }, + { + "command": "git.graph.cherryPick", + "when": "scmProvider == git", + "group": "4_modify@1" }, { "command": "git.copyCommitId", @@ -2032,6 +2052,16 @@ "command": "git.graph.checkout", "when": "scmProvider == git", "group": "1_checkout@1" + }, + { + "command": "git.graph.deleteBranch", + "when": "scmProvider == git && scmHistoryItemRef =~ /^refs\\/heads\\//", + "group": "2_branch@2" + }, + { + "command": "git.graph.deleteTag", + "when": "scmProvider == git && scmHistoryItemRef =~ /^refs\\/tags\\//", + "group": "3_tag@2" } ], "editor/title": [ diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index e27b66875d0..61168a79c34 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -62,14 +62,11 @@ "command.undoCommit": "Undo Last Commit", "command.checkout": "Checkout to...", "command.checkoutDetached": "Checkout to (Detached)...", - "command.graphCheckout": "Checkout", - "command.graphCheckoutDetached": "Checkout (Detached)", "command.branch": "Create Branch...", "command.branchFrom": "Create Branch From...", "command.deleteBranch": "Delete Branch...", "command.renameBranch": "Rename Branch...", "command.cherryPick": "Cherry Pick...", - "command.cherryPickRef": "Cherry Pick", "command.cherryPickAbort": "Abort Cherry Pick", "command.merge": "Merge...", "command.mergeAbort": "Abort Merge", @@ -126,6 +123,11 @@ "command.viewStagedChanges": "Open Staged Changes", "command.viewUntrackedChanges": "Open Untracked Changes", "command.viewCommit": "Open Commit", + "command.graphCheckout": "Checkout", + "command.graphCheckoutDetached": "Checkout (Detached)", + "command.graphCherryPick": "Cherry Pick", + "command.graphDeleteBranch": "Delete Branch", + "command.graphDeleteTag": "Delete Tag", "command.api.getRepositories": "Get Repositories", "command.api.getRepositoryState": "Get Repository State", "command.api.getRemoteSources": "Get Remote Sources", diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 584eec49422..26d0a1a1c3d 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -2875,10 +2875,24 @@ export class CommandCenter { } @command('git.deleteBranch', { repository: true }) - async deleteBranch(repository: Repository, name: string, force?: boolean): Promise { + async deleteBranch(repository: Repository, name: string | undefined, force?: boolean): Promise { + await this._deleteBranch(repository, name, force); + } + + @command('git.graph.deleteBranch', { repository: true }) + async deleteBranch2(repository: Repository, historyItem?: SourceControlHistoryItem, historyItemRefId?: string): Promise { + const historyItemRef = historyItem?.references?.find(r => r.id === historyItemRefId); + if (!historyItemRef) { + return; + } + + await this._deleteBranch(repository, historyItemRef.name); + } + + private async _deleteBranch(repository: Repository, name: string | undefined, force?: boolean): Promise { let run: (force?: boolean) => Promise; if (typeof name === 'string') { - run = force => repository.deleteBranch(name, force); + run = force => repository.deleteBranch(name!, force); } else { const getBranchPicks = async () => { const refs = await repository.getRefs({ pattern: 'refs/heads' }); @@ -3014,12 +3028,21 @@ export class CommandCenter { const placeHolder = l10n.t('Select a tag to delete'); const choice = await this.pickRef(tagPicks(), placeHolder); - if (choice instanceof TagDeleteItem) { await choice.run(repository); } } + @command('git.graph.deleteTag', { repository: true }) + async deleteTag2(repository: Repository, historyItem?: SourceControlHistoryItem, historyItemRefId?: string): Promise { + const historyItemRef = historyItem?.references?.find(r => r.id === historyItemRefId); + if (!historyItemRef) { + return; + } + + await repository.deleteTag(historyItemRef.name); + } + @command('git.deleteRemoteTag', { repository: true }) async deleteRemoteTag(repository: Repository): Promise { const remotePicks = repository.remotes @@ -3378,11 +3401,12 @@ export class CommandCenter { await repository.cherryPick(hash); } - @command('git.cherryPickRef', { repository: true }) - async cherryPickRef(repository: Repository, historyItem?: SourceControlHistoryItem): Promise { + @command('git.graph.cherryPick', { repository: true }) + async cherryPick2(repository: Repository, historyItem?: SourceControlHistoryItem): Promise { if (!historyItem) { return; } + await repository.cherryPick(historyItem.id); }